From 8b355788333f9078066b3f877c4e5c1c4001597c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 27 May 2013 12:02:27 +0200 Subject: [PATCH 1/3] fix migration from old to new encryption --- apps/files_encryption/hooks/hooks.php | 2 -- apps/files_encryption/lib/crypt.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 2066300a16..07072fb8c4 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -81,8 +81,6 @@ class Hooks { $session->setLegacyKey( $plainLegacyKey ); } - - $publicKey = Keymanager::getPublicKey( $view, $params['uid'] ); // Encrypt existing user files: // This serves to upgrade old versions of the encryption diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index f5b7a8a0a4..009a648016 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -613,7 +613,7 @@ class Crypt $decrypted = $bf->decrypt( $content ); - return rtrim( $decrypted, "\0" );; + return $decrypted; } From df22a7c4954acb67c9365f9900bd7a3f70f13487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 27 May 2013 12:21:39 +0200 Subject: [PATCH 2/3] make legacyDecrypt() private als always call legacyBlockDecrypt() from other classes --- apps/files_encryption/hooks/hooks.php | 2 +- apps/files_encryption/lib/crypt.php | 2 +- apps/files_encryption/lib/proxy.php | 2 +- apps/files_encryption/tests/crypt.php | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 07072fb8c4..9af1f2c645 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -76,7 +76,7 @@ class Hooks { && $encLegacyKey = $userView->file_get_contents( 'encryption.key' ) ) { - $plainLegacyKey = Crypt::legacyDecrypt( $encLegacyKey, $params['password'] ); + $plainLegacyKey = Crypt::legacyBlockDecrypt( $encLegacyKey, $params['password'] ); $session->setLegacyKey( $plainLegacyKey ); diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 009a648016..9345712a45 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -607,7 +607,7 @@ class Crypt * * This function decrypts an content */ - public static function legacyDecrypt( $content, $passphrase = '' ) { + private static function legacyDecrypt( $content, $passphrase = '' ) { $bf = self::getBlowfish( $passphrase ); diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index eaaeae9b61..d9520810bf 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -223,7 +223,7 @@ class Proxy extends \OC_FileProxy && isset( $_SESSION['legacyenckey'] ) && Crypt::isEncryptedMeta( $path ) ) { - $plainData = Crypt::legacyDecrypt( $data, $session->getLegacyKey() ); + $plainData = Crypt::legacyBlockDecrypt( $data, $session->getLegacyKey() ); } \OC_FileProxy::$enabled = $proxyStatus; diff --git a/apps/files_encryption/tests/crypt.php b/apps/files_encryption/tests/crypt.php index 74b4252a1d..e9f155e264 100755 --- a/apps/files_encryption/tests/crypt.php +++ b/apps/files_encryption/tests/crypt.php @@ -515,7 +515,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase { */ function testLegacyDecryptShort($crypted) { - $decrypted = Encryption\Crypt::legacyDecrypt($crypted, $this->pass); + $decrypted = Encryption\Crypt::legacyBlockDecrypt($crypted, $this->pass); $this->assertEquals($this->dataShort, $decrypted); @@ -543,7 +543,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase { */ function testLegacyDecryptLong($crypted) { - $decrypted = Encryption\Crypt::legacyDecrypt($crypted, $this->pass); + $decrypted = Encryption\Crypt::legacyBlockDecrypt($crypted, $this->pass); $this->assertEquals($this->dataLong, $decrypted); @@ -560,7 +560,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase { $encKey = Encryption\Crypt::legacyCreateKey($this->pass); // Decrypt key - $key = Encryption\Crypt::legacyDecrypt($encKey, $this->pass); + $key = Encryption\Crypt::legacyBlockDecrypt($encKey, $this->pass); $this->assertTrue(is_numeric($key)); From 4c05259ccfbb7e2f0083794172eaa7c06f4b2592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Mon, 27 May 2013 13:47:03 +0200 Subject: [PATCH 3/3] legacyBlockDecryprt() needs to be public --- apps/files_encryption/lib/crypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 9345712a45..33f9fc2060 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -623,7 +623,7 @@ class Crypt * @param int $maxLength * @return string */ - private static function legacyBlockDecrypt( $data, $key = '', $maxLength = 0 ) { + public static function legacyBlockDecrypt( $data, $key = '', $maxLength = 0 ) { $result = ''; while ( strlen( $data ) ) { $result .= self::legacyDecrypt( substr( $data, 0, 8192 ), $key );