diff options
Diffstat (limited to 'lib/private/Encryption/Keys/Storage.php')
-rw-r--r-- | lib/private/Encryption/Keys/Storage.php | 68 |
1 files changed, 14 insertions, 54 deletions
diff --git a/lib/private/Encryption/Keys/Storage.php b/lib/private/Encryption/Keys/Storage.php index b6376dc0146..cce22b9138a 100644 --- a/lib/private/Encryption/Keys/Storage.php +++ b/lib/private/Encryption/Keys/Storage.php @@ -1,29 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bjoern Schiessle <bjoern@schiessle.org> - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OC\Encryption\Keys; @@ -78,8 +58,8 @@ class Storage implements IStorage { $this->util = $util; $this->encryption_base_dir = '/files_encryption'; - $this->keys_base_dir = $this->encryption_base_dir .'/keys'; - $this->backup_base_dir = $this->encryption_base_dir .'/backup'; + $this->keys_base_dir = $this->encryption_base_dir . '/keys'; + $this->backup_base_dir = $this->encryption_base_dir . '/backup'; $this->root_dir = $this->util->getKeyStorageRoot(); $this->crypto = $crypto; $this->config = $config; @@ -98,14 +78,14 @@ class Storage implements IStorage { */ public function getFileKey($path, $keyId, $encryptionModuleId) { $realFile = $this->util->stripPartialFileExtension($path); - $keyDir = $this->getFileKeyDir($encryptionModuleId, $realFile); + $keyDir = $this->util->getFileKeyDir($encryptionModuleId, $realFile); $key = $this->getKey($keyDir . $keyId)['key']; if ($key === '' && $realFile !== $path) { // Check if the part file has keys and use them, if no normal keys // exist. This is required to fix copyBetweenStorage() when we // rename a .part file over storage borders. - $keyDir = $this->getFileKeyDir($encryptionModuleId, $path); + $keyDir = $this->util->getFileKeyDir($encryptionModuleId, $path); $key = $this->getKey($keyDir . $keyId)['key']; } @@ -135,7 +115,7 @@ class Storage implements IStorage { * @inheritdoc */ public function setFileKey($path, $keyId, $key, $encryptionModuleId) { - $keyDir = $this->getFileKeyDir($encryptionModuleId, $path); + $keyDir = $this->util->getFileKeyDir($encryptionModuleId, $path); return $this->setKey($keyDir . $keyId, [ 'key' => base64_encode($key), ]); @@ -177,7 +157,7 @@ class Storage implements IStorage { * @inheritdoc */ public function deleteFileKey($path, $keyId, $encryptionModuleId) { - $keyDir = $this->getFileKeyDir($encryptionModuleId, $path); + $keyDir = $this->util->getFileKeyDir($encryptionModuleId, $path); return !$this->view->file_exists($keyDir . $keyId) || $this->view->unlink($keyDir . $keyId); } @@ -185,7 +165,7 @@ class Storage implements IStorage { * @inheritdoc */ public function deleteAllFileKeys($path) { - $keyDir = $this->getFileKeyDir('', $path); + $keyDir = $this->util->getFileKeyDir('', $path); return !$this->view->file_exists($keyDir) || $this->view->deleteAll($keyDir); } @@ -237,7 +217,7 @@ class Storage implements IStorage { if (!array_key_exists('uid', $data) || $data['uid'] !== $uid) { // If the migration is done we error out - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); + $versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0.0'); if (version_compare($versionFromBeforeUpdate, '20.0.0.1', '<=')) { return $data['key']; } @@ -272,7 +252,7 @@ class Storage implements IStorage { $data = $this->view->file_get_contents($path); // Version <20.0.0.1 doesn't have this - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); + $versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0.0'); if (version_compare($versionFromBeforeUpdate, '20.0.0.1', '<=')) { $key = [ 'key' => base64_encode($data), @@ -335,7 +315,7 @@ class Storage implements IStorage { private function setKey($path, $key) { $this->keySetPreparation(dirname($path)); - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); + $versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0.0'); if (version_compare($versionFromBeforeUpdate, '20.0.0.1', '<=')) { // Only store old format if this happens during the migration. // TODO: Remove for 21 @@ -356,26 +336,6 @@ class Storage implements IStorage { } /** - * get path to key folder for a given file - * - * @param string $encryptionModuleId - * @param string $path path to the file, relative to data/ - * @return string - */ - private function getFileKeyDir($encryptionModuleId, $path) { - [$owner, $filename] = $this->util->getUidAndFilename($path); - - // in case of system wide mount points the keys are stored directly in the data directory - if ($this->util->isSystemWideMountPoint($filename, $owner)) { - $keyPath = $this->root_dir . '/' . $this->keys_base_dir . $filename . '/'; - } else { - $keyPath = $this->root_dir . '/' . $owner . $this->keys_base_dir . $filename . '/'; - } - - return Filesystem::normalizePath($keyPath . $encryptionModuleId . '/', false); - } - - /** * move keys if a file was renamed * * @param string $source |