File tree Expand file tree Collapse file tree
lib/Handler/CertificateEngine Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515use OCA \Libresign \AppInfo \Application ;
1616use OCA \Libresign \Db \CrlMapper ;
1717use OCA \Libresign \Enum \CertificateType ;
18+ use OCA \Libresign \Exception \EmptyCertificateException ;
1819use OCA \Libresign \Exception \LibresignException ;
1920use OCA \Libresign \Handler \CfsslServerHandler ;
2021use OCA \Libresign \Helper \ConfigureCheckHelper ;
@@ -77,6 +78,10 @@ public function generateRootCert(
7778 string $ commonName ,
7879 array $ names = [],
7980 ): void {
81+ if (empty ($ commonName )) {
82+ throw new EmptyCertificateException ('Common Name (CN) cannot be empty for root certificate ' );
83+ }
84+
8085 $ this ->cfsslServerHandler ->createConfigServer (
8186 $ commonName ,
8287 $ names ,
Original file line number Diff line number Diff line change 1010
1111use OCA \Libresign \Db \CrlMapper ;
1212use OCA \Libresign \Enum \CertificateType ;
13+ use OCA \Libresign \Exception \EmptyCertificateException ;
1314use OCA \Libresign \Exception \LibresignException ;
1415use OCA \Libresign \Service \CaIdentifierService ;
1516use OCA \Libresign \Service \CertificatePolicyService ;
@@ -60,6 +61,10 @@ public function generateRootCert(
6061 string $ commonName ,
6162 array $ names = [],
6263 ): void {
64+ if (empty ($ commonName )) {
65+ throw new EmptyCertificateException ('Common Name (CN) cannot be empty for root certificate ' );
66+ }
67+
6368 $ privateKey = openssl_pkey_new ([
6469 'private_key_bits ' => 2048 ,
6570 'private_key_type ' => OPENSSL_KEYTYPE_RSA ,
Original file line number Diff line number Diff line change @@ -77,6 +77,13 @@ public function testEmptyCertificate(): void {
7777 $ signerInstance ->readCertificate ('' , '' );
7878 }
7979
80+ public function testEmptyCommonNameThrowsException (): void {
81+ $ rootInstance = $ this ->getInstance ();
82+ $ this ->expectException (EmptyCertificateException::class);
83+ $ this ->expectExceptionMessage ('Common Name (CN) cannot be empty for root certificate ' );
84+ $ rootInstance ->generateRootCert ('' , []);
85+ }
86+
8087 public function testInvalidPassword (): void {
8188 // Create root cert
8289 $ rootInstance = $ this ->getInstance ();
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public static function setUpBeforeClass(): void {
5050 $ certificateEngine = self ::$ certificateEngineFactory ->getEngine ();
5151 $ certificateEngine
5252 ->setConfigPath (\OCP \Server::get (ITempManager::class)->getTemporaryFolder ('certificate ' ))
53- ->generateRootCert ('' , []);
53+ ->generateRootCert ('Test Root CA ' , []);
5454
5555 self ::$ certificateContent = $ certificateEngine
5656@@ -92,6 +92,7 @@ private function getInstance(array $methods = []): JSignPdfHandler|MockObject {
9292 $ this ->signatureBackgroundService ,
9393 $ certificateEngineFactory ,
9494 $ this ->javaHelper ,
95+ $ this ->createMock (\OCA \Libresign \Service \DocMdpConfigService::class),
9596 );
9697 }
9798 return $ this ->getMockBuilder (JSignPdfHandler::class)
@@ -103,6 +104,7 @@ private function getInstance(array $methods = []): JSignPdfHandler|MockObject {
103104 $ this ->signatureBackgroundService ,
104105 $ certificateEngineFactory ,
105106 $ this ->javaHelper ,
107+ $ this ->createMock (\OCA \Libresign \Service \DocMdpConfigService::class),
106108 ])
107109 ->onlyMethods ($ methods )
108110 ->getMock ();
You can’t perform that action at this time.
0 commit comments