crlGen.addCRLEntry(BigInteger.ONE, now, entryExtensions);
crlGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(pair.getPublic()));
X509CRL crl = crlGen.generate(pair.getPrivate(), "BC");
if (!crl.getIssuerX500Principal().equals(new X500Principal("CN=Test CA")))
{
fail("failed CRL issuer test");
}
byte[] authExt = crl.getExtensionValue(X509Extensions.AuthorityKeyIdentifier.getId());
if (authExt == null)
{
fail("failed to find CRL extension");
}
AuthorityKeyIdentifier authId = new AuthorityKeyIdentifierStructure(authExt);
X509CRLEntry entry = crl.getRevokedCertificate(BigInteger.ONE);
if (entry == null)
{
fail("failed to find CRL entry");
}
if (!entry.getSerialNumber().equals(BigInteger.ONE))
{
fail("CRL cert serial number does not match");
}
if (!entry.hasExtensions())
{
fail("CRL entry extension not found");
}
byte[] ext = entry.getExtensionValue(X509Extensions.ReasonCode.getId());
if (ext != null)
{
DEREnumerated reasonCode = (DEREnumerated)X509ExtensionUtil.fromExtensionValue(ext);
if (reasonCode.getValue().intValue() != CRLReason.privilegeWithdrawn)
{
fail("CRL entry reasonCode wrong");
}
}
else
{
fail("CRL entry reasonCode not found");
}
//
// check loading of existing CRL
//
crlGen = new X509V2CRLGenerator();
now = new Date();
crlGen.setIssuerDN(new X500Principal("CN=Test CA"));
crlGen.setThisUpdate(now);
crlGen.setNextUpdate(new Date(now.getTime() + 100000));
crlGen.setSignatureAlgorithm("SHA256WithRSAEncryption");
crlGen.addCRL(crl);
crlGen.addCRLEntry(BigInteger.valueOf(2), now, entryExtensions);
crlGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(pair.getPublic()));
X509CRL newCrl = crlGen.generate(pair.getPrivate(), "BC");
int count = 0;
boolean oneFound = false;
boolean twoFound = false;
Iterator it = newCrl.getRevokedCertificates().iterator();
while (it.hasNext())
{
X509CRLEntry crlEnt = (X509CRLEntry)it.next();
if (crlEnt.getSerialNumber().intValue() == 1)
{
oneFound = true;
}
else if (crlEnt.getSerialNumber().intValue() == 2)
{
twoFound = true;
}
count++;
}
if (count != 2)
{
fail("wrong number of CRLs found");
}
if (!oneFound || !twoFound)
{
fail("wrong CRLs found in copied list");
}
//
// check factory read back
//
CertificateFactory cFact = CertificateFactory.getInstance("X.509", "BC");
X509CRL readCrl = (X509CRL)cFact.generateCRL(new ByteArrayInputStream(newCrl.getEncoded()));
if (readCrl == null)
{
fail("crl not returned!");
}