KeyStoreCertSigner implements CertSigner, AutoCloseable { @Override public String generateX509Certificate(String csr, String keyUsage, int certExpiryMins) { int certExpiryTime = (certExpiryMins == 0) ? this.maxCertExpiryTimeMins : certExpiryMins; PKCS10CertificationRequest certReq = Crypto.getPKCS10CertRequest(csr); X509Certificate cert = Crypto.generateX509Certificate(certReq, caPrivateKey, caCertificate, certExpiryTime, false); return Crypto.convertToPEMFormat(cert); } KeyStoreCertSigner(X509Certificate caCertificate, PrivateKey caPrivateKey, int maxCertExpiryTimeMins); @Override String generateX509Certificate(String csr, String keyUsage, int certExpiryMins); @Override String getCACertificate(); @Override int getMaxCertExpiryTimeMins(); @Override void close();  }
@Test public void testGenerateX509Certificate() { try (KeyStoreCertSigner keyStoreCertSigner = new KeyStoreCertSigner(CA_CERT, CA_KEY, 43200)) { String certPem = keyStoreCertSigner.generateX509Certificate(CLIENT_CSR_PEM, null, 0); X509Certificate cert = Crypto.loadX509Certificate(certPem); long certExpiry = Duration.between(cert.getNotBefore().toInstant(), cert.getNotAfter().toInstant()).toMinutes(); Assert.assertEquals(cert.getIssuerX500Principal().getName(), "CN=Sample Self Signed Intermediate CA,O=Athenz,C=US"); Assert.assertEquals(cert.getSubjectX500Principal().getName(), "CN=sys.auth.zts,O=Athenz,C=US"); Assert.assertEquals(certExpiry, 43200); } }
@Test public void testGenerateX509CertificateWithExpiry() { int certExpiryMins = 60; try (KeyStoreCertSigner keyStoreCertSigner = new KeyStoreCertSigner(CA_CERT, CA_KEY, 43200)) { String certPem = keyStoreCertSigner.generateX509Certificate(CLIENT_CSR_PEM, null, certExpiryMins); X509Certificate cert = Crypto.loadX509Certificate(certPem); long certExpiry = Duration.between(cert.getNotBefore().toInstant(), cert.getNotAfter().toInstant()).toMinutes(); Assert.assertEquals(cert.getIssuerX500Principal().getName(), "CN=Sample Self Signed Intermediate CA,O=Athenz,C=US"); Assert.assertEquals(cert.getSubjectX500Principal().getName(), "CN=sys.auth.zts,O=Athenz,C=US"); Assert.assertEquals(certExpiry, 60); } }