Skip to content

Commit cacc724

Browse files
committed
feat(CertificateManager): Add option to specify the default certificates bundle path
Signed-off-by: provokateurin <[email protected]>
1 parent 195dbad commit cacc724

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

config/config.sample.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,4 +2743,13 @@
27432743
* Defaults to true.
27442744
*/
27452745
'files.trash.delete' => true,
2746+
2747+
/**
2748+
* Change the default certificates bundle used for trusting certificates.
2749+
*
2750+
* Nextcloud ships its own up-to-date certificates bundle, but in certain cases admins may wish to specify a different bundle, for example the one shipped by their distro.
2751+
*
2752+
* Defaults to `\OC::$SERVERROOT . '/resources/config/ca-bundle.crt'`.
2753+
*/
2754+
'default_certificates_bundle_path' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',
27462755
];

lib/private/Files/ObjectStore/S3ConnectionTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ protected function paramCredentialProvider(): callable {
205205

206206
protected function getCertificateBundlePath(): ?string {
207207
if ((int)($this->params['use_nextcloud_bundle'] ?? '0')) {
208+
/** @var ICertificateManager $certManager */
209+
$certManager = Server::get(ICertificateManager::class);
208210
// since we store the certificate bundles on the primary storage, we can't get the bundle while setting up the primary storage
209211
if (!isset($this->params['primary_storage'])) {
210-
/** @var ICertificateManager $certManager */
211-
$certManager = Server::get(ICertificateManager::class);
212212
return $certManager->getAbsoluteBundlePath();
213213
} else {
214-
return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
214+
return $certManager->getDefaultCertificatesBundlePath();
215215
}
216216
} else {
217217
return null;

lib/private/Http/Client/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private function getCertBundle(): string {
102102
// $this->certificateManager->getAbsoluteBundlePath() tries to instantiate
103103
// a view
104104
if (!$this->config->getSystemValueBool('installed', false)) {
105-
return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
105+
return $this->certificateManager->getDefaultCertificatesBundlePath();
106106
}
107107

108108
return $this->certificateManager->getAbsoluteBundlePath();

lib/private/Security/CertificateManager.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function createCertificateBundle(): void {
100100
$this->view->mkdir($path);
101101
}
102102

103-
$defaultCertificates = file_get_contents(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
103+
$defaultCertificates = file_get_contents($this->getDefaultCertificatesBundlePath());
104104
if (strlen($defaultCertificates) < 1024) { // sanity check to verify that we have some content for our bundle
105105
// log as exception so we have a stacktrace
106106
$e = new \Exception('Shipped ca-bundle is empty, refusing to create certificate bundle');
@@ -204,7 +204,7 @@ public function getAbsoluteBundlePath(): string {
204204
try {
205205
if ($this->bundlePath === null) {
206206
if (!$this->hasCertificates()) {
207-
$this->bundlePath = \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
207+
$this->bundlePath = $this->getDefaultCertificatesBundlePath();
208208
} else {
209209
if ($this->needsRebundling()) {
210210
$this->createCertificateBundle();
@@ -221,7 +221,7 @@ public function getAbsoluteBundlePath(): string {
221221
return $this->bundlePath;
222222
} catch (\Exception $e) {
223223
$this->logger->error('Failed to get absolute bundle path. Fallback to default ca-bundle.crt', ['exception' => $e]);
224-
return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
224+
return $this->getDefaultCertificatesBundlePath();
225225
}
226226
}
227227

@@ -246,6 +246,10 @@ private function needsRebundling(): bool {
246246
* get mtime of ca-bundle shipped by Nextcloud
247247
*/
248248
protected function getFilemtimeOfCaBundle(): int {
249-
return filemtime(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
249+
return filemtime($this->getDefaultCertificatesBundlePath());
250+
}
251+
252+
public function getDefaultCertificatesBundlePath(): string {
253+
return $this->config->getSystemValueString('default_certificates_bundle_path', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
250254
}
251255
}

lib/public/ICertificateManager.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,11 @@ public function getCertificateBundle(): string;
5252
* @since 9.0.0
5353
*/
5454
public function getAbsoluteBundlePath(): string;
55+
56+
/**
57+
* Get the path of the default certificates bundle.
58+
*
59+
* @since 32.0.0
60+
*/
61+
public function getDefaultCertificatesBundlePath(): string;
5562
}

tests/lib/Http/Client/ClientTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ public function testSetDefaultOptionsWithNotInstalled(): void {
465465
$this->certificateManager
466466
->expects($this->never())
467467
->method('listCertificates');
468+
$this->certificateManager
469+
->expects($this->once())
470+
->method('getDefaultCertificatesBundlePath')
471+
->willReturn(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
468472

469473
$this->assertEquals([
470474
'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',

tests/lib/Security/CertificateManagerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ protected function setUp(): void {
4848
$config = $this->createMock(IConfig::class);
4949
$config->expects($this->any())->method('getSystemValueBool')
5050
->with('installed', false)->willReturn(true);
51+
$config
52+
->expects($this->any())
53+
->method('getSystemValueString')
54+
->with('default_certificates_bundle_path', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt')
55+
->willReturn(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
5156

5257
$this->random = $this->createMock(ISecureRandom::class);
5358
$this->random->method('generate')

0 commit comments

Comments
 (0)