summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-05-17 17:29:32 +0200
committerBjörn Schießle <schiessle@owncloud.com>2013-05-17 17:29:32 +0200
commiteaa61b8539bcd1f428d8fad1d67894e8cb4f271a (patch)
treed7724a0ebdbb720da73c393b4adbf870cef80528 /apps
parentbdf74090fc073a9968a14ff53e7d70954f5920e8 (diff)
downloadnextcloud-server-eaa61b8539bcd1f428d8fad1d67894e8cb4f271a.tar.gz
nextcloud-server-eaa61b8539bcd1f428d8fad1d67894e8cb4f271a.zip
fix migration to new encryption
Diffstat (limited to 'apps')
-rw-r--r--apps/files_encryption/ajax/encryptall.php40
-rw-r--r--apps/files_encryption/hooks/hooks.php2
-rwxr-xr-xapps/files_encryption/lib/crypt.php21
-rw-r--r--apps/files_encryption/lib/util.php3
4 files changed, 18 insertions, 48 deletions
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 @@
-<?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
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)) {