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.

UpdateCertificateStore.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Repair;
  24. use OC\Files\View;
  25. use OC\Server;
  26. use OCP\IConfig;
  27. use OCP\Migration\IOutput;
  28. use OCP\Migration\IRepairStep;
  29. /**
  30. * Class UpdateCertificateStore rewrites the user specific certificate store after
  31. * an update has been performed. This is done because a new root certificate file
  32. * might have been added.
  33. *
  34. * @package OC\Repair
  35. */
  36. class UpdateCertificateStore implements IRepairStep {
  37. /**
  38. * FIXME: The certificate manager does only allow specifying the user
  39. * within the constructor. This makes DI impossible.
  40. * @var Server
  41. */
  42. protected $server;
  43. /** @var IConfig */
  44. protected $config;
  45. /**
  46. * @param Server $server
  47. * @param IConfig $config
  48. */
  49. public function __construct(Server $server,
  50. IConfig $config) {
  51. $this->server = $server;
  52. $this->config = $config;
  53. }
  54. /** {@inheritDoc} */
  55. public function getName() {
  56. return 'Update user certificate stores with new root certificates';
  57. }
  58. /** {@inheritDoc} */
  59. public function run(IOutput $out) {
  60. $rootView = new View();
  61. $dataDirectory = $this->config->getSystemValue('datadirectory', null);
  62. if(is_null($dataDirectory)) {
  63. throw new \Exception('No data directory specified');
  64. }
  65. $pathToRootCerts = '/files_external/rootcerts.crt';
  66. foreach($rootView->getDirectoryContent('', 'httpd/unix-directory') as $fileInfo) {
  67. $uid = trim($fileInfo->getPath(), '/');
  68. if($rootView->file_exists($uid . $pathToRootCerts)) {
  69. // Delete the existing root certificate
  70. $rootView->unlink($uid . $pathToRootCerts);
  71. /**
  72. * FIXME: The certificate manager does only allow specifying the user
  73. * within the constructor. This makes DI impossible.
  74. */
  75. // Regenerate the certificates
  76. $certificateManager = $this->server->getCertificateManager($uid);
  77. $certificateManager->createCertificateBundle();
  78. }
  79. }
  80. }
  81. }