updatecertificatestore.php 2.5 KB

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