use of org.cloudfoundry.credhub.util.CurrentTimeProvider in project credhub by cloudfoundry-incubator.
the class CertificateGeneratorTest method makeCert.
private X509CertificateHolder makeCert(KeyPair certKeyPair, PrivateKey caPrivateKey, X500Name caDn, X500Name subjectDn, boolean isCa) throws OperatorCreationException, NoSuchAlgorithmException, CertIOException {
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(certKeyPair.getPublic().getEncoded());
ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256withRSA").setProvider(BouncyCastleProvider.PROVIDER_NAME).build(caPrivateKey);
CurrentTimeProvider currentTimeProvider = new CurrentTimeProvider();
Instant now = currentTimeProvider.getNow().toInstant();
X509v3CertificateBuilder x509v3CertificateBuilder = new X509v3CertificateBuilder(caDn, BigInteger.TEN, Date.from(now), Date.from(now.plus(Duration.ofDays(365))), subjectDn, publicKeyInfo);
x509v3CertificateBuilder.addExtension(Extension.basicConstraints, true, new BasicConstraints(isCa));
return x509v3CertificateBuilder.build(contentSigner);
}
Aggregations