public CRLResponse generate(final CRLRequest request) {
try {
Date now = new Date();
BouncyCastleCRLRequest bcRequest = new BouncyCastleCRLRequest(request);
X509v2CRLBuilder builder = new X509v2CRLBuilder(bcRequest.getIssuerX500Name(), now);
builder.setNextUpdate(bcRequest.getNextUpdate());
X509Certificate certificate = bcRequest.getIssuerCertificate();
AuthorityKeyIdentifier authorityKeyIdentifier = new JcaX509ExtensionUtils().createAuthorityKeyIdentifier(certificate);
builder.addExtension(X509Extension.authorityKeyIdentifier, false, authorityKeyIdentifier);
builder.addExtension(X509Extension.cRLNumber, false, new CRLNumber(bcRequest.getNumber()));
if (bcRequest.getOldCrl() != null) {
X509CRLHolder current = new X509CRLHolder(bcRequest.getOldCrl());
builder.addCRL(current);
}
PrivateKey privateKey = bcRequest.getIssuerPrivateKey();
JcaContentSignerBuilder contentSignerBuilder = new JcaContentSignerBuilder(bcRequest.getSignAlgorithm());
contentSignerBuilder.setProvider(BouncyCastleProviderHelper.PROVIDER_NAME);
ContentSigner contentSigner = contentSignerBuilder.build(privateKey);
for (CRLEntry entry : bcRequest.getEntries()) {
builder.addCRLEntry(entry.getSerialNumber(), entry.getDate(), entry.getReason().getCode());
}
X509CRLHolder crlh = builder.build(contentSigner);
JcaX509CRLConverter crlConverter = new JcaX509CRLConverter();
crlConverter.setProvider(BouncyCastleProviderHelper.PROVIDER_NAME);
X509CRL crl = crlConverter.getCRL(crlh);