Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable25] Check return value and improve error handling on certificate manager #38090

Merged
merged 3 commits into from
May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/private/Security/CertificateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public function createCertificateBundle(): void {
$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();
Expand Down Expand Up @@ -238,7 +242,7 @@ public function getCertificateBundle(): string {
*/
public function getAbsoluteBundlePath(): string {
try {
if (!$this->bundlePath) {
if ($this->bundlePath === null) {
if (!$this->hasCertificates()) {
$this->bundlePath = \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
}
Expand All @@ -247,10 +251,16 @@ public function getAbsoluteBundlePath(): string {
$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';
}
}
Expand Down