From 6e2259037b1a221bf8c6044900a4476ea2a5346b Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 6 Jul 2017 11:06:48 +0200 Subject: [PATCH 1/2] Add recovery key on public upload In order to decide if a recovery key needs to be added we always need to check the files owner settings and not the settings of the currently logged in user. Signed-off-by: Bjoern Schiessle --- apps/encryption/lib/Crypto/Encryption.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/encryption/lib/Crypto/Encryption.php b/apps/encryption/lib/Crypto/Encryption.php index fdcbd41a09c87..15b6fd77b95be 100644 --- a/apps/encryption/lib/Crypto/Encryption.php +++ b/apps/encryption/lib/Crypto/Encryption.php @@ -60,6 +60,9 @@ class Encryption implements IEncryptionModule { /** @var string */ private $user; + /** @var string */ + private $owner; + /** @var string */ private $fileKey; @@ -174,6 +177,7 @@ public function begin($path, $user, $mode, array $header, array $accessList) { $this->path = $this->getPathToRealFile($path); $this->accessList = $accessList; $this->user = $user; + $this->owner = $this->util->getOwner($path); $this->isWriteOperation = false; $this->writeCache = ''; @@ -280,13 +284,15 @@ public function end($path, $position = 0) { } } - $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->user); + $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->owner); $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys); $this->keyManager->setAllFileKeys($this->path, $encryptedKeyfiles); } return $result; } + + /** * encrypt data * @@ -407,7 +413,7 @@ public function update($path, $uid, array $accessList) { } } - $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $uid); + $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $this->owner); $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys); From d3039b8205c585eb55aef50809463f4c8aeb768a Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 17 Jul 2017 13:13:27 +0200 Subject: [PATCH 2/2] make sure that we always have a owner Signed-off-by: Bjoern Schiessle --- apps/encryption/lib/Crypto/Encryption.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/encryption/lib/Crypto/Encryption.php b/apps/encryption/lib/Crypto/Encryption.php index 15b6fd77b95be..4c964fc61fd42 100644 --- a/apps/encryption/lib/Crypto/Encryption.php +++ b/apps/encryption/lib/Crypto/Encryption.php @@ -60,7 +60,7 @@ class Encryption implements IEncryptionModule { /** @var string */ private $user; - /** @var string */ + /** @var array */ private $owner; /** @var string */ @@ -139,6 +139,7 @@ public function __construct(Crypt $crypt, $this->decryptAll = $decryptAll; $this->logger = $logger; $this->l = $il10n; + $this->owner = []; $this->useMasterPassword = $util->isMasterKeyEnabled(); } @@ -177,7 +178,6 @@ public function begin($path, $user, $mode, array $header, array $accessList) { $this->path = $this->getPathToRealFile($path); $this->accessList = $accessList; $this->user = $user; - $this->owner = $this->util->getOwner($path); $this->isWriteOperation = false; $this->writeCache = ''; @@ -284,7 +284,7 @@ public function end($path, $position = 0) { } } - $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->owner); + $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys, $this->getOwner($path)); $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys); $this->keyManager->setAllFileKeys($this->path, $encryptedKeyfiles); } @@ -413,7 +413,7 @@ public function update($path, $uid, array $accessList) { } } - $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $this->owner); + $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys, $this->getOwner($path)); $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys); @@ -562,6 +562,19 @@ protected function stripPartFileExtension($path) { return $path; } + /** + * get owner of a file + * + * @param string $path + * @return string + */ + protected function getOwner($path) { + if (!isset($this->owner[$path])) { + $this->owner[$path] = $this->util->getOwner($path); + } + return $this->owner[$path]; + } + /** * Check if the module is ready to be used by that specific user. * In case a module is not ready - because e.g. key pairs have not been generated