Skip to content

Commit

Permalink
Change to support re-create masterkeys
Browse files Browse the repository at this point in the history
This change supports a new command to re-create
masterkey

Signed-off-by: Sujith H <sharidasan@owncloud.com>
  • Loading branch information
sharidas committed Jul 24, 2017
1 parent feac34c commit acf7f57
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
Expand All @@ -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 .
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit acf7f57

Please sign in to comment.