diff options
Diffstat (limited to 'core/Command/Encryption/MigrateKeyStorage.php')
-rw-r--r-- | core/Command/Encryption/MigrateKeyStorage.php | 84 |
1 files changed, 30 insertions, 54 deletions
diff --git a/core/Command/Encryption/MigrateKeyStorage.php b/core/Command/Encryption/MigrateKeyStorage.php index 43b725f6ad8..8d9c7910769 100644 --- a/core/Command/Encryption/MigrateKeyStorage.php +++ b/core/Command/Encryption/MigrateKeyStorage.php @@ -38,25 +38,12 @@ 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; + protected View $rootView; + protected IUserManager $userManager; + protected IConfig $config; + protected Util $util; + protected QuestionHelper $questionHelper; + private ICrypto $crypto; public function __construct(View $view, IUserManager $userManager, IConfig $config, Util $util, ICrypto $crypto) { parent::__construct(); @@ -85,14 +72,14 @@ class MigrateKeyStorage extends Command { } /** - * 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) { + protected function updateKeys(string $root, OutputInterface $output): bool { $output->writeln("Start to update the keys:"); $this->updateSystemKeys($root); @@ -102,11 +89,9 @@ class MigrateKeyStorage extends Command { } /** - * move system key folder - * - * @param string $root + * Move system key folder */ - protected function updateSystemKeys($root) { + protected function updateSystemKeys(string $root): void { if (!$this->rootView->is_dir($root . '/files_encryption')) { return; } @@ -119,40 +104,31 @@ class MigrateKeyStorage extends Command { 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); - - 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); } } } |