Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-01-10 11:57:03 +0300
committerGitHub <noreply@github.com>2017-01-10 11:57:03 +0300
commit97788f15330c06e067d9cd9c390e17a24191e0ce (patch)
tree85b9a26b79cca3a2b87a2d72d549a698b9dd0386
parentca81eb01ac4b826e41768aeece077e730879c665 (diff)
parentdaa4f393cbaa70fe5639eb4be10c0df70fdaa253 (diff)
Merge pull request #2994 from nextcloud/stable11_2987
dont write a certificate bundle if the shipped ca bundle is empty
-rw-r--r--lib/private/Security/CertificateManager.php20
-rw-r--r--lib/private/Server.php4
-rw-r--r--tests/lib/Security/CertificateManagerTest.php7
3 files changed, 23 insertions, 8 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 2c0aac9b43c..1d9a9f4d721 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -485,7 +485,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) {
@@ -1233,7 +1233,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());
}
/**
diff --git a/tests/lib/Security/CertificateManagerTest.php b/tests/lib/Security/CertificateManagerTest.php
index 92a063d47c7..408e65c6766 100644
--- a/tests/lib/Security/CertificateManagerTest.php
+++ b/tests/lib/Security/CertificateManagerTest.php
@@ -8,8 +8,10 @@
namespace Test\Security;
+use OC\Files\Storage\Temporary;
use \OC\Security\CertificateManager;
use OCP\IConfig;
+use OCP\ILogger;
/**
* Class CertificateManagerTest
@@ -43,7 +45,7 @@ class CertificateManagerTest extends \Test\TestCase {
$config->expects($this->any())->method('getSystemValue')
->with('installed', false)->willReturn(true);
- $this->certificateManager = new CertificateManager($this->username, new \OC\Files\View(), $config);
+ $this->certificateManager = new CertificateManager($this->username, new \OC\Files\View(), $config, $this->createMock(ILogger::class));
}
protected function tearDown() {
@@ -143,7 +145,7 @@ class CertificateManagerTest extends \Test\TestCase {
/** @var CertificateManager | \PHPUnit_Framework_MockObject_MockObject $certificateManager */
$certificateManager = $this->getMockBuilder('OC\Security\CertificateManager')
- ->setConstructorArgs([$uid, $view, $config])
+ ->setConstructorArgs([$uid, $view, $config, $this->createMock(ILogger::class)])
->setMethods(['getFilemtimeOfCaBundle', 'getCertificateBundle'])
->getMock();
@@ -210,5 +212,4 @@ class CertificateManagerTest extends \Test\TestCase {
[null, 10, 5, 8, false, true],
];
}
-
}