]> source.dussan.org Git - nextcloud-server.git/commitdiff
Development snapshot
authorSam Tuke <samtuke@owncloud.com>
Tue, 23 Apr 2013 16:41:01 +0000 (18:41 +0200)
committerSam Tuke <samtuke@owncloud.com>
Tue, 23 Apr 2013 16:41:01 +0000 (18:41 +0200)
working on stream handling (large files) in Util->encryptAll()

apps/files_encryption/lib/keymanager.php
apps/files_encryption/lib/proxy.php
apps/files_encryption/lib/util.php

index 9885f5e5508b560ac37647bfb4e5678c28eda4f8..0e1dafeed7581d251f9e9c90414016d7584ff66d 100755 (executable)
@@ -106,6 +106,7 @@ class Keymanager {
         */
        public static function setFileKey( \OC_FilesystemView $view, $path, $userId, $catfile ) {
                
+               $proxyStatus = \OC_FileProxy::$enabled;
                \OC_FileProxy::$enabled = false;
 
                //here we need the currently logged in user, while userId can be a different user
@@ -129,7 +130,7 @@ class Keymanager {
                $result = $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile );
                
                
-               \OC_FileProxy::$enabled = true;
+               \OC_FileProxy::$enabled = $proxyStatus;
                
                return $result;
                
index 0d20ff1af1a33468dfa37c734b1f5089db373406..620f7cc8c31d0001196f31a06925969e5045074a 100644 (file)
@@ -142,7 +142,6 @@ class Proxy extends \OC_FileProxy {
                                $multiEncrypted = Crypt::multiKeyEncrypt( $plainKey, $publicKeys );
                                
                                // Save sharekeys to user folders
-                               
                                Keymanager::setShareKeys( $rootView, $filePath, $multiEncrypted['keys'] );
                                
                                // Set encrypted keyfile as common varname
index 38b4219f6e2edf6d0e5e1de4f1d4fd9ca3fc77b9..f9198e0606aff08620bf80499b8743a6f0e20864 100644 (file)
@@ -500,37 +500,39 @@ class Util {
                
                        // Encrypt unencrypted files
                        foreach ( $found['plain'] as $plainFile ) {
-                       
-                               // Open plain file handle
-                               
-                               
-                               // Open enc file handle
-                               
-                               
-                               // Read plain file in chunks
                                
                                //relative to data/<user>/file
                                $relPath = $plainFile['path'];
+                               
                                //relative to /data
                                $rawPath = $this->userId . '/files/' .  $plainFile['path'];
-
-                               // Open handle with for binary reading
-                               $plainHandle = $this->view->fopen( $rawPath, 'rb' );
-                               // Open handle with for binary writing
-
-                               $encHandle = fopen( 'crypt://' . $relPath . '.tmp', 'wb' );
                                
-                               // Overwrite the existing file with the encrypted one
-                               //$this->view->file_put_contents( $plainFile['path'], $encrypted['data'] );
-                               $size = stream_copy_to_stream( $plainHandle, $encHandle );
-
-                               $this->view->rename($rawPath . '.tmp', $rawPath);
-
-                               // Fetch the key that has just been set/updated by the stream
-                               //$encKey = Keymanager::getFileKey( $this->view, $this->userId, $relPath );
+                               // Open plain file handle for binary reading
+                               $plainHandle1 = $this->view->fopen( $rawPath, 'rb' );
+                               
+                               // 2nd handle for moving plain file - view->rename() doesn't work, this is a workaround
+                               $plainHandle2 = $this->view->fopen( $rawPath . '.plaintmp', 'wb' );
+                               
+                               // Move plain file to a temporary location
+                               stream_copy_to_stream( $plainHandle1, $plainHandle2 );
+                               
+                               // Close access to original file
+//                             $this->view->fclose( $plainHandle1 ); // not implemented in view{}
+                               
+                               // Delete original plain file so we can rename enc file later
+                               $this->view->unlink( $rawPath );
+                               
+                               // Open enc file handle for binary writing, with same filename as original plain file
+                               $encHandle = fopen( 'crypt://' . $relPath, 'wb' );
+                               
+                               // Save data from plain stream to new encrypted file via enc stream
+                               // NOTE: Stream{} will be invoked for handling 
+                               // the encryption, and should handle all keys 
+                               // and their generation etc. automatically
+                               $size = stream_copy_to_stream( $plainHandle2, $encHandle );
                                
-                               // Save keyfile
-                               //Keymanager::setFileKey( $this->view, $relPath, $this->userId, $encKey );
+                               // Delete temporary plain copy of file
+                               $this->view->unlink( $rawPath . '.plaintmp' );
                                
                                // Add the file to the cache
                                \OC\Files\Filesystem::putFileInfo( $plainFile['path'], array( 'encrypted'=>true, 'size' => $size ), '' );