You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.9 KiB

  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Encryption\Command;
  25. use OCA\Encryption\Util;
  26. use OCP\IConfig;
  27. use Symfony\Component\Console\Command\Command;
  28. use Symfony\Component\Console\Helper\QuestionHelper;
  29. use Symfony\Component\Console\Input\InputInterface;
  30. use Symfony\Component\Console\Output\OutputInterface;
  31. use Symfony\Component\Console\Question\ConfirmationQuestion;
  32. class DisableMasterKey extends Command {
  33. /** @var Util */
  34. protected $util;
  35. /** @var IConfig */
  36. protected $config;
  37. /** @var QuestionHelper */
  38. protected $questionHelper;
  39. /**
  40. * @param Util $util
  41. * @param IConfig $config
  42. * @param QuestionHelper $questionHelper
  43. */
  44. public function __construct(Util $util,
  45. IConfig $config,
  46. QuestionHelper $questionHelper) {
  47. $this->util = $util;
  48. $this->config = $config;
  49. $this->questionHelper = $questionHelper;
  50. parent::__construct();
  51. }
  52. protected function configure() {
  53. $this
  54. ->setName('encryption:disable-master-key')
  55. ->setDescription('Disable the master key and use per-user keys instead. Only available for fresh installations with no existing encrypted data! There is no way to enable it again.');
  56. }
  57. protected function execute(InputInterface $input, OutputInterface $output): int {
  58. $isMasterKeyEnabled = $this->util->isMasterKeyEnabled();
  59. if (!$isMasterKeyEnabled) {
  60. $output->writeln('Master key already disabled');
  61. } else {
  62. $question = new ConfirmationQuestion(
  63. 'Warning: Only perform this operation for a fresh installations with no existing encrypted data! '
  64. . 'There is no way to enable the master key again. '
  65. . 'We strongly recommend to keep the master key, it provides significant performance improvements '
  66. . 'and is easier to handle for both, users and administrators. '
  67. . 'Do you really want to switch to per-user keys? (y/n) ', false);
  68. if ($this->questionHelper->ask($input, $output, $question)) {
  69. $this->config->setAppValue('encryption', 'useMasterKey', '0');
  70. $output->writeln('Master key successfully disabled.');
  71. } else {
  72. $output->writeln('aborted.');
  73. return 1;
  74. }
  75. }
  76. return 0;
  77. }
  78. }