mirror of
https://github.com/nextcloud/server.git
synced 2026-04-26 08:38:11 -04:00
Merge pull request #38090 from nextcloud/backport/35092/stable25
[stable25] Check return value and improve error handling on certificate manager
This commit is contained in:
commit
4f4231275c
1 changed files with 12 additions and 2 deletions
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue