aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/Encryption
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-04-12 17:55:01 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-05-20 22:18:06 +0200
commitb70c6a128fe5d0053b7971881696eafce4cb7c26 (patch)
tree641ff76531803c207a92d86f47d46b6dd93ab6d3 /core/Command/Encryption
parent2b0d82675f669f00ad90f2750b1832a60ec9f766 (diff)
downloadnextcloud-server-b70c6a128fe5d0053b7971881696eafce4cb7c26.tar.gz
nextcloud-server-b70c6a128fe5d0053b7971881696eafce4cb7c26.zip
Update core to PHP 7.4 standard
- Typed properties - Port to LoggerInterface Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'core/Command/Encryption')
-rw-r--r--core/Command/Encryption/ChangeKeyStorageRoot.php27
-rw-r--r--core/Command/Encryption/DecryptAll.php50
-rw-r--r--core/Command/Encryption/Disable.php6
-rw-r--r--core/Command/Encryption/Enable.php11
-rw-r--r--core/Command/Encryption/EncryptAll.php43
-rw-r--r--core/Command/Encryption/ListModules.php11
-rw-r--r--core/Command/Encryption/MigrateKeyStorage.php84
-rw-r--r--core/Command/Encryption/SetDefaultModule.php11
-rw-r--r--core/Command/Encryption/ShowKeyStorageRoot.php7
-rw-r--r--core/Command/Encryption/Status.php6
10 files changed, 70 insertions, 186 deletions
diff --git a/core/Command/Encryption/ChangeKeyStorageRoot.php b/core/Command/Encryption/ChangeKeyStorageRoot.php
index 633ae2c4a7a..6ae59421a69 100644
--- a/core/Command/Encryption/ChangeKeyStorageRoot.php
+++ b/core/Command/Encryption/ChangeKeyStorageRoot.php
@@ -40,29 +40,12 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class ChangeKeyStorageRoot extends Command {
+ protected View $rootView;
+ protected IUserManager $userManager;
+ protected IConfig $config;
+ protected Util $util;
+ protected QuestionHelper $questionHelper;
- /** @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) {
parent::__construct();
$this->rootView = $view;
diff --git a/core/Command/Encryption/DecryptAll.php b/core/Command/Encryption/DecryptAll.php
index 7382c254723..ce17f787abd 100644
--- a/core/Command/Encryption/DecryptAll.php
+++ b/core/Command/Encryption/DecryptAll.php
@@ -41,35 +41,14 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class DecryptAll extends Command {
+ protected IManager $encryptionManager;
+ protected IAppManager $appManager;
+ protected IConfig $config;
+ protected QuestionHelper $questionHelper;
+ protected bool $wasTrashbinEnabled;
+ protected bool $wasMaintenanceModeEnabled;
+ protected \OC\Encryption\DecryptAll $decryptAll;
- /** @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,
@@ -89,7 +68,7 @@ class DecryptAll extends Command {
/**
* 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);
@@ -99,7 +78,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');
@@ -181,13 +160,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 fca810b2ab2..446601a1b4f 100644
--- a/core/Command/Encryption/Disable.php
+++ b/core/Command/Encryption/Disable.php
@@ -27,12 +27,8 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Disable extends Command {
- /** @var IConfig */
- protected $config;
+ protected IConfig $config;
- /**
- * @param IConfig $config
- */
public function __construct(IConfig $config) {
parent::__construct();
$this->config = $config;
diff --git a/core/Command/Encryption/Enable.php b/core/Command/Encryption/Enable.php
index 99c60bc9b5f..9d680144e60 100644
--- a/core/Command/Encryption/Enable.php
+++ b/core/Command/Encryption/Enable.php
@@ -29,16 +29,9 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Enable extends Command {
- /** @var IConfig */
- protected $config;
+ protected IConfig $config;
+ protected IManager $encryptionManager;
- /** @var IManager */
- protected $encryptionManager;
-
- /**
- * @param IConfig $config
- * @param IManager $encryptionManager
- */
public function __construct(IConfig $config, IManager $encryptionManager) {
parent::__construct();
diff --git a/core/Command/Encryption/EncryptAll.php b/core/Command/Encryption/EncryptAll.php
index 54e33221f4a..11e33ae9e2e 100644
--- a/core/Command/Encryption/EncryptAll.php
+++ b/core/Command/Encryption/EncryptAll.php
@@ -36,31 +36,13 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class EncryptAll extends Command {
+ protected IManager $encryptionManager;
+ protected IAppManager $appManager;
+ protected IConfig $config;
+ protected QuestionHelper $questionHelper;
+ protected bool $wasTrashbinEnabled = false;
+ protected bool $wasMaintenanceModeEnabled;
- /** @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,
@@ -77,8 +59,8 @@ class EncryptAll extends Command {
/**
* Set maintenance mode and disable the trashbin app
*/
- protected function forceMaintenanceAndTrashbin() {
- $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin');
+ protected function forceMaintenanceAndTrashbin(): void {
+ $this->wasTrashbinEnabled = (bool)$this->appManager->isEnabledForUser('files_trashbin');
$this->wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance');
$this->config->setSystemValue('maintenance', true);
$this->appManager->disableApp('files_trashbin');
@@ -87,7 +69,7 @@ class EncryptAll 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');
@@ -138,10 +120,9 @@ class EncryptAll extends Command {
}
$this->resetMaintenanceAndTrashbin();
- } else {
- $output->writeln('aborted');
- return 1;
+ return 0;
}
- return 0;
+ $output->writeln('aborted');
+ return 1;
}
}
diff --git a/core/Command/Encryption/ListModules.php b/core/Command/Encryption/ListModules.php
index 9105dff3f6d..88ad9875073 100644
--- a/core/Command/Encryption/ListModules.php
+++ b/core/Command/Encryption/ListModules.php
@@ -30,16 +30,9 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ListModules extends Base {
- /** @var IManager */
- protected $encryptionManager;
+ protected IManager $encryptionManager;
+ protected IConfig $config;
- /** @var IConfig */
- protected $config;
-
- /**
- * @param IManager $encryptionManager
- * @param IConfig $config
- */
public function __construct(
IManager $encryptionManager,
IConfig $config
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);
}
}
}
diff --git a/core/Command/Encryption/SetDefaultModule.php b/core/Command/Encryption/SetDefaultModule.php
index 0b8b4ce5891..b50e004867f 100644
--- a/core/Command/Encryption/SetDefaultModule.php
+++ b/core/Command/Encryption/SetDefaultModule.php
@@ -31,16 +31,9 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SetDefaultModule extends Command {
- /** @var IManager */
- protected $encryptionManager;
+ protected IManager $encryptionManager;
+ protected IConfig $config;
- /** @var IConfig */
- protected $config;
-
- /**
- * @param IManager $encryptionManager
- * @param IConfig $config
- */
public function __construct(
IManager $encryptionManager,
IConfig $config
diff --git a/core/Command/Encryption/ShowKeyStorageRoot.php b/core/Command/Encryption/ShowKeyStorageRoot.php
index 1ac882645d5..1c4f2b4cb4a 100644
--- a/core/Command/Encryption/ShowKeyStorageRoot.php
+++ b/core/Command/Encryption/ShowKeyStorageRoot.php
@@ -29,13 +29,8 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ShowKeyStorageRoot extends Command {
+ protected Util $util;
- /** @var Util */
- protected $util;
-
- /**
- * @param Util $util
- */
public function __construct(Util $util) {
parent::__construct();
$this->util = $util;
diff --git a/core/Command/Encryption/Status.php b/core/Command/Encryption/Status.php
index 0db34c77f61..34ebabe1b73 100644
--- a/core/Command/Encryption/Status.php
+++ b/core/Command/Encryption/Status.php
@@ -27,12 +27,8 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Status extends Base {
- /** @var IManager */
- protected $encryptionManager;
+ protected IManager $encryptionManager;
- /**
- * @param IManager $encryptionManager
- */
public function __construct(IManager $encryptionManager) {
parent::__construct();
$this->encryptionManager = $encryptionManager;