1
0

DisableMasterKey.php 3.0 KB

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