]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix migration to new encryption
authorBjörn Schießle <schiessle@owncloud.com>
Fri, 17 May 2013 15:29:32 +0000 (17:29 +0200)
committerBjörn Schießle <schiessle@owncloud.com>
Fri, 17 May 2013 15:29:32 +0000 (17:29 +0200)
apps/files_encryption/ajax/encryptall.php [deleted file]
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/crypt.php
apps/files_encryption/lib/util.php

diff --git a/apps/files_encryption/ajax/encryptall.php b/apps/files_encryption/ajax/encryptall.php
deleted file mode 100644 (file)
index ce613ca..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>
- * 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
index 76a19ff968c581e698abe9e4651665c3ce97f19b..72334559b8ce36ec28da4252717c7abc4ba1dbef 100644 (file)
@@ -88,7 +88,7 @@ class Hooks {
                        // This serves to upgrade old versions of the encryption\r
                        // app (see appinfo/spec.txt)\r
                        if (\r
-                               $util->encryptAll( $publicKey,  '/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password'] )\r
+                               $util->encryptAll( '/' . $params['uid'] . '/' . 'files', $session->getLegacyKey(), $params['password'] )\r
                        ) {\r
                                \r
                                \OC_Log::write( \r
index 708d1719d73583f274f94313eb59647fd19854e4..56dacc94b0ce184d323fbd346d5c30daf85c7d22 100755 (executable)
@@ -169,7 +169,7 @@ class Crypt {
          * @return true / false\r
          */\r
        public static function isLegacyEncryptedContent( $data, $relPath ) {\r
-       \r
+\r
                // Fetch all file metadata from DB\r
                $metadata = \OC\Files\Filesystem::getFileInfo( $relPath, '' );\r
                \r
@@ -683,15 +683,26 @@ class Crypt {
                \r
                $decrypted = $bf->decrypt( $content );\r
                \r
-               $trimmed = rtrim( $decrypted, "\0" );\r
-               \r
-               return $trimmed;\r
+               return $decrypted;\r
                \r
        }\r
+\r
+       private static function legacyBlockDecrypt($data, $key='',$maxLength=0) {\r
+               $result = '';\r
+               while (strlen($data)) {\r
+                       $result.=self::legacyDecrypt(substr($data, 0, 8192), $key);\r
+                       $data = substr($data, 8192);\r
+               }\r
+               if ($maxLength > 0) {\r
+                       return substr($result, 0, $maxLength);\r
+               } else {\r
+                       return rtrim($result, "\0");\r
+               }\r
+       }\r
        \r
        public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKeys, $newPassphrase, $path ) {\r
        \r
-               $decrypted = self::legacyDecrypt( $legacyEncryptedContent, $legacyPassphrase );\r
+               $decrypted = self::legacyBlockDecrypt( $legacyEncryptedContent, $legacyPassphrase );\r
 \r
                // Encrypt plain data, generate keyfile & encrypted file\r
                $cryptedData = self::symmetricEncryptFileContentKeyfile( $decrypted );\r
index f1042ed759a78deca387bc60d06b93cca52261db..9588db8d647b669f3050ae6b0dfabed0ddad6de1 100644 (file)
@@ -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)) {