Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Handler/CertificateEngine/OpenSslHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ public function generateCertificate(): string {
'private_key_type' => OPENSSL_KEYTYPE_RSA,
]);

$csr = openssl_csr_new($this->getCsrNames(), $privateKey);
$csr = @openssl_csr_new($this->getCsrNames(), $privateKey);
if ($csr === false) {
$message = openssl_error_string();
throw new LibresignException('OpenSSL error: ' . $message);
}

$x509 = openssl_csr_sign($csr, $rootCertificate, $rootPrivateKey, $this->expirity(), [
'config' => $this->getFilenameToLeafCert(),
Expand Down
30 changes: 30 additions & 0 deletions tests/php/Unit/Handler/CertificateEngine/OpenSslHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use OCA\Libresign\Exception\EmptyCertificateException;
use OCA\Libresign\Exception\InvalidPasswordException;
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Handler\CertificateEngine\OpenSslHandler;
use OCA\Libresign\Service\CertificatePolicyService;
use OCP\Files\AppData\IAppDataFactory;
Expand Down Expand Up @@ -72,6 +73,35 @@ public function testInvalidPassword(): void {
$signerInstance->readCertificate($certificateContent, 'invalid password');
}

public function testMaxLengthOfDistinguishedNamesWithSuccess(): void {
// Create root cert
$rootInstance = $this->getInstance();
$rootInstance->generateRootCert('', []);

// Create signer cert
$signerInstance = $this->getInstance();
$longName = str_repeat('a', 64);
$signerInstance->setCommonName($longName);
$signerInstance->setPassword('123456');
$certificateContent = $signerInstance->generateCertificate();
$parsed = $signerInstance->readCertificate($certificateContent, '123456');
$this->assertEquals($longName, $parsed['subject']['CN']);
}

public function testBiggerThanMaxLengthOfDistinguishedNamesWithError(): void {
// Create root cert
$rootInstance = $this->getInstance();
$rootInstance->generateRootCert('', []);

// Create signer cert
$signerInstance = $this->getInstance();
$longName = str_repeat('a', 65);
$signerInstance->setCommonName($longName);
$signerInstance->setPassword('123456');
$this->expectException(LibresignException::class);
$signerInstance->generateCertificate();
}

/**
* @dataProvider dataReadCertificate
*/
Expand Down
Loading