001: package org.bouncycastle.asn1.x509;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.DERInteger;
006: import org.bouncycastle.asn1.DERObjectIdentifier;
007: import org.bouncycastle.asn1.DERSequence;
008: import org.bouncycastle.asn1.DERGeneralizedTime;
009: import org.bouncycastle.asn1.DERBitString;
010: import org.bouncycastle.asn1.DERSet;
011:
012: /**
013: * Generator for Version 2 AttributeCertificateInfo
014: * <pre>
015: * AttributeCertificateInfo ::= SEQUENCE {
016: * version AttCertVersion -- version is v2,
017: * holder Holder,
018: * issuer AttCertIssuer,
019: * signature AlgorithmIdentifier,
020: * serialNumber CertificateSerialNumber,
021: * attrCertValidityPeriod AttCertValidityPeriod,
022: * attributes SEQUENCE OF Attribute,
023: * issuerUniqueID UniqueIdentifier OPTIONAL,
024: * extensions Extensions OPTIONAL
025: * }
026: * </pre>
027: *
028: */
029: public class V2AttributeCertificateInfoGenerator {
030: private DERInteger version;
031: private Holder holder;
032: private AttCertIssuer issuer;
033: private AlgorithmIdentifier signature;
034: private DERInteger serialNumber;
035: private ASN1EncodableVector attributes;
036: private DERBitString issuerUniqueID;
037: private X509Extensions extensions;
038:
039: // Note: validity period start/end dates stored directly
040: //private AttCertValidityPeriod attrCertValidityPeriod;
041: private DERGeneralizedTime startDate, endDate;
042:
043: public V2AttributeCertificateInfoGenerator() {
044: this .version = new DERInteger(1);
045: attributes = new ASN1EncodableVector();
046: }
047:
048: public void setHolder(Holder holder) {
049: this .holder = holder;
050: }
051:
052: public void addAttribute(String oid, ASN1Encodable value) {
053: attributes.add(new Attribute(new DERObjectIdentifier(oid),
054: new DERSet(value)));
055: }
056:
057: /**
058: * @param attribute
059: */
060: public void addAttribute(Attribute attribute) {
061: attributes.add(attribute);
062: }
063:
064: public void setSerialNumber(DERInteger serialNumber) {
065: this .serialNumber = serialNumber;
066: }
067:
068: public void setSignature(AlgorithmIdentifier signature) {
069: this .signature = signature;
070: }
071:
072: public void setIssuer(AttCertIssuer issuer) {
073: this .issuer = issuer;
074: }
075:
076: public void setStartDate(DERGeneralizedTime startDate) {
077: this .startDate = startDate;
078: }
079:
080: public void setEndDate(DERGeneralizedTime endDate) {
081: this .endDate = endDate;
082: }
083:
084: public void setIssuerUniqueID(DERBitString issuerUniqueID) {
085: this .issuerUniqueID = issuerUniqueID;
086: }
087:
088: public void setExtensions(X509Extensions extensions) {
089: this .extensions = extensions;
090: }
091:
092: public AttributeCertificateInfo generateAttributeCertificateInfo() {
093: if ((serialNumber == null) || (signature == null)
094: || (issuer == null) || (startDate == null)
095: || (endDate == null) || (holder == null)
096: || (attributes == null)) {
097: throw new IllegalStateException(
098: "not all mandatory fields set in V2 AttributeCertificateInfo generator");
099: }
100:
101: ASN1EncodableVector v = new ASN1EncodableVector();
102:
103: v.add(version);
104: v.add(holder);
105: v.add(issuer);
106: v.add(signature);
107: v.add(serialNumber);
108:
109: //
110: // before and after dates => AttCertValidityPeriod
111: //
112: AttCertValidityPeriod validity = new AttCertValidityPeriod(
113: startDate, endDate);
114: v.add(validity);
115:
116: // Attributes
117: v.add(new DERSequence(attributes));
118:
119: if (issuerUniqueID != null) {
120: v.add(issuerUniqueID);
121: }
122:
123: if (extensions != null) {
124: v.add(extensions);
125: }
126:
127: return new AttributeCertificateInfo(new DERSequence(v));
128: }
129: }
|