Merge pull request #15598 from owncloud/fix-enc-file-size-master

Fix file size of encrypted files
This commit is contained in:
Björn Schießle 2015-04-14 16:48:04 +02:00
commit 4f0437fbde
7 changed files with 16 additions and 51 deletions

View File

@ -245,7 +245,7 @@ class Crypt {
if (!empty($header)) { if (!empty($header)) {
$privateKey = substr($privateKey, $privateKey = substr($privateKey,
strpos($privateKey, strpos($privateKey,
self::HEADER_END) + strlen(self::HEADER_START)); self::HEADER_END) + strlen(self::HEADER_END));
} }
$plainKey = $this->symmetricDecryptFileContent($privateKey, $plainKey = $this->symmetricDecryptFileContent($privateKey,

View File

@ -308,16 +308,6 @@ class Encryption implements IEncryptionModule {
return false; return false;
} }
/**
* calculate unencrypted size
*
* @param string $path to file
* @return integer unencrypted size
*/
public function calculateUnencryptedSize($path) {
// TODO: Implement calculateUnencryptedSize() method.
}
/** /**
* get size of the unencrypted payload per block. * get size of the unencrypted payload per block.
* ownCloud read/write files with a block size of 8192 byte * ownCloud read/write files with a block size of 8192 byte

View File

@ -119,16 +119,6 @@ class DummyModule implements IEncryptionModule {
return false; return false;
} }
/**
* calculate unencrypted size
*
* @param string $path to file
* @return integer unencrypted size
*/
public function calculateUnencryptedSize($path) {
return 42;
}
public function getUnencryptedBlockSize() { public function getUnencryptedBlockSize() {
return 6126; return 6126;
} }

View File

@ -91,21 +91,23 @@ class Encryption extends Wrapper {
*/ */
public function filesize($path) { public function filesize($path) {
$fullPath = $this->getFullPath($path); $fullPath = $this->getFullPath($path);
$size = $this->storage->filesize($path);
$info = $this->getCache()->get($path); $info = $this->getCache()->get($path);
if (isset($this->unencryptedSize[$fullPath])) { if (isset($this->unencryptedSize[$fullPath])) {
$size = $this->unencryptedSize[$fullPath]; $size = $this->unencryptedSize[$fullPath];
if (isset($info['fileid'])) {
$info['encrypted'] = true;
$info['size'] = $size;
$this->getCache()->put($path, $info);
}
return $size;
} }
if (isset($info['fileid'])) { if (isset($info['fileid']) && $info['encrypted']) {
$info['encrypted'] = true; return $info['size'];
$info['size'] = $size;
$this->getCache()->put($path, $info);
} }
return $this->storage->filesize($path);
return $size;
} }
/** /**
@ -181,6 +183,9 @@ class Encryption extends Wrapper {
$result = $this->storage->rename($path1, $path2); $result = $this->storage->rename($path1, $path2);
if ($result) { if ($result) {
$target = $this->getFullPath($path2); $target = $this->getFullPath($path2);
if (isset($this->unencryptedSize[$source])) {
$this->unencryptedSize[$target] = $this->unencryptedSize[$source];
}
$encryptionModule = $this->getEncryptionModule($path2); $encryptionModule = $this->getEncryptionModule($path2);
if ($encryptionModule) { if ($encryptionModule) {
$keyStorage = $this->getKeyStorage($encryptionModule->getId()); $keyStorage = $this->getKeyStorage($encryptionModule->getId());

View File

@ -96,14 +96,6 @@ interface IEncryptionModule {
*/ */
public function shouldEncrypt($path); public function shouldEncrypt($path);
/**
* calculate unencrypted size
*
* @param string $path to file
* @return integer unencrypted size
*/
public function calculateUnencryptedSize($path);
/** /**
* get size of the unencrypted payload per block. * get size of the unencrypted payload per block.
* ownCloud read/write files with a block size of 8192 byte * ownCloud read/write files with a block size of 8192 byte

View File

@ -74,7 +74,7 @@ class Encryption extends \Test\Files\Storage\Storage {
protected function buildMockModule() { protected function buildMockModule() {
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize']) ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize'])
->getMock(); ->getMock();
$encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE'); $encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
@ -85,20 +85,9 @@ class Encryption extends \Test\Files\Storage\Storage {
$encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0); $encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
$encryptionModule->expects($this->any())->method('update')->willReturn(true); $encryptionModule->expects($this->any())->method('update')->willReturn(true);
$encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true); $encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
$encryptionModule->expects($this->any())->method('calculateUnencryptedSize')->willReturn(42);
$encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192); $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
return $encryptionModule; return $encryptionModule;
} }
// public function testMkDirRooted() {
// $this->instance->mkdir('bar');
// $this->assertTrue($this->sourceStorage->is_dir('foo/bar'));
// }
//
// public function testFilePutContentsRooted() {
// $this->instance->file_put_contents('bar', 'asd');
// $this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar'));
// }
} }
// //

View File

@ -88,7 +88,7 @@ class Encryption extends \Test\TestCase {
protected function buildMockModule() { protected function buildMockModule() {
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize']) ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize'])
->getMock(); ->getMock();
$encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE'); $encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
@ -99,7 +99,6 @@ class Encryption extends \Test\TestCase {
$encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0); $encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
$encryptionModule->expects($this->any())->method('update')->willReturn(true); $encryptionModule->expects($this->any())->method('update')->willReturn(true);
$encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true); $encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
$encryptionModule->expects($this->any())->method('calculateUnencryptedSize')->willReturn(42);
$encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192); $encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
return $encryptionModule; return $encryptionModule;
} }