Skip to content

Commit 4f42312

Browse files
authored
Merge pull request #38090 from nextcloud/backport/35092/stable25
[stable25] Check return value and improve error handling on certificate manager
2 parents bf71686 + 8f7c7b3 commit 4f42312

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/private/Security/CertificateManager.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ public function createCertificateBundle(): void {
147147
$tmpPath = $certPath . '.tmp' . $this->random->generate(10, ISecureRandom::CHAR_DIGITS);
148148
$fhCerts = $this->view->fopen($tmpPath, 'w');
149149

150+
if (!is_resource($fhCerts)) {
151+
throw new \RuntimeException('Unable to open file handler to create certificate bundle "' . $tmpPath . '".');
152+
}
153+
150154
// Write user certificates
151155
foreach ($certs as $cert) {
152156
$file = $path . '/uploads/' . $cert->getName();
@@ -238,7 +242,7 @@ public function getCertificateBundle(): string {
238242
*/
239243
public function getAbsoluteBundlePath(): string {
240244
try {
241-
if (!$this->bundlePath) {
245+
if ($this->bundlePath === null) {
242246
if (!$this->hasCertificates()) {
243247
$this->bundlePath = \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
244248
}
@@ -247,10 +251,16 @@ public function getAbsoluteBundlePath(): string {
247251
$this->createCertificateBundle();
248252
}
249253

250-
$this->bundlePath = $this->view->getLocalFile($this->getCertificateBundle());
254+
$certificateBundle = $this->getCertificateBundle();
255+
$this->bundlePath = $this->view->getLocalFile($certificateBundle) ?: null;
256+
257+
if ($this->bundlePath === null) {
258+
throw new \RuntimeException('Unable to get certificate bundle "' . $certificateBundle . '".');
259+
}
251260
}
252261
return $this->bundlePath;
253262
} catch (\Exception $e) {
263+
$this->logger->error('Failed to get absolute bundle path. Fallback to default ca-bundle.crt', ['exception' => $e]);
254264
return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
255265
}
256266
}

0 commit comments

Comments
 (0)