summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2023-05-17 19:04:10 +0200
committerGitHub <noreply@github.com>2023-05-17 19:04:10 +0200
commit7c6b47dd27bbd5e477034f94b5111a687bbc2bbd (patch)
treefa80a851f8fd73d47769a23b28a5b242b5abb26f
parent4bd2f33cfe0027656cd90d4664562bc49f9d19b9 (diff)
parent22f02a46d1b16793b9f7498d939221284afa83df (diff)
downloadnextcloud-server-7c6b47dd27bbd5e477034f94b5111a687bbc2bbd.tar.gz
nextcloud-server-7c6b47dd27bbd5e477034f94b5111a687bbc2bbd.zip
Merge pull request #38091 from nextcloud/backport/35092/stable26
[stable26] Check return value and improve error handling on certificate manager
-rw-r--r--lib/private/Security/CertificateManager.php14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/private/Security/CertificateManager.php b/lib/private/Security/CertificateManager.php
index fa26c19ceae..6231534205a 100644
--- a/lib/private/Security/CertificateManager.php
+++ b/lib/private/Security/CertificateManager.php
@@ -147,6 +147,10 @@ class CertificateManager implements ICertificateManager {
$tmpPath = $certPath . '.tmp' . $this->random->generate(10, ISecureRandom::CHAR_DIGITS);
$fhCerts = $this->view->fopen($tmpPath, 'w');
+ if (!is_resource($fhCerts)) {
+ throw new \RuntimeException('Unable to open file handler to create certificate bundle "' . $tmpPath . '".');
+ }
+
// Write user certificates
foreach ($certs as $cert) {
$file = $path . '/uploads/' . $cert->getName();
@@ -238,7 +242,7 @@ class CertificateManager implements ICertificateManager {
*/
public function getAbsoluteBundlePath(): string {
try {
- if (!$this->bundlePath) {
+ if ($this->bundlePath === null) {
if (!$this->hasCertificates()) {
$this->bundlePath = \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
}
@@ -247,10 +251,16 @@ class CertificateManager implements ICertificateManager {
$this->createCertificateBundle();
}
- $this->bundlePath = $this->view->getLocalFile($this->getCertificateBundle());
+ $certificateBundle = $this->getCertificateBundle();
+ $this->bundlePath = $this->view->getLocalFile($certificateBundle) ?: null;
+
+ if ($this->bundlePath === null) {
+ throw new \RuntimeException('Unable to get certificate bundle "' . $certificateBundle . '".');
+ }
}
return $this->bundlePath;
} catch (\Exception $e) {
+ $this->logger->error('Failed to get absolute bundle path. Fallback to default ca-bundle.crt', ['exception' => $e]);
return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
}
}