diff options
Diffstat (limited to 'core/Command/Encryption')
-rw-r--r-- | core/Command/Encryption/ChangeKeyStorageRoot.php | 75 | ||||
-rw-r--r-- | core/Command/Encryption/DecryptAll.php | 101 | ||||
-rw-r--r-- | core/Command/Encryption/Disable.php | 34 | ||||
-rw-r--r-- | core/Command/Encryption/Enable.php | 64 | ||||
-rw-r--r-- | core/Command/Encryption/EncryptAll.php | 86 | ||||
-rw-r--r-- | core/Command/Encryption/ListModules.php | 47 | ||||
-rw-r--r-- | core/Command/Encryption/MigrateKeyStorage.php | 174 | ||||
-rw-r--r-- | core/Command/Encryption/SetDefaultModule.php | 45 | ||||
-rw-r--r-- | core/Command/Encryption/ShowKeyStorageRoot.php | 37 | ||||
-rw-r--r-- | core/Command/Encryption/Status.php | 34 |
10 files changed, 179 insertions, 518 deletions
diff --git a/core/Command/Encryption/ChangeKeyStorageRoot.php b/core/Command/Encryption/ChangeKeyStorageRoot.php index c178949364e..3049fd2ca08 100644 --- a/core/Command/Encryption/ChangeKeyStorageRoot.php +++ b/core/Command/Encryption/ChangeKeyStorageRoot.php @@ -1,29 +1,10 @@ <?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 Morris Jobke <hey@morrisjobke.de> - * - * @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\Core\Command\Encryption; use OC\Encryption\Keys\Storage; @@ -41,36 +22,14 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; class ChangeKeyStorageRoot extends Command { - - /** @var View */ - protected $rootView; - - /** @var IUserManager */ - protected $userManager; - - /** @var IConfig */ - protected $config; - - /** @var Util */ - protected $util; - - /** @var QuestionHelper */ - protected $questionHelper; - - /** - * @param View $view - * @param IUserManager $userManager - * @param IConfig $config - * @param Util $util - * @param QuestionHelper $questionHelper - */ - public function __construct(View $view, IUserManager $userManager, IConfig $config, Util $util, QuestionHelper $questionHelper) { + public function __construct( + protected View $rootView, + protected IUserManager $userManager, + protected IConfig $config, + protected Util $util, + protected QuestionHelper $questionHelper, + ) { parent::__construct(); - $this->rootView = $view; - $this->userManager = $userManager; - $this->config = $config; - $this->util = $util; - $this->questionHelper = $questionHelper; } protected function configure() { @@ -120,10 +79,10 @@ class ChangeKeyStorageRoot extends Command { * @throws \Exception */ protected function moveAllKeys($oldRoot, $newRoot, OutputInterface $output) { - $output->writeln("Start to move keys:"); + $output->writeln('Start to move keys:'); if ($this->rootView->is_dir($oldRoot) === false) { - $output->writeln("No old keys found: Nothing needs to be moved"); + $output->writeln('No old keys found: Nothing needs to be moved'); return false; } @@ -164,8 +123,8 @@ class ChangeKeyStorageRoot extends Command { */ protected function moveSystemKeys($oldRoot, $newRoot) { if ( - $this->rootView->is_dir($oldRoot . '/files_encryption') && - $this->targetExists($newRoot . '/files_encryption') === false + $this->rootView->is_dir($oldRoot . '/files_encryption') + && $this->targetExists($newRoot . '/files_encryption') === false ) { $this->rootView->rename($oldRoot . '/files_encryption', $newRoot . '/files_encryption'); } @@ -224,8 +183,8 @@ class ChangeKeyStorageRoot extends Command { $source = $oldRoot . '/' . $user . '/files_encryption'; $target = $newRoot . '/' . $user . '/files_encryption'; if ( - $this->rootView->is_dir($source) && - $this->targetExists($target) === false + $this->rootView->is_dir($source) + && $this->targetExists($target) === false ) { $this->prepareParentFolder($newRoot . '/' . $user); $this->rootView->rename($source, $target); diff --git a/core/Command/Encryption/DecryptAll.php b/core/Command/Encryption/DecryptAll.php index 6166a940861..92e2ba787e2 100644 --- a/core/Command/Encryption/DecryptAll.php +++ b/core/Command/Encryption/DecryptAll.php @@ -1,34 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author davitol <dtoledo@solidgear.es> - * @author Evgeny Golyshev <eugulixes@gmail.com> - * @author Joas Schilling <coding@schilljs.com> - * @author Marius Blüm <marius@lineone.io> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Ruben Homs <ruben@homs.codes> - * @author Sergio Bertolín <sbertolin@solidgear.es> - * @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\Core\Command\Encryption; use OCP\App\IAppManager; @@ -42,55 +18,23 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; class DecryptAll extends Command { + protected bool $wasTrashbinEnabled = false; + protected bool $wasMaintenanceModeEnabled = false; - /** @var IManager */ - protected $encryptionManager; - - /** @var IAppManager */ - protected $appManager; - - /** @var IConfig */ - protected $config; - - /** @var QuestionHelper */ - protected $questionHelper; - - /** @var bool */ - protected $wasTrashbinEnabled; - - /** @var bool */ - protected $wasMaintenanceModeEnabled; - - /** @var \OC\Encryption\DecryptAll */ - protected $decryptAll; - - /** - * @param IManager $encryptionManager - * @param IAppManager $appManager - * @param IConfig $config - * @param \OC\Encryption\DecryptAll $decryptAll - * @param QuestionHelper $questionHelper - */ public function __construct( - IManager $encryptionManager, - IAppManager $appManager, - IConfig $config, - \OC\Encryption\DecryptAll $decryptAll, - QuestionHelper $questionHelper + protected IManager $encryptionManager, + protected IAppManager $appManager, + protected IConfig $config, + protected \OC\Encryption\DecryptAll $decryptAll, + protected QuestionHelper $questionHelper, ) { parent::__construct(); - - $this->appManager = $appManager; - $this->encryptionManager = $encryptionManager; - $this->config = $config; - $this->decryptAll = $decryptAll; - $this->questionHelper = $questionHelper; } /** * Set maintenance mode and disable the trashbin app */ - protected function forceMaintenanceAndTrashbin() { + protected function forceMaintenanceAndTrashbin(): void { $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); $this->wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); $this->config->setSystemValue('maintenance', true); @@ -100,7 +44,7 @@ class DecryptAll extends Command { /** * Reset the maintenance mode and re-enable the trashbin app */ - protected function resetMaintenanceAndTrashbin() { + protected function resetMaintenanceAndTrashbin(): void { $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); if ($this->wasTrashbinEnabled) { $this->appManager->enableApp('files_trashbin'); @@ -137,10 +81,10 @@ class DecryptAll extends Command { $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); if ($isMaintenanceModeEnabled) { - $output->writeln("Maintenance mode must be disabled when starting decryption,"); - $output->writeln("in order to load the relevant encryption modules correctly."); - $output->writeln("Your instance will automatically be put to maintenance mode"); - $output->writeln("during the actual decryption of the files."); + $output->writeln('Maintenance mode must be disabled when starting decryption,'); + $output->writeln('in order to load the relevant encryption modules correctly.'); + $output->writeln('Your instance will automatically be put to maintenance mode'); + $output->writeln('during the actual decryption of the files.'); return 1; } @@ -182,13 +126,12 @@ class DecryptAll extends Command { } $this->resetMaintenanceAndTrashbin(); return 0; - } else { - $output->write('Enable server side encryption... '); - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); - $output->writeln('done.'); - $output->writeln('aborted'); - return 1; } + $output->write('Enable server side encryption... '); + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); + $output->writeln('done.'); + $output->writeln('aborted'); + return 1; } catch (\Exception $e) { // enable server side encryption again if something went wrong $this->config->setAppValue('core', 'encryption_enabled', 'yes'); diff --git a/core/Command/Encryption/Disable.php b/core/Command/Encryption/Disable.php index c188e6c097b..91d4ac82d23 100644 --- a/core/Command/Encryption/Disable.php +++ b/core/Command/Encryption/Disable.php @@ -1,25 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.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\Core\Command\Encryption; use OCP\IConfig; @@ -28,15 +13,10 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class Disable extends Command { - /** @var IConfig */ - protected $config; - - /** - * @param IConfig $config - */ - public function __construct(IConfig $config) { + public function __construct( + protected IConfig $config, + ) { parent::__construct(); - $this->config = $config; } protected function configure() { diff --git a/core/Command/Encryption/Enable.php b/core/Command/Encryption/Enable.php index 2de6eb2e0c7..2c476185692 100644 --- a/core/Command/Encryption/Enable.php +++ b/core/Command/Encryption/Enable.php @@ -1,26 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.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\Core\Command\Encryption; use OCP\Encryption\IManager; @@ -30,21 +14,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class Enable extends Command { - /** @var IConfig */ - protected $config; - - /** @var IManager */ - protected $encryptionManager; - - /** - * @param IConfig $config - * @param IManager $encryptionManager - */ - public function __construct(IConfig $config, IManager $encryptionManager) { + public function __construct( + protected IConfig $config, + protected IManager $encryptionManager, + ) { parent::__construct(); - - $this->encryptionManager = $encryptionManager; - $this->config = $config; } protected function configure() { @@ -67,18 +41,18 @@ class Enable extends Command { if (empty($modules)) { $output->writeln('<error>No encryption module is loaded</error>'); return 1; - } else { - $defaultModule = $this->config->getAppValue('core', 'default_encryption_module', null); - if ($defaultModule === null) { - $output->writeln('<error>No default module is set</error>'); - return 1; - } elseif (!isset($modules[$defaultModule])) { - $output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>'); - return 1; - } else { - $output->writeln('Default module: ' . $defaultModule); - } } + $defaultModule = $this->config->getAppValue('core', 'default_encryption_module', null); + if ($defaultModule === null) { + $output->writeln('<error>No default module is set</error>'); + return 1; + } + if (!isset($modules[$defaultModule])) { + $output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>'); + return 1; + } + $output->writeln('Default module: ' . $defaultModule); + return 0; } } diff --git a/core/Command/Encryption/EncryptAll.php b/core/Command/Encryption/EncryptAll.php index 0be03fd95b1..f2c991471b6 100644 --- a/core/Command/Encryption/EncryptAll.php +++ b/core/Command/Encryption/EncryptAll.php @@ -1,30 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Evgeny Golyshev <eugulixes@gmail.com> - * @author Joas Schilling <coding@schilljs.com> - * @author Matthew Setter <matthew@matthewsetter.com> - * @author Morris Jobke <hey@morrisjobke.de> - * - * @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\Core\Command\Encryption; use OCP\App\IAppManager; @@ -37,50 +17,22 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; class EncryptAll extends Command { + protected bool $wasTrashbinEnabled = false; - /** @var IManager */ - protected $encryptionManager; - - /** @var IAppManager */ - protected $appManager; - - /** @var IConfig */ - protected $config; - - /** @var QuestionHelper */ - protected $questionHelper; - - /** @var bool */ - protected $wasTrashbinEnabled; - - /** @var bool */ - protected $wasMaintenanceModeEnabled; - - /** - * @param IManager $encryptionManager - * @param IAppManager $appManager - * @param IConfig $config - * @param QuestionHelper $questionHelper - */ public function __construct( - IManager $encryptionManager, - IAppManager $appManager, - IConfig $config, - QuestionHelper $questionHelper + protected IManager $encryptionManager, + protected IAppManager $appManager, + protected IConfig $config, + protected QuestionHelper $questionHelper, ) { parent::__construct(); - $this->appManager = $appManager; - $this->encryptionManager = $encryptionManager; - $this->config = $config; - $this->questionHelper = $questionHelper; } /** * Set maintenance mode and disable the trashbin app */ - protected function forceMaintenanceAndTrashbin() { - $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); - $this->wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); + protected function forceMaintenanceAndTrashbin(): void { + $this->wasTrashbinEnabled = (bool)$this->appManager->isEnabledForUser('files_trashbin'); $this->config->setSystemValue('maintenance', true); $this->appManager->disableApp('files_trashbin'); } @@ -88,8 +40,8 @@ class EncryptAll extends Command { /** * Reset the maintenance mode and re-enable the trashbin app */ - protected function resetMaintenanceAndTrashbin() { - $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); + protected function resetMaintenanceAndTrashbin(): void { + $this->config->setSystemValue('maintenance', false); if ($this->wasTrashbinEnabled) { $this->appManager->enableApp('files_trashbin'); } @@ -120,6 +72,11 @@ class EncryptAll extends Command { throw new \Exception('Server side encryption is not enabled'); } + if ($this->config->getSystemValueBool('maintenance')) { + $output->writeln('<error>This command cannot be run with maintenance mode enabled.</error>'); + return self::FAILURE; + } + $output->writeln("\n"); $output->writeln('You are about to encrypt all files stored in your Nextcloud installation.'); $output->writeln('Depending on the number of available files, and their size, this may take quite some time.'); @@ -139,10 +96,9 @@ class EncryptAll extends Command { } $this->resetMaintenanceAndTrashbin(); - } else { - $output->writeln('aborted'); - return 1; + return self::SUCCESS; } - return 0; + $output->writeln('aborted'); + return self::FAILURE; } } diff --git a/core/Command/Encryption/ListModules.php b/core/Command/Encryption/ListModules.php index 21a8be8057f..bf02c29f432 100644 --- a/core/Command/Encryption/ListModules.php +++ b/core/Command/Encryption/ListModules.php @@ -1,27 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Ruben Homs <ruben@homs.codes> - * - * @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\Core\Command\Encryption; use OC\Core\Command\Base; @@ -31,23 +14,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class ListModules extends Base { - /** @var IManager */ - protected $encryptionManager; - - /** @var IConfig */ - protected $config; - - /** - * @param IManager $encryptionManager - * @param IConfig $config - */ public function __construct( - IManager $encryptionManager, - IConfig $config + protected IManager $encryptionManager, + protected IConfig $config, ) { parent::__construct(); - $this->encryptionManager = $encryptionManager; - $this->config = $config; } protected function configure() { @@ -62,8 +33,8 @@ class ListModules extends Base { protected function execute(InputInterface $input, OutputInterface $output): int { $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); if ($isMaintenanceModeEnabled) { - $output->writeln("Maintenance mode must be disabled when listing modules"); - $output->writeln("in order to list the relevant encryption modules correctly."); + $output->writeln('Maintenance mode must be disabled when listing modules'); + $output->writeln('in order to list the relevant encryption modules correctly.'); return 1; } @@ -86,7 +57,7 @@ class ListModules extends Base { */ protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) { if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { - array_walk($items, function (&$item) { + array_walk($items, function (&$item): void { if (!$item['default']) { $item = $item['displayName']; } else { diff --git a/core/Command/Encryption/MigrateKeyStorage.php b/core/Command/Encryption/MigrateKeyStorage.php index 98dea8fad5c..937b17cde5f 100644 --- a/core/Command/Encryption/MigrateKeyStorage.php +++ b/core/Command/Encryption/MigrateKeyStorage.php @@ -3,28 +3,9 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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 - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - - namespace OC\Core\Command\Encryption; use OC\Encryption\Keys\Storage; @@ -35,41 +16,21 @@ use OCP\IUserManager; use OCP\Security\ICrypto; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class MigrateKeyStorage extends Command { - - /** @var View */ - protected $rootView; - - /** @var IUserManager */ - protected $userManager; - - /** @var IConfig */ - protected $config; - - /** @var Util */ - protected $util; - - /** @var QuestionHelper */ - protected $questionHelper; - /** - * @var ICrypto - */ - private $crypto; - - public function __construct(View $view, IUserManager $userManager, IConfig $config, Util $util, ICrypto $crypto) { + public function __construct( + protected View $rootView, + protected IUserManager $userManager, + protected IConfig $config, + protected Util $util, + private ICrypto $crypto, + ) { parent::__construct(); - $this->rootView = $view; - $this->userManager = $userManager; - $this->config = $config; - $this->util = $util; - $this->crypto = $crypto; } - protected function configure() { + protected function configure(): void { parent::configure(); $this ->setName('encryption:migrate-key-storage-format') @@ -79,94 +40,85 @@ class MigrateKeyStorage extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { $root = $this->util->getKeyStorageRoot(); - $output->writeln("Updating key storage format"); + $output->writeln('Updating key storage format'); $this->updateKeys($root, $output); - $output->writeln("Key storage format successfully updated"); + $output->writeln('Key storage format successfully updated'); return 0; } /** - * move keys to new key storage root + * Move keys to new key storage root * - * @param string $root - * @param OutputInterface $output - * @return bool * @throws \Exception */ - protected function updateKeys(string $root, OutputInterface $output) { - $output->writeln("Start to update the keys:"); + protected function updateKeys(string $root, OutputInterface $output): bool { + $output->writeln('Start to update the keys:'); - $this->updateSystemKeys($root); + $this->updateSystemKeys($root, $output); $this->updateUsersKeys($root, $output); $this->config->deleteSystemValue('encryption.key_storage_migrated'); return true; } /** - * move system key folder - * - * @param string $root + * Move system key folder */ - protected function updateSystemKeys($root) { + protected function updateSystemKeys(string $root, OutputInterface $output): void { if (!$this->rootView->is_dir($root . '/files_encryption')) { return; } - $this->traverseKeys($root . '/files_encryption', null); + $this->traverseKeys($root . '/files_encryption', null, $output); } - private function traverseKeys(string $folder, ?string $uid) { + private function traverseKeys(string $folder, ?string $uid, OutputInterface $output): void { $listing = $this->rootView->getDirectoryContent($folder); foreach ($listing as $node) { if ($node['mimetype'] === 'httpd/unix-directory') { - //ignore - } else { - $endsWith = function ($haystack, $needle) { - $length = strlen($needle); - if ($length === 0) { - return true; - } + continue; + } - return (substr($haystack, -$length) === $needle); - }; + if ($node['name'] === 'fileKey' + || str_ends_with($node['name'], '.privateKey') + || str_ends_with($node['name'], '.publicKey') + || str_ends_with($node['name'], '.shareKey')) { + $path = $folder . '/' . $node['name']; - if ($node['name'] === 'fileKey' || - $endsWith($node['name'], '.privateKey') || - $endsWith($node['name'], '.publicKey') || - $endsWith($node['name'], '.shareKey')) { - $path = $folder . '/' . $node['name']; + $content = $this->rootView->file_get_contents($path); - $content = $this->rootView->file_get_contents($path); + if ($content === false) { + $output->writeln("<error>Failed to open path $path</error>"); + continue; + } - try { - $this->crypto->decrypt($content); - continue; - } catch (\Exception $e) { - // Ignore we now update the data. - } + try { + $this->crypto->decrypt($content); + continue; + } catch (\Exception $e) { + // Ignore we now update the data. + } - $data = [ - 'key' => base64_encode($content), - 'uid' => $uid, - ]; + $data = [ + 'key' => base64_encode($content), + 'uid' => $uid, + ]; - $enc = $this->crypto->encrypt(json_encode($data)); - $this->rootView->file_put_contents($path, $enc); - } + $enc = $this->crypto->encrypt(json_encode($data)); + $this->rootView->file_put_contents($path, $enc); } } } - private function traverseFileKeys(string $folder) { + private function traverseFileKeys(string $folder, OutputInterface $output): void { $listing = $this->rootView->getDirectoryContent($folder); foreach ($listing as $node) { if ($node['mimetype'] === 'httpd/unix-directory') { - $this->traverseFileKeys($folder . '/' . $node['name']); + $this->traverseFileKeys($folder . '/' . $node['name'], $output); } else { - $endsWith = function ($haystack, $needle) { + $endsWith = function (string $haystack, string $needle): bool { $length = strlen($needle); if ($length === 0) { return true; @@ -175,14 +127,19 @@ class MigrateKeyStorage extends Command { return (substr($haystack, -$length) === $needle); }; - if ($node['name'] === 'fileKey' || - $endsWith($node['name'], '.privateKey') || - $endsWith($node['name'], '.publicKey') || - $endsWith($node['name'], '.shareKey')) { + if ($node['name'] === 'fileKey' + || $endsWith($node['name'], '.privateKey') + || $endsWith($node['name'], '.publicKey') + || $endsWith($node['name'], '.shareKey')) { $path = $folder . '/' . $node['name']; $content = $this->rootView->file_get_contents($path); + if ($content === false) { + $output->writeln("<error>Failed to open path $path</error>"); + continue; + } + try { $this->crypto->decrypt($content); continue; @@ -204,10 +161,8 @@ class MigrateKeyStorage extends Command { /** * setup file system for the given user - * - * @param string $uid */ - protected function setupUserFS($uid) { + protected function setupUserFS(string $uid): void { \OC_Util::tearDownFS(); \OC_Util::setupFS($uid); } @@ -215,11 +170,8 @@ class MigrateKeyStorage extends Command { /** * iterate over each user and move the keys to the new storage - * - * @param string $root - * @param OutputInterface $output */ - protected function updateUsersKeys(string $root, OutputInterface $output) { + protected function updateUsersKeys(string $root, OutputInterface $output): void { $progress = new ProgressBar($output); $progress->start(); @@ -231,7 +183,7 @@ class MigrateKeyStorage extends Command { foreach ($users as $user) { $progress->advance(); $this->setupUserFS($user); - $this->updateUserKeys($root, $user); + $this->updateUserKeys($root, $user, $output); } $offset += $limit; } while (count($users) >= $limit); @@ -242,20 +194,18 @@ class MigrateKeyStorage extends Command { /** * move user encryption folder to new root folder * - * @param string $root - * @param string $user * @throws \Exception */ - protected function updateUserKeys(string $root, string $user) { + protected function updateUserKeys(string $root, string $user, OutputInterface $output): void { if ($this->userManager->userExists($user)) { $source = $root . '/' . $user . '/files_encryption/OC_DEFAULT_MODULE'; if ($this->rootView->is_dir($source)) { - $this->traverseKeys($source, $user); + $this->traverseKeys($source, $user, $output); } $source = $root . '/' . $user . '/files_encryption/keys'; if ($this->rootView->is_dir($source)) { - $this->traverseFileKeys($source); + $this->traverseFileKeys($source, $output); } } } diff --git a/core/Command/Encryption/SetDefaultModule.php b/core/Command/Encryption/SetDefaultModule.php index 21c1ba77322..d10872afd38 100644 --- a/core/Command/Encryption/SetDefaultModule.php +++ b/core/Command/Encryption/SetDefaultModule.php @@ -1,27 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Ruben Homs <ruben@homs.codes> - * - * @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\Core\Command\Encryption; use OCP\Encryption\IManager; @@ -32,23 +15,11 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class SetDefaultModule extends Command { - /** @var IManager */ - protected $encryptionManager; - - /** @var IConfig */ - protected $config; - - /** - * @param IManager $encryptionManager - * @param IConfig $config - */ public function __construct( - IManager $encryptionManager, - IConfig $config + protected IManager $encryptionManager, + protected IConfig $config, ) { parent::__construct(); - $this->encryptionManager = $encryptionManager; - $this->config = $config; } protected function configure() { @@ -68,8 +39,8 @@ class SetDefaultModule extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); if ($isMaintenanceModeEnabled) { - $output->writeln("Maintenance mode must be disabled when setting default module,"); - $output->writeln("in order to load the relevant encryption modules correctly."); + $output->writeln('Maintenance mode must be disabled when setting default module,'); + $output->writeln('in order to load the relevant encryption modules correctly.'); return 1; } diff --git a/core/Command/Encryption/ShowKeyStorageRoot.php b/core/Command/Encryption/ShowKeyStorageRoot.php index c3e2cc40932..8cf97076249 100644 --- a/core/Command/Encryption/ShowKeyStorageRoot.php +++ b/core/Command/Encryption/ShowKeyStorageRoot.php @@ -1,27 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Björn Schießle <bjoern@schiessle.org> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.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\Core\Command\Encryption; use OC\Encryption\Util; @@ -30,16 +13,10 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class ShowKeyStorageRoot extends Command { - - /** @var Util */ - protected $util; - - /** - * @param Util $util - */ - public function __construct(Util $util) { + public function __construct( + protected Util $util, + ) { parent::__construct(); - $this->util = $util; } protected function configure() { diff --git a/core/Command/Encryption/Status.php b/core/Command/Encryption/Status.php index b7a6f33d7d8..6e4f7d16d0c 100644 --- a/core/Command/Encryption/Status.php +++ b/core/Command/Encryption/Status.php @@ -1,25 +1,10 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Joas Schilling <coding@schilljs.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\Core\Command\Encryption; use OC\Core\Command\Base; @@ -28,15 +13,10 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class Status extends Base { - /** @var IManager */ - protected $encryptionManager; - - /** - * @param IManager $encryptionManager - */ - public function __construct(IManager $encryptionManager) { + public function __construct( + protected IManager $encryptionManager, + ) { parent::__construct(); - $this->encryptionManager = $encryptionManager; } protected function configure() { |