Search in sources :

Example 6 with AuthorityKeyIdentifierStructure

use of com.android.org.bouncycastle.x509.extension.AuthorityKeyIdentifierStructure in project wso2-synapse by wso2.

the class CRLVerifierTest method createCRL.

/**
 * Creates a fake CRL for the fake CA. The fake certificate with the given revokedSerialNumber will be marked
 * as Revoked in the returned CRL.
 * @param caCert the fake CA certificate.
 * @param caPrivateKey private key of the fake CA.
 * @param revokedSerialNumber the serial number of the fake peer certificate made to be marked as revoked.
 * @return the created fake CRL
 * @throws Exception
 */
public static X509CRL createCRL(X509Certificate caCert, PrivateKey caPrivateKey, BigInteger revokedSerialNumber) throws Exception {
    X509V2CRLGenerator crlGen = new X509V2CRLGenerator();
    Date now = new Date();
    crlGen.setIssuerDN(caCert.getSubjectX500Principal());
    crlGen.setThisUpdate(now);
    crlGen.setNextUpdate(new Date(now.getTime() + TestConstants.NEXT_UPDATE_PERIOD));
    crlGen.setSignatureAlgorithm("SHA256WithRSAEncryption");
    crlGen.addCRLEntry(revokedSerialNumber, now, CRLReason.privilegeWithdrawn);
    crlGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(caCert));
    crlGen.addExtension(X509Extensions.CRLNumber, false, new CRLNumber(BigInteger.valueOf(1)));
    return crlGen.generateX509CRL(caPrivateKey, "BC");
}
Also used : AuthorityKeyIdentifierStructure(org.bouncycastle.x509.extension.AuthorityKeyIdentifierStructure) Date(java.util.Date) X509V2CRLGenerator(org.bouncycastle.x509.X509V2CRLGenerator)

Aggregations

AuthorityKeyIdentifierStructure (org.bouncycastle.x509.extension.AuthorityKeyIdentifierStructure)5 SubjectKeyIdentifierStructure (org.bouncycastle.x509.extension.SubjectKeyIdentifierStructure)4 X509Certificate (java.security.cert.X509Certificate)3 X500Principal (javax.security.auth.x500.X500Principal)3 BigInteger (java.math.BigInteger)2 Certificate (java.security.cert.Certificate)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 BasicConstraints (org.bouncycastle.asn1.x509.BasicConstraints)2 X509Principal (org.bouncycastle.jce.X509Principal)2 X509V3CertificateGenerator (org.bouncycastle.x509.X509V3CertificateGenerator)2 BasicConstraints (com.android.org.bouncycastle.asn1.x509.BasicConstraints)1 X509V3CertificateGenerator (com.android.org.bouncycastle.x509.X509V3CertificateGenerator)1 AuthorityKeyIdentifierStructure (com.android.org.bouncycastle.x509.extension.AuthorityKeyIdentifierStructure)1 SubjectKeyIdentifierStructure (com.android.org.bouncycastle.x509.extension.SubjectKeyIdentifierStructure)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 PrivateKey (java.security.PrivateKey)1 GregorianCalendar (java.util.GregorianCalendar)1 GeneralName (org.bouncycastle.asn1.x509.GeneralName)1