From 0f8fe77b3a7be660e78079bc987bb851b30b576c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 29 Nov 2016 16:27:28 +0100 Subject: check if the file should really be encrypted before we update the file cache Signed-off-by: Bjoern Schiessle --- lib/private/Files/Storage/Wrapper/Encryption.php | 32 ++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'lib/private') diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 8531ccc0dd0..c0ccd22d147 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -444,7 +444,7 @@ class Encryption extends Wrapper { } // encryption disabled on write of new file and write to existing unencrypted file -> don't encrypt - if (!$encryptionEnabled || !$this->mount->getOption('encrypt', true)) { + if (!$encryptionEnabled || !$this->shouldEncrypt($path)) { if (!$targetExists || !$targetIsEncrypted) { $shouldEncrypt = false; } @@ -651,7 +651,7 @@ class Encryption extends Wrapper { * @param bool $isRename */ private function updateEncryptedVersion(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename) { - $isEncrypted = $this->encryptionManager->isEnabled() && $this->mount->getOption('encrypt', true) ? 1 : 0; + $isEncrypted = $this->encryptionManager->isEnabled() && $this->shouldEncrypt($targetInternalPath) ? 1 : 0; $cacheInformation = [ 'encrypted' => (bool)$isEncrypted, ]; @@ -954,6 +954,7 @@ class Encryption extends Wrapper { throw $e; } } + return $encryptionModule; } @@ -991,4 +992,31 @@ class Encryption extends Wrapper { return substr($normalized, 0, strlen('/files_versions/')) === '/files_versions/'; } + /** + * check if the given storage should be encrypted or not + * + * @param $path + * @return bool + */ + protected function shouldEncrypt($path) { + $fullPath = $this->getFullPath($path); + $mountPointConfig = $this->mount->getOption('encrypt', true); + if ($mountPointConfig === false) { + return false; + } + + try { + $encryptionModule = $this->getEncryptionModule($fullPath); + } catch (ModuleDoesNotExistsException $e) { + return false; + } + + if ($encryptionModule === null) { + $encryptionModule = $this->encryptionManager->getEncryptionModule(); + } + + return $encryptionModule->shouldEncrypt($fullPath); + + } + } -- cgit v1.2.3