summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Schießle <bjoern@schiessle.org>2015-04-14 16:48:04 +0200
committerBjörn Schießle <bjoern@schiessle.org>2015-04-14 16:48:04 +0200
commit4f0437fbdef8e729167c1a8078e790c7983f69ef (patch)
tree81017dacc38eb0ecbabd22c08a17f7a460d6aa18
parent82cab257622759d1b64582f27de33a982c79c158 (diff)
parentcbe30f740ede9df6ef30a7b65746957ca42996b2 (diff)
downloadnextcloud-server-4f0437fbdef8e729167c1a8078e790c7983f69ef.tar.gz
nextcloud-server-4f0437fbdef8e729167c1a8078e790c7983f69ef.zip
Merge pull request #15598 from owncloud/fix-enc-file-size-master
Fix file size of encrypted files
-rw-r--r--apps/encryption/lib/crypto/crypt.php2
-rw-r--r--apps/encryption/lib/crypto/encryption.php10
-rw-r--r--apps/encryption_dummy/lib/dummymodule.php10
-rw-r--r--lib/private/files/storage/wrapper/encryption.php21
-rw-r--r--lib/public/encryption/iencryptionmodule.php8
-rw-r--r--tests/lib/files/storage/wrapper/encryption.php13
-rw-r--r--tests/lib/files/stream/encryption.php3
7 files changed, 16 insertions, 51 deletions
diff --git a/apps/encryption/lib/crypto/crypt.php b/apps/encryption/lib/crypto/crypt.php
index 91f986611be..c026aa6a90a 100644
--- a/apps/encryption/lib/crypto/crypt.php
+++ b/apps/encryption/lib/crypto/crypt.php
@@ -245,7 +245,7 @@ class Crypt {
if (!empty($header)) {
$privateKey = substr($privateKey,
strpos($privateKey,
- self::HEADER_END) + strlen(self::HEADER_START));
+ self::HEADER_END) + strlen(self::HEADER_END));
}
$plainKey = $this->symmetricDecryptFileContent($privateKey,
diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php
index 13beda196ce..fd5a84c9734 100644
--- a/apps/encryption/lib/crypto/encryption.php
+++ b/apps/encryption/lib/crypto/encryption.php
@@ -309,16 +309,6 @@ class Encryption implements IEncryptionModule {
}
/**
- * 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.
* ownCloud read/write files with a block size of 8192 byte
*
diff --git a/apps/encryption_dummy/lib/dummymodule.php b/apps/encryption_dummy/lib/dummymodule.php
index b4dfe34a9bf..813b50edcbd 100644
--- a/apps/encryption_dummy/lib/dummymodule.php
+++ b/apps/encryption_dummy/lib/dummymodule.php
@@ -119,16 +119,6 @@ class DummyModule implements IEncryptionModule {
return false;
}
- /**
- * calculate unencrypted size
- *
- * @param string $path to file
- * @return integer unencrypted size
- */
- public function calculateUnencryptedSize($path) {
- return 42;
- }
-
public function getUnencryptedBlockSize() {
return 6126;
}
diff --git a/lib/private/files/storage/wrapper/encryption.php b/lib/private/files/storage/wrapper/encryption.php
index 4136e008af9..5697139bd6b 100644
--- a/lib/private/files/storage/wrapper/encryption.php
+++ b/lib/private/files/storage/wrapper/encryption.php
@@ -91,21 +91,23 @@ class Encryption extends Wrapper {
*/
public function filesize($path) {
$fullPath = $this->getFullPath($path);
- $size = $this->storage->filesize($path);
$info = $this->getCache()->get($path);
-
if (isset($this->unencryptedSize[$fullPath])) {
$size = $this->unencryptedSize[$fullPath];
- }
- if (isset($info['fileid'])) {
- $info['encrypted'] = true;
- $info['size'] = $size;
- $this->getCache()->put($path, $info);
+ if (isset($info['fileid'])) {
+ $info['encrypted'] = true;
+ $info['size'] = $size;
+ $this->getCache()->put($path, $info);
+ }
+ return $size;
}
- return $size;
+ if (isset($info['fileid']) && $info['encrypted']) {
+ return $info['size'];
+ }
+ return $this->storage->filesize($path);
}
/**
@@ -181,6 +183,9 @@ class Encryption extends Wrapper {
$result = $this->storage->rename($path1, $path2);
if ($result) {
$target = $this->getFullPath($path2);
+ if (isset($this->unencryptedSize[$source])) {
+ $this->unencryptedSize[$target] = $this->unencryptedSize[$source];
+ }
$encryptionModule = $this->getEncryptionModule($path2);
if ($encryptionModule) {
$keyStorage = $this->getKeyStorage($encryptionModule->getId());
diff --git a/lib/public/encryption/iencryptionmodule.php b/lib/public/encryption/iencryptionmodule.php
index c1ce7d99d78..d22ca0ec86c 100644
--- a/lib/public/encryption/iencryptionmodule.php
+++ b/lib/public/encryption/iencryptionmodule.php
@@ -97,14 +97,6 @@ interface IEncryptionModule {
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.
* ownCloud read/write files with a block size of 8192 byte
*
diff --git a/tests/lib/files/storage/wrapper/encryption.php b/tests/lib/files/storage/wrapper/encryption.php
index 4f7a9e851c1..ec3770260aa 100644
--- a/tests/lib/files/storage/wrapper/encryption.php
+++ b/tests/lib/files/storage/wrapper/encryption.php
@@ -74,7 +74,7 @@ class Encryption extends \Test\Files\Storage\Storage {
protected function buildMockModule() {
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
->disableOriginalConstructor()
- ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize'])
+ ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize'])
->getMock();
$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('update')->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);
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'));
-// }
}
//
diff --git a/tests/lib/files/stream/encryption.php b/tests/lib/files/stream/encryption.php
index 53727a2213d..6964d203f18 100644
--- a/tests/lib/files/stream/encryption.php
+++ b/tests/lib/files/stream/encryption.php
@@ -88,7 +88,7 @@ class Encryption extends \Test\TestCase {
protected function buildMockModule() {
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
->disableOriginalConstructor()
- ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'calculateUnencryptedSize', 'getUnencryptedBlockSize'])
+ ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize'])
->getMock();
$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('update')->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);
return $encryptionModule;
}