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.

EnableMasterKey.php 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  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, version 3,
  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 EnableMasterKey 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:enable-master-key')
  55. ->setDescription('Enable the master key. Only available for fresh installations with no existing encrypted data! There is also no way to disable it again.');
  56. }
  57. protected function execute(InputInterface $input, OutputInterface $output): int {
  58. $isAlreadyEnabled = $this->util->isMasterKeyEnabled();
  59. if ($isAlreadyEnabled) {
  60. $output->writeln('Master key already enabled');
  61. } else {
  62. $question = new ConfirmationQuestion(
  63. 'Warning: Only available for fresh installations with no existing encrypted data! '
  64. . 'There is also no way to disable it again. Do you want to continue? (y/n) ', false);
  65. if ($this->questionHelper->ask($input, $output, $question)) {
  66. $this->config->setAppValue('encryption', 'useMasterKey', '1');
  67. $output->writeln('Master key successfully enabled.');
  68. } else {
  69. $output->writeln('aborted.');
  70. return 1;
  71. }
  72. }
  73. return 0;
  74. }
  75. }