use of org.bouncycastle.cert.X509CRLHolder in project candlepin by candlepin.
the class X509CRLEntryStreamTest method testCRLwithoutUpdateTime.
@Test
public void testCRLwithoutUpdateTime() throws Exception {
X509v2CRLBuilder crlBuilder = new X509v2CRLBuilder(issuer, new Date());
AuthorityKeyIdentifier identifier = new JcaX509ExtensionUtils().createAuthorityKeyIdentifier(keyPair.getPublic());
crlBuilder.addExtension(Extension.authorityKeyIdentifier, false, identifier);
crlBuilder.addExtension(Extension.cRLNumber, false, new CRLNumber(new BigInteger("127")));
crlBuilder.addCRLEntry(new BigInteger("100"), new Date(), CRLReason.unspecified);
X509CRLHolder holder = crlBuilder.build(signer);
File noUpdateTimeCrl = new File(folder.getRoot(), "test.crl");
FileUtils.writeByteArrayToFile(noUpdateTimeCrl, holder.getEncoded());
X509CRLEntryStream stream = new X509CRLEntryStream(noUpdateTimeCrl);
try {
Set<BigInteger> streamedSerials = new HashSet<>();
while (stream.hasNext()) {
streamedSerials.add(getSerial(stream.next()));
}
assertEquals(1, streamedSerials.size());
assertTrue(streamedSerials.contains(new BigInteger("100")));
} finally {
stream.close();
}
}
use of org.bouncycastle.cert.X509CRLHolder in project wildfly by wildfly.
the class CertificateRevocationListTestBase method prepareCrlFiles.
private static void prepareCrlFiles(X509Certificate intermediateIssuerCertificate, SelfSignedX509CertificateAndSigningKey issuerSelfSignedX509CertificateAndSigningKey, X509Certificate revoked, File crlFile) throws Exception {
// Used for all CRLs
Calendar calendar = Calendar.getInstance();
Date currentDate = calendar.getTime();
calendar.add(Calendar.YEAR, 1);
Date nextYear = calendar.getTime();
calendar.add(Calendar.YEAR, -1);
calendar.add(Calendar.SECOND, -30);
Date revokeDate = calendar.getTime();
X509v2CRLBuilder caBlankCrlBuilder = new X509v2CRLBuilder(convertSunStyleToBCStyle(intermediateIssuerCertificate.getIssuerDN()), currentDate);
caBlankCrlBuilder.addCRLEntry(revoked.getSerialNumber(), currentDate, CRLReason.unspecified);
X509CRLHolder caBlankCrlHolder = caBlankCrlBuilder.setNextUpdate(nextYear).build(new JcaContentSignerBuilder("SHA256withRSA").setProvider("BC").build(issuerSelfSignedX509CertificateAndSigningKey.getSigningKey()));
PemWriter caBlankCrlOutput = new PemWriter(new OutputStreamWriter(new FileOutputStream(crlFile)));
caBlankCrlOutput.writeObject(new MiscPEMGenerator(caBlankCrlHolder));
caBlankCrlOutput.close();
}
use of org.bouncycastle.cert.X509CRLHolder in project wildfly by wildfly.
the class OcspTestBase method prepareCrlFiles.
private static void prepareCrlFiles(X509Certificate intermediateIssuerCertificate, SelfSignedX509CertificateAndSigningKey issuerSelfSignedX509CertificateAndSigningKey) throws Exception {
// Used for all CRLs
Calendar calendar = Calendar.getInstance();
Date currentDate = calendar.getTime();
calendar.add(Calendar.YEAR, 1);
Date nextYear = calendar.getTime();
calendar.add(Calendar.YEAR, -1);
calendar.add(Calendar.SECOND, -30);
// Creates the CRL for ca/crl/blank.pem
X509v2CRLBuilder caBlankCrlBuilder = new X509v2CRLBuilder(convertSunStyleToBCStyle(intermediateIssuerCertificate.getIssuerDN()), currentDate);
X509CRLHolder caBlankCrlHolder = caBlankCrlBuilder.setNextUpdate(nextYear).build(new JcaContentSignerBuilder("SHA256withRSA").setProvider("BC").build(issuerSelfSignedX509CertificateAndSigningKey.getSigningKey()));
PemWriter caBlankCrlOutput = new PemWriter(new OutputStreamWriter(new FileOutputStream(CA_BLANK_PEM_CRL)));
caBlankCrlOutput.writeObject(new MiscPEMGenerator(caBlankCrlHolder));
caBlankCrlOutput.close();
}
use of org.bouncycastle.cert.X509CRLHolder in project zookeeper by apache.
the class QuorumSSLTest method buildCRL.
private void buildCRL(X509Certificate x509Certificate, String crlPath) throws Exception {
X509v2CRLBuilder builder = new JcaX509v2CRLBuilder(x509Certificate.getIssuerX500Principal(), certStartTime);
builder.addCRLEntry(x509Certificate.getSerialNumber(), certStartTime, CRLReason.cACompromise);
builder.setNextUpdate(certEndTime);
builder.addExtension(Extension.authorityKeyIdentifier, false, new JcaX509ExtensionUtils().createAuthorityKeyIdentifier(rootCertificate));
builder.addExtension(Extension.cRLNumber, false, new CRLNumber(new BigInteger("1000")));
X509CRLHolder cRLHolder = builder.build(contentSigner);
PemWriter pemWriter = new PemWriter(new FileWriter(crlPath));
pemWriter.writeObject(new MiscPEMGenerator(cRLHolder));
pemWriter.flush();
pemWriter.close();
}
use of org.bouncycastle.cert.X509CRLHolder 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);
}
}
Aggregations