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.

ImportCertificate.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Command\Security;
  8. use OC\Core\Command\Base;
  9. use OCP\ICertificateManager;
  10. use Symfony\Component\Console\Input\InputArgument;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class ImportCertificate extends Base {
  14. public function __construct(
  15. protected ICertificateManager $certificateManager,
  16. ) {
  17. parent::__construct();
  18. }
  19. protected function configure() {
  20. $this
  21. ->setName('security:certificates:import')
  22. ->setDescription('import trusted certificate in PEM format')
  23. ->addArgument(
  24. 'path',
  25. InputArgument::REQUIRED,
  26. 'path to the PEM certificate to import'
  27. );
  28. }
  29. protected function execute(InputInterface $input, OutputInterface $output): int {
  30. $path = $input->getArgument('path');
  31. if (!file_exists($path)) {
  32. $output->writeln('<error>Certificate not found, please provide a path accessible by the web server user</error>');
  33. return 1;
  34. }
  35. $certData = file_get_contents($path);
  36. $name = basename($path);
  37. $this->certificateManager->addCertificate($certData, $name);
  38. return 0;
  39. }
  40. }