use of org.bouncycastle.cert.X509CRLHolder in project poi by apache.
the class PkiTestUtils method generateCrl.
public static X509CRL generateCrl(X509Certificate issuer, PrivateKey issuerPrivateKey) throws CertificateEncodingException, IOException, CRLException, OperatorCreationException {
X509CertificateHolder holder = new X509CertificateHolder(issuer.getEncoded());
X509v2CRLBuilder crlBuilder = new X509v2CRLBuilder(holder.getIssuer(), new Date());
crlBuilder.setNextUpdate(new Date(new Date().getTime() + 100000));
JcaContentSignerBuilder contentBuilder = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC");
CRLNumber crlNumber = new CRLNumber(new BigInteger("1234"));
crlBuilder.addExtension(Extension.cRLNumber, false, crlNumber);
X509CRLHolder x509Crl = crlBuilder.build(contentBuilder.build(issuerPrivateKey));
return new JcaX509CRLConverter().setProvider("BC").getCRL(x509Crl);
}
use of org.bouncycastle.cert.X509CRLHolder in project robovm by robovm.
the class CMSUtils method getCRLsFromStore.
static List getCRLsFromStore(Store crlStore) throws CMSException {
List certs = new ArrayList();
try {
for (Iterator it = crlStore.getMatches(null).iterator(); it.hasNext(); ) {
X509CRLHolder c = (X509CRLHolder) it.next();
certs.add(c.toASN1Structure());
}
return certs;
} catch (ClassCastException e) {
throw new CMSException("error processing certs", e);
}
}
use of org.bouncycastle.cert.X509CRLHolder in project xipki by xipki.
the class CaEmulator method getCrl.
public synchronized CertificateList getCrl(X500Name issuer, BigInteger serialNumber) throws Exception {
if (crl != null) {
return crl;
}
Date thisUpdate = new Date();
X509v2CRLBuilder crlBuilder = new X509v2CRLBuilder(caSubject, thisUpdate);
Date nextUpdate = new Date(thisUpdate.getTime() + 30 * DAY_IN_MS);
crlBuilder.setNextUpdate(nextUpdate);
Date caStartTime = caCert.getTBSCertificate().getStartDate().getDate();
Date revocationTime = new Date(caStartTime.getTime() + 1);
if (revocationTime.after(thisUpdate)) {
revocationTime = caStartTime;
}
crlBuilder.addCRLEntry(BigInteger.valueOf(2), revocationTime, CRLReason.keyCompromise);
crlBuilder.addExtension(Extension.cRLNumber, false, new ASN1Integer(crlNumber.getAndAdd(1)));
String signatureAlgorithm = ScepUtil.getSignatureAlgorithm(caKey, ScepHashAlgo.SHA256);
ContentSigner contentSigner = new JcaContentSignerBuilder(signatureAlgorithm).build(caKey);
X509CRLHolder crl = crlBuilder.build(contentSigner);
return crl.toASN1Structure();
}
use of org.bouncycastle.cert.X509CRLHolder in project candlepin by candlepin.
the class X509CRLStreamWriterTest method testSignatureKeyChange.
@Test
public void testSignatureKeyChange() throws Exception {
KeyPair differentKeyPair = generator.generateKeyPair();
ContentSigner otherSigner = new JcaContentSignerBuilder("SHA256WithRSAEncryption").setProvider(BC_PROVIDER).build(differentKeyPair.getPrivate());
X509v2CRLBuilder crlBuilder = createCRLBuilder();
X509CRLHolder holder = crlBuilder.build(otherSigner);
File crlToChange = writeCRL(holder);
X509CRLStreamWriter stream = new X509CRLStreamWriter(crlToChange, (RSAPrivateKey) keyPair.getPrivate(), (RSAPublicKey) keyPair.getPublic());
stream.preScan(crlToChange).lock();
OutputStream o = new BufferedOutputStream(new FileOutputStream(outfile));
stream.write(o);
o.close();
// No SignatureException should be thrown
readCRL();
}
use of org.bouncycastle.cert.X509CRLHolder in project candlepin by candlepin.
the class X509CRLStreamWriterTest method testDeleteEntryFromCRL.
@Test
public void testDeleteEntryFromCRL() throws Exception {
X509v2CRLBuilder crlBuilder = createCRLBuilder();
crlBuilder.addCRLEntry(new BigInteger("101"), new Date(), CRLReason.unspecified);
X509CRLHolder holder = crlBuilder.build(signer);
File crlToChange = writeCRL(holder);
CRLEntryValidator validator = new CRLEntryValidator() {
@Override
public boolean shouldDelete(CRLEntry entry) {
return entry.getUserCertificate().getValue().equals(new BigInteger("101"));
}
};
X509CRLStreamWriter stream = new X509CRLStreamWriter(crlToChange, (RSAPrivateKey) keyPair.getPrivate(), (RSAPublicKey) keyPair.getPublic());
stream.add(new BigInteger("9000"), new Date(), 0);
stream.preScan(crlToChange, validator).lock();
OutputStream o = new BufferedOutputStream(new FileOutputStream(outfile));
stream.write(o);
o.close();
X509CRL changedCrl = readCRL();
Set<BigInteger> discoveredSerials = new HashSet<>();
for (X509CRLEntry entry : changedCrl.getRevokedCertificates()) {
discoveredSerials.add(entry.getSerialNumber());
}
Set<BigInteger> expected = new HashSet<>();
expected.add(new BigInteger("100"));
expected.add(new BigInteger("9000"));
assertEquals(expected, discoveredSerials);
}
Aggregations