From 53248a9b6069f64662e259053684c175498fe67d Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Tue, 5 Feb 2013 15:35:29 +0000 Subject: [PATCH] Recryption of legacy encrypted files now working on login --- apps/files_encryption/lib/crypt.php | 9 ++++++++- apps/files_encryption/lib/util.php | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 231bfd9826b..7f96702b768 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -188,10 +188,17 @@ class Crypt { $trimmed = ltrim( $path, '/' ); + // Path must not include user/files + $split = explode( '/', $trimmed ); + $sliced = array_slice( $split, 2 ); + $relPath = implode( '/', $sliced ); + +// trigger_error("REL PATH = ".var_export($relPath, 1)); + // trigger_error( "DATA = ".var_export($data, 1). " CATFILE?: ".var_export( self::isCatfile( $data ), 1)); // Fetch all file metadata from DB - $metadata = \OC\Files\Filesystem::getFileInfo( $trimmed, '' ); + $metadata = \OC\Files\Filesystem::getFileInfo( $relPath, '' ); trigger_error("PATH = ". var_export($trimmed, 1)." METADATA = ".var_export($metadata['encrypted'], 1)); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 7e396a9145b..89fe79b6ff5 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -391,26 +391,32 @@ class Util { && ! empty( $newPassphrase ) ) { - foreach ( $found['legacy'] as $legacyFilePath ) { + foreach ( $found['legacy'] as $legacyFile ) { // Fetch data from file - $legacyData = $this->view->file_get_contents( $legacyFilePath ); + $legacyData = $this->view->file_get_contents( $legacyFile['path'] ); - trigger_error("\n\nlegdata = ".var_export($legacyData).' \n\npassphrase = '.var_export($legacyPassphrase).' \n\npublickey = '.var_export($publicKey).' \n\nnewpass = '.var_export($newPassphrase)); + trigger_error("\n\nlegdata = ".var_export($legacyData, 1).' \n\npassphrase = '.var_export($legacyPassphrase, 1).' \n\npublickey = '.var_export($publicKey, 1).' \n\nnewpass = '.var_export($newPassphrase, 1)); // Recrypt data, generate catfile $recrypted = Crypt::legacyKeyRecryptKeyfile( $legacyData, $legacyPassphrase, $publicKey, $newPassphrase ); + // Format path to be relative to user files dir + $trimmed = ltrim( $legacyFile['path'], '/' ); + $split = explode( '/', $trimmed ); + $sliced = array_slice( $split, 2 ); + $relPath = implode( '/', $sliced ); + // Save keyfile - Keymanager::setFileKey( $this->view, $plainFile['path'], $this->userId, $recrypted['key'] ); + Keymanager::setFileKey( $this->view, $relPath, $this->userId, $recrypted['key'] ); // Overwrite the existing file with the encrypted one - $this->view->file_put_contents( $plainFile['path'], $recrypted['data'] ); + $this->view->file_put_contents( $legacyFile['path'], $recrypted['data'] ); $size = strlen( $recrypted['data'] ); // Add the file to the cache - \OC\Files\Filesystem::putFileInfo( $plainFile['path'], array( 'encrypted'=>true, 'size' => $size ), '' ); + \OC\Files\Filesystem::putFileInfo( $legacyFile['path'], array( 'encrypted'=>true, 'size' => $size ), '' ); } -- 2.39.5