+++ /dev/null
-<?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
// 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
* @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
\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
/**
* @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)) {