Recryption of legacy encrypted files now working on login

This commit is contained in:
Sam Tuke 2013-02-05 15:35:29 +00:00
parent fd90b82acd
commit 53248a9b60
2 changed files with 20 additions and 7 deletions

View File

@ -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));

View File

@ -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 ), '' );
}