Skip to content

Commit c683862

Browse files
Merge pull request #52749 from nextcloud/feat/certificatemanager/default-bundle-path-option
feat(CertificateManager): Add option to specify the default certificates bundle path
2 parents 86560b3 + 0c3a872 commit c683862

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
@@ -2877,4 +2877,13 @@
28772877
* Defaults to ``true``
28782878
*/
28792879
'enable_lazy_objects' => true,
2880+
2881+
/**
2882+
* Change the default certificates bundle used for trusting certificates.
2883+
*
2884+
* 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.
2885+
*
2886+
* Defaults to `\OC::$SERVERROOT . '/resources/config/ca-bundle.crt'`.
2887+
*/
2888+
'default_certificates_bundle_path' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',
28802889
];

lib/private/Files/ObjectStore/S3ConnectionTrait.php

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

242242
protected function getCertificateBundlePath(): ?string {
243243
if ((int)($this->params['use_nextcloud_bundle'] ?? '0')) {
244+
/** @var ICertificateManager $certManager */
245+
$certManager = Server::get(ICertificateManager::class);
244246
// since we store the certificate bundles on the primary storage, we can't get the bundle while setting up the primary storage
245247
if (!isset($this->params['primary_storage'])) {
246-
/** @var ICertificateManager $certManager */
247-
$certManager = Server::get(ICertificateManager::class);
248248
return $certManager->getAbsoluteBundlePath();
249249
} else {
250-
return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
250+
return $certManager->getDefaultCertificatesBundlePath();
251251
}
252252
} else {
253253
return null;

lib/private/Http/Client/Client.php

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

111111
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 33.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
@@ -473,6 +473,10 @@ public function testSetDefaultOptionsWithNotInstalled(): void {
473473
$this->certificateManager
474474
->expects($this->never())
475475
->method('listCertificates');
476+
$this->certificateManager
477+
->expects($this->once())
478+
->method('getDefaultCertificatesBundlePath')
479+
->willReturn(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
476480

477481
$this->serverVersion->method('getVersionString')
478482
->willReturn('123.45.6');

tests/lib/Security/CertificateManagerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ protected function setUp(): void {
5252
$config = $this->createMock(IConfig::class);
5353
$config->expects($this->any())->method('getSystemValueBool')
5454
->with('installed', false)->willReturn(true);
55+
$config
56+
->expects($this->any())
57+
->method('getSystemValueString')
58+
->with('default_certificates_bundle_path', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt')
59+
->willReturn(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
5560

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

0 commit comments

Comments
 (0)