1 package org.bouncycastle.asn1.x509;
4 import java.util.Vector;
5 import java.util.Enumeration;
7 import org.bouncycastle.asn1.*;
10 * Generator for Version 2 TBSCertList structures.
12 * TBSCertList ::= SEQUENCE {
13 * version Version OPTIONAL,
14 * -- if present, shall be v2
15 * signature AlgorithmIdentifier,
18 * nextUpdate Time OPTIONAL,
19 * revokedCertificates SEQUENCE OF SEQUENCE {
20 * userCertificate CertificateSerialNumber,
21 * revocationDate Time,
22 * crlEntryExtensions Extensions OPTIONAL
23 * -- if present, shall be v2
25 * crlExtensions [0] EXPLICIT Extensions OPTIONAL
26 * -- if present, shall be v2
30 * <b>Note: This class may be subject to change</b>
32 public class V2TBSCertListGenerator
34 DERInteger version = new DERInteger(1);
36 AlgorithmIdentifier signature;
38 Time thisUpdate, nextUpdate=null;
39 X509Extensions extensions=null;
40 private Vector crlentries=null;
42 public V2TBSCertListGenerator()
47 public void setSignature(
48 AlgorithmIdentifier signature)
50 this.signature = signature;
53 public void setIssuer(
59 public void setThisUpdate(
60 DERUTCTime thisUpdate)
62 this.thisUpdate = new Time(thisUpdate);
65 public void setNextUpdate(
66 DERUTCTime nextUpdate)
68 this.nextUpdate = new Time(nextUpdate);
71 public void setThisUpdate(
74 this.thisUpdate = thisUpdate;
77 public void setNextUpdate(
80 this.nextUpdate = nextUpdate;
83 public void addCRLEntry(
84 DERConstructedSequence crlEntry)
86 if (crlentries == null)
87 crlentries = new Vector();
88 crlentries.addElement(crlEntry);
91 public void addCRLEntry(DERInteger userCertificate, DERUTCTime revocationDate, int reason)
93 addCRLEntry(userCertificate, new Time(revocationDate), reason);
96 public void addCRLEntry(DERInteger userCertificate, Time revocationDate, int reason)
98 DERConstructedSequence seq = new DERConstructedSequence();
99 seq.addObject(userCertificate);
100 seq.addObject(revocationDate);
104 CRLReason rf = new CRLReason(reason);
105 ByteArrayOutputStream bOut = new ByteArrayOutputStream();
106 DEROutputStream dOut = new DEROutputStream(bOut);
109 dOut.writeObject(rf);
111 catch (IOException e)
113 throw new IllegalArgumentException("error encoding value: " + e);
115 byte[] value = bOut.toByteArray();
116 DERConstructedSequence eseq = new DERConstructedSequence();
117 DERConstructedSequence eseq1 = new DERConstructedSequence();
118 eseq1.addObject(X509Extensions.ReasonCode);
119 eseq1.addObject(new DEROctetString(value));
120 eseq.addObject(eseq1);
121 X509Extensions ex = new X509Extensions(eseq);
124 if (crlentries == null)
125 crlentries = new Vector();
126 crlentries.addElement(seq);
129 public void setExtensions(
130 X509Extensions extensions)
132 this.extensions = extensions;
135 public TBSCertList generateTBSCertList()
137 if ((signature == null) || (issuer == null) || (thisUpdate == null))
139 throw new IllegalStateException("Not all mandatory fields set in V2 TBSCertList generator.");
142 DERConstructedSequence seq = new DERConstructedSequence();
144 seq.addObject(version);
145 seq.addObject(signature);
146 seq.addObject(issuer);
148 seq.addObject(thisUpdate);
149 if (nextUpdate != null)
150 seq.addObject(nextUpdate);
152 // Add CRLEntries if they exist
153 if (crlentries != null) {
154 DERConstructedSequence certseq = new DERConstructedSequence();
155 Enumeration it = crlentries.elements();
156 while( it.hasMoreElements() ) {
157 certseq.addObject((DERConstructedSequence)it.nextElement());
159 seq.addObject(certseq);
162 if (extensions != null)
164 seq.addObject(new DERTaggedObject(0, extensions));
167 return new TBSCertList(seq);