001: package org.bouncycastle.asn1.x509;
002:
003: import org.bouncycastle.asn1.ASN1Encodable;
004: import org.bouncycastle.asn1.ASN1EncodableVector;
005: import org.bouncycastle.asn1.ASN1Sequence;
006: import org.bouncycastle.asn1.ASN1TaggedObject;
007: import org.bouncycastle.asn1.DERBoolean;
008: import org.bouncycastle.asn1.DERObject;
009: import org.bouncycastle.asn1.DERSequence;
010: import org.bouncycastle.asn1.DERTaggedObject;
011:
012: /**
013: * <pre>
014: * IssuingDistributionPoint ::= SEQUENCE {
015: * distributionPoint [0] DistributionPointName OPTIONAL,
016: * onlyContainsUserCerts [1] BOOLEAN DEFAULT FALSE,
017: * onlyContainsCACerts [2] BOOLEAN DEFAULT FALSE,
018: * onlySomeReasons [3] ReasonFlags OPTIONAL,
019: * indirectCRL [4] BOOLEAN DEFAULT FALSE,
020: * onlyContainsAttributeCerts [5] BOOLEAN DEFAULT FALSE }
021: * </pre>
022: */
023: public class IssuingDistributionPoint extends ASN1Encodable {
024: private DistributionPointName distributionPoint;
025:
026: private boolean onlyContainsUserCerts;
027:
028: private boolean onlyContainsCACerts;
029:
030: private ReasonFlags onlySomeReasons;
031:
032: private boolean indirectCRL;
033:
034: private boolean onlyContainsAttributeCerts;
035:
036: private ASN1Sequence seq;
037:
038: public static IssuingDistributionPoint getInstance(
039: ASN1TaggedObject obj, boolean explicit) {
040: return getInstance(ASN1Sequence.getInstance(obj, explicit));
041: }
042:
043: public static IssuingDistributionPoint getInstance(Object obj) {
044: if (obj == null || obj instanceof IssuingDistributionPoint) {
045: return (IssuingDistributionPoint) obj;
046: } else if (obj instanceof ASN1Sequence) {
047: return new IssuingDistributionPoint((ASN1Sequence) obj);
048: }
049:
050: throw new IllegalArgumentException("unknown object in factory");
051: }
052:
053: /**
054: * Constructor from given details.
055: *
056: * @param distributionPoint
057: * May contain an URI as pointer to most current CRL.
058: * @param onlyContainsUserCerts Covers revocation information for end certificates.
059: * @param onlyContainsCACerts Covers revocation information for CA certificates.
060: *
061: * @param onlySomeReasons
062: * Which revocation reasons does this point cover.
063: * @param indirectCRL
064: * If <code>true</code> then the CRL contains revocation
065: * information about certificates ssued by other CAs.
066: * @param onlyContainsAttributeCerts Covers revocation information for attribute certificates.
067: */
068: public IssuingDistributionPoint(
069: DistributionPointName distributionPoint,
070: boolean onlyContainsUserCerts, boolean onlyContainsCACerts,
071: ReasonFlags onlySomeReasons, boolean indirectCRL,
072: boolean onlyContainsAttributeCerts) {
073: this .distributionPoint = distributionPoint;
074: this .indirectCRL = indirectCRL;
075: this .onlyContainsAttributeCerts = onlyContainsAttributeCerts;
076: this .onlyContainsCACerts = onlyContainsCACerts;
077: this .onlyContainsUserCerts = onlyContainsUserCerts;
078: this .onlySomeReasons = onlySomeReasons;
079:
080: ASN1EncodableVector vec = new ASN1EncodableVector();
081: if (distributionPoint != null) { // CHOICE item so explicitly tagged
082: vec.add(new DERTaggedObject(true, 0, distributionPoint));
083: }
084: if (!onlyContainsUserCerts) {
085: vec
086: .add(new DERTaggedObject(false, 1, new DERBoolean(
087: true)));
088: }
089: if (!onlyContainsCACerts) {
090: vec
091: .add(new DERTaggedObject(false, 2, new DERBoolean(
092: true)));
093: }
094: if (onlySomeReasons != null) {
095: vec.add(new DERTaggedObject(false, 3, onlySomeReasons));
096: }
097: if (!indirectCRL) {
098: vec
099: .add(new DERTaggedObject(false, 4, new DERBoolean(
100: true)));
101: }
102: if (!onlyContainsAttributeCerts) {
103: vec
104: .add(new DERTaggedObject(false, 5, new DERBoolean(
105: true)));
106: }
107:
108: seq = new DERSequence(vec);
109: }
110:
111: /**
112: * Constructor from ASN1Sequence
113: */
114: public IssuingDistributionPoint(ASN1Sequence seq) {
115: this .seq = seq;
116:
117: for (int i = 0; i != seq.size(); i++) {
118: ASN1TaggedObject o = ASN1TaggedObject.getInstance(seq
119: .getObjectAt(i));
120:
121: switch (o.getTagNo()) {
122: case 0:
123: // CHOICE so explicit
124: distributionPoint = DistributionPointName.getInstance(
125: o, true);
126: break;
127: case 1:
128: onlyContainsUserCerts = DERBoolean
129: .getInstance(o, false).isTrue();
130: break;
131: case 2:
132: onlyContainsCACerts = DERBoolean.getInstance(o, false)
133: .isTrue();
134: break;
135: case 3:
136: onlySomeReasons = new ReasonFlags(ReasonFlags
137: .getInstance(o, false));
138: break;
139: case 4:
140: indirectCRL = DERBoolean.getInstance(o, false).isTrue();
141: break;
142: case 5:
143: onlyContainsAttributeCerts = DERBoolean.getInstance(o,
144: false).isTrue();
145: break;
146: default:
147: throw new IllegalArgumentException(
148: "unknown tag in IssuingDistributionPoint");
149: }
150: }
151: }
152:
153: public boolean onlyContainsUserCerts() {
154: return onlyContainsUserCerts;
155: }
156:
157: public boolean onlyContainsCACerts() {
158: return onlyContainsCACerts;
159: }
160:
161: public boolean isIndirectCRL() {
162: return indirectCRL;
163: }
164:
165: public boolean onlyContainsAttributeCerts() {
166: return onlyContainsAttributeCerts;
167: }
168:
169: /**
170: * @return Returns the distributionPoint.
171: */
172: public DistributionPointName getDistributionPoint() {
173: return distributionPoint;
174: }
175:
176: /**
177: * @return Returns the onlySomeReasons.
178: */
179: public ReasonFlags getOnlySomeReasons() {
180: return onlySomeReasons;
181: }
182:
183: public DERObject toASN1Object() {
184: return seq;
185: }
186:
187: public String toString() {
188: String sep = System.getProperty("line.separator");
189: StringBuffer buf = new StringBuffer();
190:
191: buf.append("IssuingDistributionPoint: [");
192: buf.append(sep);
193: if (distributionPoint != null) {
194: appendObject(buf, sep, "distributionPoint",
195: distributionPoint.toString());
196: }
197: if (onlyContainsUserCerts) {
198: appendObject(buf, sep, "onlyContainsUserCerts",
199: booleanToString(onlyContainsUserCerts));
200: }
201: if (onlyContainsCACerts) {
202: appendObject(buf, sep, "onlyContainsCACerts",
203: booleanToString(onlyContainsCACerts));
204: }
205: if (onlySomeReasons != null) {
206: appendObject(buf, sep, "onlySomeReasons", onlySomeReasons
207: .toString());
208: }
209: if (onlyContainsAttributeCerts) {
210: appendObject(buf, sep, "onlyContainsAttributeCerts",
211: booleanToString(onlyContainsAttributeCerts));
212: }
213: if (indirectCRL) {
214: appendObject(buf, sep, "indirectCRL",
215: booleanToString(indirectCRL));
216: }
217: buf.append("]");
218: buf.append(sep);
219: return buf.toString();
220: }
221:
222: private void appendObject(StringBuffer buf, String sep,
223: String name, String value) {
224: String indent = " ";
225:
226: buf.append(indent);
227: buf.append(name);
228: buf.append(":");
229: buf.append(sep);
230: buf.append(indent);
231: buf.append(indent);
232: buf.append(value);
233: buf.append(sep);
234: }
235:
236: private String booleanToString(boolean value) {
237: return value ? "true" : "false";
238: }
239: }
|