mirror of
https://github.com/nextcloud/server.git
synced 2026-02-27 03:50:37 -05:00
fix migration to new encryption
This commit is contained in:
parent
bdf74090fc
commit
eaa61b8539
4 changed files with 18 additions and 48 deletions
|
|
@ -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();
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue