UpdateCertificateStore.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. }