CertificateUtils { public static X509Certificate createTestRootCertificate(String subject, Instant notBefore, Instant notAfter, KeyPair keypair) { Objects.requireNonNull(subject, "subject"); Objects.requireNonNull(notBefore, "notBefore"); Objects.requireNonNull(notAfter, "notAfter"); Objects.requireNonNull(keypair, "keypair"); JcaX509v1CertificateBuilder certBuilder = new JcaX509v1CertificateBuilder( new X500Name(subject), BigInteger.valueOf(System.currentTimeMillis()), Date.from(notBefore), Date.from(notAfter), new X500Name(subject), keypair.getPublic() ); return buildCertificate(certBuilder::build, keypair.getPrivate()); } private  CertificateUtils(); static PKCS10CertificationRequest readCSR(InputStream in); static X509Certificate createTlsAlpn01Certificate(KeyPair keypair, Identifier id, byte[] acmeValidation); static X509Certificate createTestRootCertificate(String subject,
            Instant notBefore, Instant notAfter, KeyPair keypair); static X509Certificate createTestIntermediateCertificate(String subject,
            Instant notBefore, Instant notAfter, PublicKey intermediatePublicKey,
            X509Certificate issuer, PrivateKey issuerPrivateKey); static X509Certificate createTestCertificate(PKCS10CertificationRequest csr,
            Instant notBefore, Instant notAfter, X509Certificate issuer, PrivateKey issuerPrivateKey); static final ASN1ObjectIdentifier ACME_VALIDATION; }
@Test public void testCreateTestRootCertificate() throws Exception { KeyPair keypair = KeyPairUtils.createKeyPair(2048); String subject = "CN=Test Root Certificate"; Instant notBefore = Instant.now().truncatedTo(SECONDS); Instant notAfter = notBefore.plus(Duration.ofDays(14)).truncatedTo(SECONDS); X509Certificate cert = CertificateUtils.createTestRootCertificate(subject, notBefore, notAfter, keypair); assertThat(cert.getIssuerX500Principal().getName(), is(subject)); assertThat(cert.getSubjectX500Principal().getName(), is(subject)); assertThat(cert.getNotBefore().toInstant(), is(notBefore)); assertThat(cert.getNotAfter().toInstant(), is(notAfter)); assertThat(cert.getSerialNumber(), not(nullValue())); assertThat(cert.getPublicKey(), is(keypair.getPublic())); cert.verify(cert.getPublicKey()); }