diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 0bbe9e67d345..849609f3a1f0 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -201,16 +201,18 @@ public function getMetaData($path) { */ public function file_get_contents($path) { - $encryptionModule = $this->getEncryptionModule($path); + if ( \OC::$server->getAppConfig()->getValue('encryption', 'enabled', false) !== false) { + $encryptionModule = $this->getEncryptionModule($path); - if ($encryptionModule) { - $handle = $this->fopen($path, "r"); - if (!$handle) { - return false; + if ($encryptionModule) { + $handle = $this->fopen($path, "r"); + if (!$handle) { + return false; + } + $data = stream_get_contents($handle); + fclose($handle); + return $data; } - $data = stream_get_contents($handle); - fclose($handle); - return $data; } return $this->storage->file_get_contents($path); } @@ -379,6 +381,8 @@ public function fopen($path, $mode) { $signed = (isset($header['signed']) && $header['signed'] === 'true') ? true : false; $fullPath = $this->getFullPath($path); $encryptionModuleId = $this->util->getEncryptionModuleId($header); + $createDecryptedFile = false; + $readNormalFile = false; if ($this->util->isExcluded($fullPath) === false) { @@ -420,6 +424,9 @@ public function fopen($path, $mode) { $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId); $shouldEncrypt = $encryptionModule->shouldEncrypt($fullPath); $signed = true; + if (\OC::$server->getSession()->get('decryptAllCmd') === true) { + $createDecryptedFile = true; + } } } else { $info = $this->getCache()->get($path); @@ -436,6 +443,9 @@ public function fopen($path, $mode) { $shouldEncrypt = true; $targetIsEncrypted = true; } + if ( \OC::$server->getSession()->get('encryptAllCmd') === true) { + $readNormalFile = true; + } } } catch (ModuleDoesNotExistsException $e) { $this->logger->warning('Encryption module "' . $encryptionModuleId . @@ -450,6 +460,9 @@ public function fopen($path, $mode) { } if ($shouldEncrypt === true && $encryptionModule !== null) { + if (($createDecryptedFile === true) || ($readNormalFile === true)) { + return $this->storage->fopen($path, $mode); + } $headerSize = $this->getHeaderSize($path); $source = $this->storage->fopen($path, $mode); if (!is_resource($source)) { @@ -672,6 +685,9 @@ private function updateEncryptedVersion(Storage $sourceStorage, $sourceInternalP // in case of a rename we need to manipulate the source cache because // this information will be kept for the new target if ($isRename) { + $encryptedVersion = 1; + $cacheInformation['encryptedVersion'] = $encryptedVersion; + $sourceStorage->getCache()->put($sourceInternalPath, $cacheInformation); } else { $this->getCache()->put($targetInternalPath, $cacheInformation);