List of usage examples for org.bouncycastle.cert AttributeCertificateIssuer AttributeCertificateIssuer
public AttributeCertificateIssuer(X500Name principal)
From source file:AAModulePackage.ACHelper.java
public static X509AttributeCertificateHolder generateAttributeCertificate(X509CertificateHolder issuerCert, X509CertificateHolder associatedCert, PrivateKey pk, String role, String record_id, String record_subject, String[] record_types, String[] actions_taken) { //Set up the validity period. Date startDate = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000); Date endDate = new Date(System.currentTimeMillis() + 365 * 24 * 60 * 60 * 1000); //AttributeCertificateHolder is a wrapper class for AttributeCertificates, courtesy of the Legion of Bouncy Castle. AttributeCertificateIssuer certIssuer = new AttributeCertificateIssuer(issuerCert.getSubject()); /*/*from w ww. j a v a 2 s . c o m*/ Please note the distinction between AttributeCertificateHolder which appears to be the Entity in possession of the certificate, while X509AttributeCertificateHolder is a wrapper class for the actual certificate itself. */ AttributeCertificateHolder holder = new AttributeCertificateHolder(associatedCert); X509v2AttributeCertificateBuilder builder = new X509v2AttributeCertificateBuilder(holder, certIssuer, BigInteger.valueOf(System.currentTimeMillis()), startDate, endDate); builder.addAttribute(NewAttributeIdentifiers.role, new DERGeneralString(role)); builder.addAttribute(NewAttributeIdentifiers.record_id, new DERGeneralString(record_id)); builder.addAttribute(NewAttributeIdentifiers.record_subject, new DERGeneralString(record_subject)); builder.addAttribute(NewAttributeIdentifiers.time_stamp, new DERGeneralizedTime(new Date())); //record_types ArrayList<ASN1Encodable> rts = new ArrayList(); for (String s : record_types) { rts.add(new DERGeneralString(s)); } ASN1Encodable[] recTypes = rts.toArray(new DERGeneralString[rts.size()]); builder.addAttribute(NewAttributeIdentifiers.record_type, recTypes); //actions_taken ArrayList<ASN1Encodable> acts = new ArrayList(); for (String s : actions_taken) { acts.add(new DERGeneralString(s)); } ASN1Encodable[] actionsTaken = acts.toArray(new DERGeneralString[acts.size()]); builder.addAttribute(NewAttributeIdentifiers.actions_taken, actionsTaken); //Build the certificate X509AttributeCertificateHolder attrCert = null; try { //builds the attribute certificate, and signs it with the owner's private key. attrCert = builder .build(new JcaContentSignerBuilder("SHA256withRSAEncryption").setProvider("BC").build(pk)); } catch (OperatorCreationException e) { e.printStackTrace(); } System.out.println("ATTRIBUTE CERTIFICATE Successfully generated."); return attrCert; }
From source file:org.italiangrid.voms.asn1.VOMSACGenerator.java
License:Apache License
private AttributeCertificateIssuer buildIssuer() throws CertificateEncodingException { JcaX509CertificateHolder issuer = new JcaX509CertificateHolder(aaCredential.getCertificate()); return new AttributeCertificateIssuer(issuer.getSubject()); }