Skip to content

Commit 4f594db

Browse files
committed
cache the path of the certificate bundle
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent bf48c0b commit 4f594db

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

lib/private/Security/CertificateManager.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class CertificateManager implements ICertificateManager {
6161
/** @var ISecureRandom */
6262
protected $random;
6363

64+
private ?string $bundlePath = null;
65+
6466
/**
6567
* @param \OC\Files\View $view relative to data/
6668
* @param IConfig $config
@@ -190,6 +192,7 @@ public function addCertificate(string $certificate, string $name): ICertificate
190192
if (!Filesystem::isValidPath($name) or Filesystem::isFileBlacklisted($name)) {
191193
throw new \Exception('Filename is not valid');
192194
}
195+
$this->bundlePath = null;
193196

194197
$dir = $this->getPathToCertificates() . 'uploads/';
195198
if (!$this->view->file_exists($dir)) {
@@ -217,6 +220,8 @@ public function removeCertificate(string $name): bool {
217220
if (!Filesystem::isValidPath($name)) {
218221
return false;
219222
}
223+
$this->bundlePath = null;
224+
220225
$path = $this->getPathToCertificates() . 'uploads/';
221226
if ($this->view->file_exists($path . $name)) {
222227
$this->view->unlink($path . $name);
@@ -241,15 +246,18 @@ public function getCertificateBundle(): string {
241246
*/
242247
public function getAbsoluteBundlePath(): string {
243248
try {
244-
if (!$this->hasCertificates()) {
245-
return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
246-
}
249+
if (!$this->bundlePath) {
250+
if (!$this->hasCertificates()) {
251+
$this->bundlePath = \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
252+
}
247253

248-
if ($this->needsRebundling()) {
249-
$this->createCertificateBundle();
250-
}
254+
if ($this->needsRebundling()) {
255+
$this->createCertificateBundle();
256+
}
251257

252-
return $this->view->getLocalFile($this->getCertificateBundle());
258+
$this->bundlePath = $this->view->getLocalFile($this->getCertificateBundle());
259+
}
260+
return $this->bundlePath;
253261
} catch (\Exception $e) {
254262
return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
255263
}

0 commit comments

Comments
 (0)