From: Björn Schießle Date: Fri, 17 May 2013 15:29:32 +0000 (+0200) Subject: fix migration to new encryption X-Git-Tag: v6.0.0alpha2~743^2~48 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eaa61b8539bcd1f428d8fad1d67894e8cb4f271a;p=nextcloud-server.git fix migration to new encryption --- diff --git a/apps/files_encryption/ajax/encryptall.php b/apps/files_encryption/ajax/encryptall.php deleted file mode 100644 index ce613ca4435..00000000000 --- a/apps/files_encryption/ajax/encryptall.php +++ /dev/null @@ -1,40 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or later. - * See the COPYING-README file. - * - * @brief Script to handle manual trigger of \OCA\Encryption\Util{}->encryptAll() - */ - -use OCA\Encryption; - -\OCP\JSON::checkAppEnabled( 'files_encryption' ); -\OCP\JSON::callCheck(); - -$return = false; - -if ( - isset( $_POST['encryptAll'] ) - && ! empty( $_POST['userPassword'] ) -) { - - $view = new \OC_FilesystemView( '' ); - $userId = \OCP\User::getUser(); - $util = new \OCA\Encryption\Util( $view, $userId ); - $session = new \OCA\Encryption\Session( $view ); - $publicKey = \OCA\Encryption\Keymanager::getPublicKey( $view, $userId ); - $path = '/' . $userId . '/' . 'files'; - - $util->encryptAll( $publicKey, $path, $session->getLegacyKey(), $_POST['userPassword'] ); - - $return = true; - -} else { - - $return = false; - -} - -// Return success or failure -( $return ) ? \OCP\JSON::success() : \OCP\JSON::error(); \ No newline at end of file diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 76a19ff968c..72334559b8c 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -88,7 +88,7 @@ class Hooks { // This serves to upgrade old versions of the encryption // app (see appinfo/spec.txt) if ( - $util->encryptAll( $publicKey, '/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password'] ) + $util->encryptAll( '/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password'] ) ) { \OC_Log::write( diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 708d1719d73..56dacc94b0c 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -169,7 +169,7 @@ class Crypt { * @return true / false */ public static function isLegacyEncryptedContent( $data, $relPath ) { - + // Fetch all file metadata from DB $metadata = \OC\Files\Filesystem::getFileInfo( $relPath, '' ); @@ -683,15 +683,26 @@ class Crypt { $decrypted = $bf->decrypt( $content ); - $trimmed = rtrim( $decrypted, "\0" ); - - return $trimmed; + return $decrypted; } + + private static function legacyBlockDecrypt($data, $key='',$maxLength=0) { + $result = ''; + while (strlen($data)) { + $result.=self::legacyDecrypt(substr($data, 0, 8192), $key); + $data = substr($data, 8192); + } + if ($maxLength > 0) { + return substr($result, 0, $maxLength); + } else { + return rtrim($result, "\0"); + } + } public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKeys, $newPassphrase, $path ) { - $decrypted = self::legacyDecrypt( $legacyEncryptedContent, $legacyPassphrase ); + $decrypted = self::legacyBlockDecrypt( $legacyEncryptedContent, $legacyPassphrase ); // Encrypt plain data, generate keyfile & encrypted file $cryptedData = self::symmetricEncryptFileContentKeyfile( $decrypted ); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index f1042ed759a..9588db8d647 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -652,11 +652,10 @@ class Util { /** * @brief Encrypt all files in a directory - * @param string $publicKey the public key to encrypt files with * @param string $dirPath the directory whose files will be encrypted * @note Encryption is recursive */ - public function encryptAll($publicKey, $dirPath, $legacyPassphrase = null, $newPassphrase = null) { + public function encryptAll($dirPath, $legacyPassphrase = null, $newPassphrase = null) { if ($found = $this->findEncFiles($dirPath)) {