summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-04-27 14:32:19 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-04-27 14:32:19 +0200
commit678b7d7e4d042ede16261c7eae659b10e597fd55 (patch)
tree1cedacc0d5cc406af50c90be8e656356c60f59ad /apps
parent93c25a1f4af11483baaef447faa235c938b2a444 (diff)
parent27683f944289e7b37f20ec7d877ed295d5ca66a3 (diff)
downloadnextcloud-server-678b7d7e4d042ede16261c7eae659b10e597fd55.tar.gz
nextcloud-server-678b7d7e4d042ede16261c7eae659b10e597fd55.zip
Merge pull request #15860 from owncloud/enc_fallback_old_encryption
[encryption] handle encrypted files correctly which where encrypted with a old version of ownCloud (<=oc6)
Diffstat (limited to 'apps')
-rw-r--r--apps/encryption/lib/crypto/crypt.php9
-rw-r--r--apps/encryption/lib/crypto/encryption.php14
-rw-r--r--apps/encryption/tests/lib/crypto/encryptionTest.php27
-rw-r--r--apps/encryption_dummy/lib/dummymodule.php3
4 files changed, 49 insertions, 4 deletions
diff --git a/apps/encryption/lib/crypto/crypt.php b/apps/encryption/lib/crypto/crypt.php
index 9ada9200551..782dbbe5a35 100644
--- a/apps/encryption/lib/crypto/crypt.php
+++ b/apps/encryption/lib/crypto/crypt.php
@@ -210,6 +210,15 @@ class Crypt {
}
/**
+ * get legacy cipher
+ *
+ * @return string
+ */
+ public function getLegacyCipher() {
+ return self::LEGACY_CIPHER;
+ }
+
+ /**
* @param string $encryptedContent
* @param string $iv
* @return string
diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php
index 8498b4223e1..3f298481680 100644
--- a/apps/encryption/lib/crypto/encryption.php
+++ b/apps/encryption/lib/crypto/encryption.php
@@ -101,6 +101,7 @@ class Encryption implements IEncryptionModule {
*
* @param string $path to the file
* @param string $user who read/write the file
+ * @param string $mode php stream open mode
* @param array $header contains the header data read from the file
* @param array $accessList who has access to the file contains the key 'users' and 'public'
*
@@ -108,12 +109,19 @@ class Encryption implements IEncryptionModule {
* written to the header, in case of a write operation
* or if no additional data is needed return a empty array
*/
- public function begin($path, $user, array $header, array $accessList) {
+ public function begin($path, $user, $mode, array $header, array $accessList) {
if (isset($header['cipher'])) {
$this->cipher = $header['cipher'];
- } else {
+ } else if (
+ $mode === 'w'
+ || $mode === 'w+'
+ || $mode === 'wb'
+ || $mode === 'wb+'
+ ) {
$this->cipher = $this->crypt->getCipher();
+ } else {
+ $this->cipher = $this->crypt->getLegacyCipher();
}
$this->path = $this->getPathToRealFile($path);
@@ -234,7 +242,7 @@ class Encryption implements IEncryptionModule {
public function decrypt($data) {
$result = '';
if (!empty($data)) {
- $result = $this->crypt->symmetricDecryptFileContent($data, $this->fileKey);
+ $result = $this->crypt->symmetricDecryptFileContent($data, $this->fileKey, $this->cipher);
}
return $result;
}
diff --git a/apps/encryption/tests/lib/crypto/encryptionTest.php b/apps/encryption/tests/lib/crypto/encryptionTest.php
index 9e14a70ebb0..500433c77d4 100644
--- a/apps/encryption/tests/lib/crypto/encryptionTest.php
+++ b/apps/encryption/tests/lib/crypto/encryptionTest.php
@@ -72,5 +72,32 @@ class EncryptionTest extends TestCase {
);
}
+ /**
+ * @dataProvider dataTestBegin
+ */
+ public function testBegin($mode, $header, $legacyCipher, $defaultCipher, $expected) {
+
+ $this->cryptMock->expects($this->any())
+ ->method('getCipher')
+ ->willReturn($defaultCipher);
+ $this->cryptMock->expects($this->any())
+ ->method('getLegacyCipher')
+ ->willReturn($legacyCipher);
+
+ $result = $this->instance->begin('/user/files/foo.txt', 'user', $mode, $header, []);
+
+ $this->assertArrayHasKey('cipher', $result);
+ $this->assertSame($expected, $result['cipher']);
+ }
+
+ public function dataTestBegin() {
+ return array(
+ array('w', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'myCipher'),
+ array('r', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'myCipher'),
+ array('w', [], 'legacyCipher', 'defaultCipher', 'defaultCipher'),
+ array('r', [], 'legacyCipher', 'defaultCipher', 'legacyCipher'),
+ );
+ }
+
} \ No newline at end of file
diff --git a/apps/encryption_dummy/lib/dummymodule.php b/apps/encryption_dummy/lib/dummymodule.php
index e974ee468e2..141edfb58f9 100644
--- a/apps/encryption_dummy/lib/dummymodule.php
+++ b/apps/encryption_dummy/lib/dummymodule.php
@@ -53,6 +53,7 @@ class DummyModule implements IEncryptionModule {
*
* @param string $path to the file
* @param string $user who read/write the file (null for public access)
+ * @param string $mode php stream open mode
* @param array $header contains the header data read from the file
* @param array $accessList who has access to the file contains the key 'users' and 'public'
*
@@ -60,7 +61,7 @@ class DummyModule implements IEncryptionModule {
* written to the header, in case of a write operation
* or if no additional data is needed return a empty array
*/
- public function begin($path, $user, array $header, array $accessList) {
+ public function begin($path, $user, $mode, array $header, array $accessList) {
return array();
}