From 8900d030d1a6359a0b58b7257e3a3fd33db4a6a4 Mon Sep 17 00:00:00 2001 From: Côme Chilliet Date: Thu, 16 Mar 2023 14:53:51 +0100 Subject: Adapt code to new encryption system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fileKey gets deleted upon save as it’s stored in shareKeys instead now. We use presence of a fileKey to detect if a file is using the legacy system or the new one, because we do not always have access to header data. Signed-off-by: Côme Chilliet --- apps/encryption/lib/KeyManager.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'apps/encryption/lib/KeyManager.php') diff --git a/apps/encryption/lib/KeyManager.php b/apps/encryption/lib/KeyManager.php index 5f35f7a8422..5c933b5f8b2 100644 --- a/apps/encryption/lib/KeyManager.php +++ b/apps/encryption/lib/KeyManager.php @@ -440,18 +440,19 @@ class KeyManager { /** * @param string $path * @param $uid + * @param ?bool $useLegacyFileKey null means try both * @return string */ - public function getFileKey(string $path, ?string $uid, bool $useLegacyFileKey): string { + public function getFileKey(string $path, ?string $uid, ?bool $useLegacyFileKey): string { if ($uid === '') { $uid = null; } $publicAccess = is_null($uid); - - if ($useLegacyFileKey) { + $encryptedFileKey = ''; + if ($useLegacyFileKey ?? true) { $encryptedFileKey = $this->keyStorage->getFileKey($path, $this->fileKeyId, Encryption::ID); - if (empty($encryptedFileKey)) { + if (empty($encryptedFileKey) && $useLegacyFileKey) { return ''; } } @@ -477,13 +478,14 @@ class KeyManager { $privateKey = $this->session->getPrivateKey(); } - if ($useLegacyFileKey) { + if ($useLegacyFileKey ?? true) { if ($encryptedFileKey && $shareKey && $privateKey) { return $this->crypt->multiKeyDecryptLegacy($encryptedFileKey, $shareKey, $privateKey); } - } else { + } + if ($useLegacyFileKey ?? false) { if ($shareKey && $privateKey) { return $this->crypt->multiKeyDecrypt($shareKey, $privateKey); } @@ -664,6 +666,10 @@ class KeyManager { return $this->keyStorage->deleteAllFileKeys($path); } + public function deleteLegacyFileKey(string $path): bool { + return $this->keyStorage->deleteFileKey($path, $this->fileKeyId, Encryption::ID); + } + /** * @param array $userIds * @return array -- cgit v1.2.3