]> source.dussan.org Git - nextcloud-server.git/commitdiff
Encryption storage wrapper is enabled by default - necessary to detect encrypted...
authorThomas Müller <thomas.mueller@tmit.eu>
Thu, 2 Apr 2015 15:16:27 +0000 (17:16 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:31 +0000 (13:30 +0200)
lib/base.php
lib/private/files/storage/wrapper/encryption.php

index 1d536464153860654727f9f1846d9fe81bf0d0a1..be397e524496fd5f0921291331a12b4c2985c3ff 100644 (file)
@@ -701,10 +701,7 @@ class OC {
        }
 
        private static function registerEncryptionWrapper() {
-               $enabled = self::$server->getEncryptionManager()->isEnabled();
-               if ($enabled) {
-                       \OCP\Util::connectHook('OC_Filesystem', 'setup', 'OC\Encryption\Manager', 'setupStorage');
-               }
+               \OCP\Util::connectHook('OC_Filesystem', 'setup', 'OC\Encryption\Manager', 'setupStorage');
        }
 
        private static function registerEncryptionHooks() {
index 2e5bbfd97becc0394499b6a15e03015d78d23c64..946e7bfbe404e762e7f4d8360bd542c06752e830 100644 (file)
@@ -229,13 +229,17 @@ class Encryption extends Wrapper {
                $encryptionModuleId = $this->util->getEncryptionModuleId($header);
 
                $size = $unencryptedSize = 0;
-               if ($this->file_exists($path)) {
+               $targetExists = $this->file_exists($path);
+               $targetIsEncrypted = false;
+               if ($targetExists) {
                        // in case the file exists we require the explicit module as
                        // specified in the file header - otherwise we need to fail hard to
                        // prevent data loss on client side
                        if (!empty($encryptionModuleId)) {
+                               $targetIsEncrypted = true;
                                $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId);
                        }
+
                        $size = $this->storage->filesize($path);
                        $unencryptedSize = $this->filesize($path);
                }
@@ -266,6 +270,14 @@ class Encryption extends Wrapper {
                                '" not found, file will be stored unencrypted');
                }
 
+               // encryption disabled on write of new file and write to existing unencrypted file -> don't encrypt
+               $encEnabled = $this->encryptionManager->isEnabled();
+               if (!$encEnabled ) {
+                       if (!$targetExists || !$targetIsEncrypted) {
+                               $shouldEncrypt = false;
+                       }
+               }
+
                if($shouldEncrypt === true && !$this->util->isExcluded($fullPath) && $encryptionModule !== null) {
                        $source = $this->storage->fopen($path, $mode);
                        $handle = \OC\Files\Stream\Encryption::wrap($source, $path, $fullPath, $header,