Search in sources :

Example 1 with CurrentTimeProvider

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);
}
Also used : CurrentTimeProvider(org.cloudfoundry.credhub.util.CurrentTimeProvider) JcaContentSignerBuilder(org.bouncycastle.operator.jcajce.JcaContentSignerBuilder) X509v3CertificateBuilder(org.bouncycastle.cert.X509v3CertificateBuilder) Instant(java.time.Instant) ContentSigner(org.bouncycastle.operator.ContentSigner) SubjectPublicKeyInfo(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo) BasicConstraints(org.bouncycastle.asn1.x509.BasicConstraints)

Aggregations

Instant (java.time.Instant)1 BasicConstraints (org.bouncycastle.asn1.x509.BasicConstraints)1 SubjectPublicKeyInfo (org.bouncycastle.asn1.x509.SubjectPublicKeyInfo)1 X509v3CertificateBuilder (org.bouncycastle.cert.X509v3CertificateBuilder)1 ContentSigner (org.bouncycastle.operator.ContentSigner)1 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)1 CurrentTimeProvider (org.cloudfoundry.credhub.util.CurrentTimeProvider)1