001: package org.bouncycastle.asn1.x509;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1Sequence;
005: import org.bouncycastle.asn1.ASN1TaggedObject;
006: import org.bouncycastle.asn1.DERGeneralizedTime;
007: import org.bouncycastle.asn1.DERInteger;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERTaggedObject;
010: import org.bouncycastle.asn1.DERUTCTime;
011:
012: /**
013: * PKIX RFC-2459 - TBSCertList object.
014: * <pre>
015: * TBSCertList ::= SEQUENCE {
016: * version Version OPTIONAL,
017: * -- if present, shall be v2
018: * signature AlgorithmIdentifier,
019: * issuer Name,
020: * thisUpdate Time,
021: * nextUpdate Time OPTIONAL,
022: * revokedCertificates SEQUENCE OF SEQUENCE {
023: * userCertificate CertificateSerialNumber,
024: * revocationDate Time,
025: * crlEntryExtensions Extensions OPTIONAL
026: * -- if present, shall be v2
027: * } OPTIONAL,
028: * crlExtensions [0] EXPLICIT Extensions OPTIONAL
029: * -- if present, shall be v2
030: * }
031: * </pre>
032: */
033: public class TBSCertList extends ASN1Encodable {
034: public class CRLEntry extends ASN1Encodable {
035: ASN1Sequence seq;
036:
037: DERInteger userCertificate;
038: Time revocationDate;
039: X509Extensions crlEntryExtensions;
040:
041: public CRLEntry(ASN1Sequence seq) {
042: if (seq.size() < 2 || seq.size() > 3) {
043: throw new IllegalArgumentException(
044: "Bad sequence size: " + seq.size());
045: }
046:
047: this .seq = seq;
048:
049: userCertificate = DERInteger
050: .getInstance(seq.getObjectAt(0));
051: revocationDate = Time.getInstance(seq.getObjectAt(1));
052: if (seq.size() == 3) {
053: crlEntryExtensions = X509Extensions.getInstance(seq
054: .getObjectAt(2));
055: }
056: }
057:
058: public DERInteger getUserCertificate() {
059: return userCertificate;
060: }
061:
062: public Time getRevocationDate() {
063: return revocationDate;
064: }
065:
066: public X509Extensions getExtensions() {
067: return crlEntryExtensions;
068: }
069:
070: public DERObject toASN1Object() {
071: return seq;
072: }
073: }
074:
075: ASN1Sequence seq;
076:
077: DERInteger version;
078: AlgorithmIdentifier signature;
079: X509Name issuer;
080: Time this Update;
081: Time nextUpdate;
082: CRLEntry[] revokedCertificates;
083: X509Extensions crlExtensions;
084:
085: public static TBSCertList getInstance(ASN1TaggedObject obj,
086: boolean explicit) {
087: return getInstance(ASN1Sequence.getInstance(obj, explicit));
088: }
089:
090: public static TBSCertList getInstance(Object obj) {
091: if (obj instanceof TBSCertList) {
092: return (TBSCertList) obj;
093: } else if (obj instanceof ASN1Sequence) {
094: return new TBSCertList((ASN1Sequence) obj);
095: }
096:
097: throw new IllegalArgumentException("unknown object in factory");
098: }
099:
100: public TBSCertList(ASN1Sequence seq) {
101: if (seq.size() < 3 || seq.size() > 7) {
102: throw new IllegalArgumentException("Bad sequence size: "
103: + seq.size());
104: }
105:
106: int seqPos = 0;
107:
108: this .seq = seq;
109:
110: if (seq.getObjectAt(seqPos) instanceof DERInteger) {
111: version = DERInteger.getInstance(seq.getObjectAt(seqPos++));
112: } else {
113: version = new DERInteger(0);
114: }
115:
116: signature = AlgorithmIdentifier.getInstance(seq
117: .getObjectAt(seqPos++));
118: issuer = X509Name.getInstance(seq.getObjectAt(seqPos++));
119: this Update = Time.getInstance(seq.getObjectAt(seqPos++));
120:
121: if (seqPos < seq.size()
122: && (seq.getObjectAt(seqPos) instanceof DERUTCTime
123: || seq.getObjectAt(seqPos) instanceof DERGeneralizedTime || seq
124: .getObjectAt(seqPos) instanceof Time)) {
125: nextUpdate = Time.getInstance(seq.getObjectAt(seqPos++));
126: }
127:
128: if (seqPos < seq.size()
129: && !(seq.getObjectAt(seqPos) instanceof DERTaggedObject)) {
130: ASN1Sequence certs = ASN1Sequence.getInstance(seq
131: .getObjectAt(seqPos++));
132: revokedCertificates = new CRLEntry[certs.size()];
133:
134: for (int i = 0; i < revokedCertificates.length; i++) {
135: revokedCertificates[i] = new CRLEntry(ASN1Sequence
136: .getInstance(certs.getObjectAt(i)));
137: }
138: }
139:
140: if (seqPos < seq.size()
141: && seq.getObjectAt(seqPos) instanceof DERTaggedObject) {
142: crlExtensions = X509Extensions.getInstance(seq
143: .getObjectAt(seqPos++));
144: }
145: }
146:
147: public int getVersion() {
148: return version.getValue().intValue() + 1;
149: }
150:
151: public DERInteger getVersionNumber() {
152: return version;
153: }
154:
155: public AlgorithmIdentifier getSignature() {
156: return signature;
157: }
158:
159: public X509Name getIssuer() {
160: return issuer;
161: }
162:
163: public Time getThisUpdate() {
164: return this Update;
165: }
166:
167: public Time getNextUpdate() {
168: return nextUpdate;
169: }
170:
171: public CRLEntry[] getRevokedCertificates() {
172: return revokedCertificates;
173: }
174:
175: public X509Extensions getExtensions() {
176: return crlExtensions;
177: }
178:
179: public DERObject toASN1Object() {
180: return seq;
181: }
182: }
|