aboutsummaryrefslogtreecommitdiffstats
path: root/apps/encryption/lib/KeyManager.php
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2023-03-16 14:53:51 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-03-17 11:08:58 +0100
commit8900d030d1a6359a0b58b7257e3a3fd33db4a6a4 (patch)
tree5e32030a28cc1fb245d38098da7d84cb93a25e5d /apps/encryption/lib/KeyManager.php
parentfbe282caeb7dd0d91435f6f547db027e500e248a (diff)
downloadnextcloud-server-8900d030d1a6359a0b58b7257e3a3fd33db4a6a4.tar.gz
nextcloud-server-8900d030d1a6359a0b58b7257e3a3fd33db4a6a4.zip
Adapt code to new encryption system
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 <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/encryption/lib/KeyManager.php')
-rw-r--r--apps/encryption/lib/KeyManager.php18
1 files changed, 12 insertions, 6 deletions
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