use OC\Files\Filesystem;
use OCP\ICertificateManager;
use OCP\IConfig;
+use OCP\ILogger;
/**
* Manage trusted certificates for users
*/
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;
}
/**
$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
}
// Append the default certificates
- $defaultCertificates = file_get_contents(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
fwrite($fhCerts, $defaultCertificates);
// Append the system certificate bundle
}
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();
$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) {
}
$userId = $user->getUID();
}
- return new CertificateManager($userId, new View(), $this->getConfig());
+ return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
}
/**
namespace Test\Security;
+use OC\Files\Storage\Temporary;
use \OC\Security\CertificateManager;
use OCP\IConfig;
+use OCP\ILogger;
/**
* Class CertificateManagerTest
$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() {
/** @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();
[null, 10, 5, 8, false, true],
];
}
-
}