]> source.dussan.org Git - nextcloud-server.git/commitdiff
Recryption of legacy encrypted files now working on login
authorSam Tuke <samtuke@owncloud.com>
Tue, 5 Feb 2013 15:35:29 +0000 (15:35 +0000)
committerSam Tuke <samtuke@owncloud.com>
Tue, 5 Feb 2013 15:35:29 +0000 (15:35 +0000)
apps/files_encryption/lib/crypt.php
apps/files_encryption/lib/util.php

index 231bfd9826b3a415f042cd19c37ede7fc4cc0445..7f96702b768c7d551d532ad092a5f7d1b1d7539e 100755 (executable)
@@ -188,10 +188,17 @@ class Crypt {
        \r
                $trimmed = ltrim( $path, '/' );\r
                \r
+               // Path must not include user/files\r
+               $split = explode( '/', $trimmed );\r
+               $sliced = array_slice( $split, 2 );\r
+               $relPath = implode( '/', $sliced );\r
+               \r
+//             trigger_error("REL PATH = ".var_export($relPath, 1));\r
+               \r
 //             trigger_error( "DATA = ".var_export($data, 1). "   CATFILE?: ".var_export( self::isCatfile( $data ), 1));\r
        \r
                // Fetch all file metadata from DB\r
-               $metadata = \OC\Files\Filesystem::getFileInfo( $trimmed, '' );\r
+               $metadata = \OC\Files\Filesystem::getFileInfo( $relPath, '' );\r
                \r
                trigger_error("PATH = ". var_export($trimmed, 1)."   METADATA = ".var_export($metadata['encrypted'], 1));\r
                \r
index 7e396a9145b8375785ad940565570c3b5bf48ebf..89fe79b6ff5c36247e66050142590776c11e6c23 100644 (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 ), '' );
                                
                                }