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);
}
}
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);
}
}
Aggregations