Skip to content

Commit

Permalink
fix: handle encryption keys with trashbin
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Oct 26, 2021
1 parent 7f380ff commit 5c1b695
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
13 changes: 13 additions & 0 deletions lib/private/Encryption/Keys/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ public function deleteFileKey($path, $keyId, $encryptionModuleId) {
* @inheritdoc
*/
public function deleteAllFileKeys($path) {
$mount = $this->mountManager->find($path);
$keyPath = $mount ? $mount->getStorage()->getEncryptionFileKeyDirectory('', $mount->getInternalPath($path)) : null;
if ($keyPath) {
return false;
}

$keyDir = $this->getFileKeyDir('', $path);
return !$this->view->file_exists($keyDir) || $this->view->deleteAll($keyDir);
}
Expand Down Expand Up @@ -348,6 +354,13 @@ public function copyKeys($source, $target) {
* @return string
*/
protected function getPathToKeys($path) {
# ask the storage implementation for the key storage
$mount = $this->mountManager->find($path);
$keyPath = $mount ? $mount->getStorage()->getEncryptionFileKeyDirectory('', $mount->getInternalPath($path)) : null;
if ($keyPath) {
return $keyPath;
}

list($owner, $relativePath) = $this->util->getUidAndFilename($path);
$systemWideMountPoint = $this->util->isSystemWideMountPoint($relativePath, $owner);

Expand Down
20 changes: 16 additions & 4 deletions lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class Encryption extends Wrapper implements Storage\IVersionedStorage {

private static $disableWriteEncryption = false;

private $inCopyKeys = false;

/**
* @param array $parameters
* @param IManager $encryptionManager
Expand Down Expand Up @@ -309,7 +311,11 @@ public function rmdir($path) {
$this->util->isExcluded($fullPath) === false &&
$this->encryptionManager->isEnabled()
) {
$this->keyStorage->deleteAllFileKeys($fullPath);
# TODO: stupid short cut - we better have an capabilities method or something
$keyPath = $this->storage->getEncryptionFileKeyDirectory('', $path);
if (!$keyPath) {
$this->keyStorage->deleteAllFileKeys($fullPath);
}
}

return $result;
Expand Down Expand Up @@ -1062,11 +1068,17 @@ public function updateUnencryptedSize($path, $unencryptedSize) {
* @return bool
*/
protected function copyKeys($source, $target) {
if (!$this->util->isExcluded($source)) {
return $this->keyStorage->copyKeys($source, $target);
if ($this->inCopyKeys) {
return false;
}
if ($this->util->isExcluded($source)) {
return false;
}
$this->inCopyKeys = true;

return false;
$result = $this->keyStorage->copyKeys($source, $target);
$this->inCopyKeys = false;
return $result;
}

/**
Expand Down

0 comments on commit 5c1b695

Please sign in to comment.