summaryrefslogtreecommitdiffstats
path: root/lib/private/Security/CertificateManager.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-05-19 22:51:26 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2017-07-12 19:24:20 +0200
commit04f209069859004702ca5138cda3dbcafe4d8c0f (patch)
tree30a901c9b02971e28ce3ef98b47c65bcac3ebe21 /lib/private/Security/CertificateManager.php
parent86a496d94ae438ae5de033fd6d9c5bee19ed4fcf (diff)
downloadnextcloud-server-04f209069859004702ca5138cda3dbcafe4d8c0f.tar.gz
nextcloud-server-04f209069859004702ca5138cda3dbcafe4d8c0f.zip
Write cert bundle to tmp file first
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Security/CertificateManager.php')
-rw-r--r--lib/private/Security/CertificateManager.php19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/private/Security/CertificateManager.php b/lib/private/Security/CertificateManager.php
index 4419b56012f..58c44b88ba6 100644
--- a/lib/private/Security/CertificateManager.php
+++ b/lib/private/Security/CertificateManager.php
@@ -31,6 +31,7 @@ use OC\Files\Filesystem;
use OCP\ICertificateManager;
use OCP\IConfig;
use OCP\ILogger;
+use OCP\Security\ISecureRandom;
/**
* Manage trusted certificates for users
@@ -56,17 +57,26 @@ class CertificateManager implements ICertificateManager {
*/
protected $logger;
+ /** @var ISecureRandom */
+ protected $random;
+
/**
* @param string $uid
* @param \OC\Files\View $view relative to data/
* @param IConfig $config
* @param ILogger $logger
+ * @param ISecureRandom $random
*/
- public function __construct($uid, \OC\Files\View $view, IConfig $config, ILogger $logger) {
+ public function __construct($uid,
+ \OC\Files\View $view,
+ IConfig $config,
+ ILogger $logger,
+ ISecureRandom $random) {
$this->uid = $uid;
$this->view = $view;
$this->config = $config;
$this->logger = $logger;
+ $this->random = $random;
}
/**
@@ -120,7 +130,8 @@ class CertificateManager implements ICertificateManager {
}
$certPath = $path . 'rootcerts.crt';
- $fhCerts = $this->view->fopen($certPath, 'w');
+ $tmpPath = $certPath . '.tmp' . $this->random->generate(10, ISecureRandom::CHAR_DIGITS);
+ $fhCerts = $this->view->fopen($tmpPath, 'w');
// Write user certificates
foreach ($certs as $cert) {
@@ -143,6 +154,8 @@ class CertificateManager implements ICertificateManager {
}
fclose($fhCerts);
+
+ $this->view->rename($tmpPath, $certPath);
}
/**
@@ -218,7 +231,7 @@ class CertificateManager implements ICertificateManager {
}
if ($this->needsRebundling($uid)) {
if (is_null($uid)) {
- $manager = new CertificateManager(null, $this->view, $this->config, $this->logger);
+ $manager = new CertificateManager(null, $this->view, $this->config, $this->logger, $this->random);
$manager->createCertificateBundle();
} else {
$this->createCertificateBundle();