-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(certificate manager): migrate certificate bundles from files_exte…
…rnal to data CertificateManager doesn't work propertly if the files_external app is disabled, so let's store directly in /data/certificate_manager the bundled certificates. This always has to be done on local disk as curl currently requires a path to the cert bundle. When we require PHP 8.1 we will be able to simply store the certificate bundle in database/memory/cache and pass it through the CURLOPT_SSLCERT_BLOB option. Signed-off-by: Thomas Citharel <[email protected]>
- Loading branch information
Showing
6 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2024 Thomas Citharel <[email protected]> | ||
* | ||
* @author Thomas Citharel <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
namespace OC\Repair\NC29; | ||
|
||
use OC\Files\View; | ||
use OCP\IConfig; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\IRepairStep; | ||
|
||
|
||
class MoveCertificateBundles implements IRepairStep { | ||
|
||
const OLD_PATH = '/files_external'; | ||
const ROOT_CERTS_FILENAME = '/rootcerts.crt'; | ||
const CERTS_UPLOAD_PATH = '/uploads'; | ||
|
||
protected string $newRootPath; | ||
|
||
public function __construct(protected View $view, protected IConfig $config) { | ||
$this->newRootPath = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/data/certificate_manager'; | ||
} | ||
|
||
public function getName(): string { | ||
return 'Move the certificate bundles from data/files_external/ to data/certificate_manager/'; | ||
} | ||
|
||
|
||
public function run(IOutput $output): void { | ||
if (!$this->shouldRun()) { | ||
return; | ||
} | ||
|
||
$oldCertificateBundlePath = self::OLD_PATH . self::ROOT_CERTS_FILENAME; | ||
$oldUploadsPath = self::OLD_PATH . self::CERTS_UPLOAD_PATH; | ||
|
||
$this->view->copy($oldUploadsPath, $this->newRootPath . self::CERTS_UPLOAD_PATH, true); | ||
$this->view->copy($oldCertificateBundlePath, $this->newRootPath . self::ROOT_CERTS_FILENAME, true); | ||
|
||
$this->view->unlink($oldCertificateBundlePath); | ||
$this->view->unlink($oldUploadsPath); | ||
} | ||
|
||
protected function shouldRun(): bool { | ||
return $this->view->file_exists($this->newRootPath . self::ROOT_CERTS_FILENAME); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2024 Thomas Citharel <[email protected]> | ||
* | ||
* @author Thomas Citharel <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace Test\Repair\NC29; | ||
|
||
use OC\Files\View; | ||
use OC\Repair\NC29\MoveCertificateBundles; | ||
use OCP\IConfig; | ||
use OCP\Migration\IOutput; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use Test\TestCase; | ||
|
||
/** | ||
* Class FixMountStoragesTest | ||
* | ||
* @package Test\Repair\NC11 | ||
* @group DB | ||
*/ | ||
class MoveCertificateBundlesTest extends TestCase { | ||
private View|MockObject $view; | ||
private IConfig|MockObject $config; | ||
private IOutput $output; | ||
|
||
private MoveCertificateBundles $repair; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->output = $this->createMock(IOutput::class); | ||
|
||
$this->view = $this->createMock(View::class); | ||
$this->config = $this->createMock(IConfig::class); | ||
$this->config->expects($this->once())->method('getSystemValue')->with('datadirectory', \OC::$SERVERROOT . '/data-autotest')->willReturn(\OC::$SERVERROOT . '/data-autotest'); | ||
|
||
$this->repair = new MoveCertificateBundles( | ||
$this->view, | ||
$this->config | ||
); | ||
} | ||
|
||
public function testGetName() { | ||
$this->assertSame('Move the certificate bundles from data/files_external/ to data/certificate_manager/', $this->repair->getName()); | ||
} | ||
|
||
public function testSkipRepairStep() { | ||
$this->view->expects($this->once())->method('file_exists')->with('/data-autotest/certificate_manager/rootcerts.crt')->willReturn(true); | ||
$this->view->expects($this->never())->method('copy'); | ||
$this->repair->run($this->output); | ||
} | ||
} |