Skip to content

Commit

Permalink
Allow using uninitialized CA for generating CRL (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsaarni authored Oct 9, 2023
1 parent 7b166c7 commit ce7e4f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ public CertificateRevocationList writeAsPem(Path out) throws IOException, Certif
private X509CRLHolder generateCrl() throws CertificateException, NoSuchAlgorithmException {
if (this.issuer == null) {
if (this.revoked.isEmpty()) {
throw new IllegalArgumentException("issuer not known: either set issuer or add certificates to the CRL");
throw new IllegalArgumentException(
"issuer not known: either set issuer or add certificates to the CRL");
}
this.issuer = this.revoked.get(0).issuer;
}

// Ensure that the issuer has a key pair.
this.issuer.ensureGenerated();

Date effectiveRevocationTime = new Date();
if (this.thisUpdate != null) {
effectiveRevocationTime = this.thisUpdate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,16 @@ public void testWritingPem(@TempDir Path tempDir) throws Exception {
assertFalse(got.isRevoked(notRevokedCert.getCertificate()));
}

@Test
public void testUninitializedCaCertificate(@TempDir Path tempDir) throws Exception {
Credential uninitialized = new Credential().subject("cn=ca"); // We have not called generate() yet.
assertDoesNotThrow(() -> new CertificateRevocationList().issuer(uninitialized).writeAsPem(tempDir.resolve("crl.pem")));
}

@Test
public void testUninitializedRevokedCertificate(@TempDir Path tempDir) throws Exception {
Credential uninitialized = new Credential().issuer(ca).subject("cn=uninitialized"); // We have not called generate() yet.
assertDoesNotThrow(() -> new CertificateRevocationList().issuer(ca).add(uninitialized).writeAsPem(tempDir.resolve("crl.pem")));
}

}

0 comments on commit ce7e4f1

Please sign in to comment.