Search in sources :

Example 6 with OperatorException

use of org.bouncycastle.operator.OperatorException in project qpid-broker-j by apache.

the class TlsResourceBuilder method createCertificateRevocationList.

static X509CRL createCertificateRevocationList(final KeyCertificatePair ca, X509Certificate... certificate) throws CRLException {
    try {
        final X500Name issuerName = X500Name.getInstance(RFC4519Style.INSTANCE, ca.getCertificate().getSubjectX500Principal().getEncoded());
        final Instant nextUpdate = Instant.now().plus(10, ChronoUnit.DAYS);
        final Date now = new Date();
        final X509v2CRLBuilder crlBuilder = new X509v2CRLBuilder(issuerName, now);
        crlBuilder.setNextUpdate(new Date(nextUpdate.toEpochMilli()));
        for (X509Certificate c : certificate) {
            crlBuilder.addCRLEntry(c.getSerialNumber(), now, CRLReason.privilegeWithdrawn);
        }
        crlBuilder.addExtension(createAuthorityKeyExtension(ca.getCertificate().getPublicKey()));
        crlBuilder.addExtension(Extension.cRLNumber, false, new CRLNumber(generateSerialNumber()));
        final ContentSigner contentSigner = createContentSigner(ca.getPrivateKey());
        final X509CRLHolder crl = crlBuilder.build(contentSigner);
        return new JcaX509CRLConverter().getCRL(crl);
    } catch (OperatorException | IOException | CertificateException e) {
        throw new CRLException(e);
    }
}
Also used : CRLNumber(org.bouncycastle.asn1.x509.CRLNumber) Instant(java.time.Instant) ContentSigner(org.bouncycastle.operator.ContentSigner) CertificateException(java.security.cert.CertificateException) X500Name(org.bouncycastle.asn1.x500.X500Name) IOException(java.io.IOException) Date(java.util.Date) X509Certificate(java.security.cert.X509Certificate) JcaX509CRLConverter(org.bouncycastle.cert.jcajce.JcaX509CRLConverter) X509CRLHolder(org.bouncycastle.cert.X509CRLHolder) X509v2CRLBuilder(org.bouncycastle.cert.X509v2CRLBuilder) CRLException(java.security.cert.CRLException) OperatorException(org.bouncycastle.operator.OperatorException)

Example 7 with OperatorException

use of org.bouncycastle.operator.OperatorException in project qpid-broker-j by apache.

the class TlsResourceBuilder method createSelfSignedCertificate.

private static X509Certificate createSelfSignedCertificate(final KeyPair keyPair, final String dn, final ValidityPeriod period, final AlternativeName... alternativeName) throws CertificateException {
    try {
        final X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(new X500Name(RFC4519Style.INSTANCE, dn), generateSerialNumber(), new Date(period.getFrom().toEpochMilli()), new Date(period.getTo().toEpochMilli()), new X500Name(RFC4519Style.INSTANCE, dn), keyPair.getPublic());
        builder.addExtension(Extension.basicConstraints, false, new BasicConstraints(false));
        builder.addExtension(createKeyUsageExtension());
        builder.addExtension(createSubjectKeyExtension(keyPair.getPublic()));
        builder.addExtension(createAlternateNamesExtension(alternativeName));
        return buildX509Certificate(builder, keyPair.getPrivate());
    } catch (OperatorException | IOException e) {
        throw new CertificateException(e);
    }
}
Also used : JcaX509v3CertificateBuilder(org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder) X509v3CertificateBuilder(org.bouncycastle.cert.X509v3CertificateBuilder) JcaX509v3CertificateBuilder(org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder) CertificateException(java.security.cert.CertificateException) X500Name(org.bouncycastle.asn1.x500.X500Name) IOException(java.io.IOException) BasicConstraints(org.bouncycastle.asn1.x509.BasicConstraints) Date(java.util.Date) OperatorException(org.bouncycastle.operator.OperatorException)

Aggregations

IOException (java.io.IOException)7 OperatorException (org.bouncycastle.operator.OperatorException)7 CertificateException (java.security.cert.CertificateException)5 Date (java.util.Date)5 X500Name (org.bouncycastle.asn1.x500.X500Name)5 BasicConstraints (org.bouncycastle.asn1.x509.BasicConstraints)5 JcaX509v3CertificateBuilder (org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder)5 X509v3CertificateBuilder (org.bouncycastle.cert.X509v3CertificateBuilder)4 CRLException (java.security.cert.CRLException)2 X509CRLHolder (org.bouncycastle.cert.X509CRLHolder)2 ContentSigner (org.bouncycastle.operator.ContentSigner)2 UncheckedIOException (java.io.UncheckedIOException)1 BigInteger (java.math.BigInteger)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Signature (java.security.Signature)1 SignatureException (java.security.SignatureException)1 X509Certificate (java.security.cert.X509Certificate)1 DSAParams (java.security.interfaces.DSAParams)1 DSAPublicKey (java.security.interfaces.DSAPublicKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1