diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-01-09 21:10:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-09 21:10:11 +0100 |
commit | 307d45e3bdf32c50e46a47b746282ecfbb43b384 (patch) | |
tree | 4ee9ab5b6a40472f20c2fa13461ed0c06ff79643 /lib/private | |
parent | 9a5b9d8555c89293073af17f8a2c1ebf3c64de8d (diff) | |
parent | 817e974c5ffc2de4732316114fdcb4f30ac292de (diff) | |
download | nextcloud-server-307d45e3bdf32c50e46a47b746282ecfbb43b384.tar.gz nextcloud-server-307d45e3bdf32c50e46a47b746282ecfbb43b384.zip |
Merge pull request #2987 from nextcloud/no-empty-bundle
dont write a certificate bundle if the shipped ca bundle is empty
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Security/CertificateManager.php | 20 | ||||
-rw-r--r-- | lib/private/Server.php | 4 |
2 files changed, 19 insertions, 5 deletions
diff --git a/lib/private/Security/CertificateManager.php b/lib/private/Security/CertificateManager.php index f7bf0df58c5..461ef9457a7 100644 --- a/lib/private/Security/CertificateManager.php +++ b/lib/private/Security/CertificateManager.php @@ -30,6 +30,7 @@ namespace OC\Security; use OC\Files\Filesystem; use OCP\ICertificateManager; use OCP\IConfig; +use OCP\ILogger; /** * Manage trusted certificates for users @@ -51,14 +52,21 @@ class CertificateManager implements ICertificateManager { protected $config; /** + * @var ILogger + */ + protected $logger; + + /** * @param string $uid * @param \OC\Files\View $view relative to data/ * @param IConfig $config + * @param ILogger $logger */ - public function __construct($uid, \OC\Files\View $view, IConfig $config) { + public function __construct($uid, \OC\Files\View $view, IConfig $config, ILogger $logger) { $this->uid = $uid; $this->view = $view; $this->config = $config; + $this->logger = $logger; } /** @@ -104,6 +112,13 @@ class CertificateManager implements ICertificateManager { $this->view->mkdir($path); } + $defaultCertificates = file_get_contents(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); + if (strlen($defaultCertificates) < 1024) { // sanity check to verify that we have some content for our bundle + // log as exception so we have a stacktrace + $this->logger->logException(new \Exception('Shipped ca-bundle is empty, refusing to create certificate bundle')); + return; + } + $fhCerts = $this->view->fopen($path . '/rootcerts.crt', 'w'); // Write user certificates @@ -117,7 +132,6 @@ class CertificateManager implements ICertificateManager { } // Append the default certificates - $defaultCertificates = file_get_contents(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); fwrite($fhCerts, $defaultCertificates); // Append the system certificate bundle @@ -203,7 +217,7 @@ class CertificateManager implements ICertificateManager { } if ($this->needsRebundling($uid)) { if (is_null($uid)) { - $manager = new CertificateManager(null, $this->view, $this->config); + $manager = new CertificateManager(null, $this->view, $this->config, $this->logger); $manager->createCertificateBundle(); } else { $this->createCertificateBundle(); diff --git a/lib/private/Server.php b/lib/private/Server.php index cc295dccd17..147fa89582a 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -482,7 +482,7 @@ class Server extends ServerContainer implements IServerContainer { $uid = $user ? $user : null; return new ClientService( $c->getConfig(), - new \OC\Security\CertificateManager($uid, new View(), $c->getConfig()) + new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) ); }); $this->registerService('EventLogger', function (Server $c) { @@ -1220,7 +1220,7 @@ class Server extends ServerContainer implements IServerContainer { } $userId = $user->getUID(); } - return new CertificateManager($userId, new View(), $this->getConfig()); + return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); } /** |