001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.security.x509;
019:
020: import java.io.IOException;
021:
022: import org.apache.harmony.security.asn1.BerInputStream;
023: import org.apache.harmony.security.asn1.ASN1Boolean;
024: import org.apache.harmony.security.asn1.ASN1Explicit;
025: import org.apache.harmony.security.asn1.ASN1Implicit;
026: import org.apache.harmony.security.asn1.ASN1Sequence;
027: import org.apache.harmony.security.asn1.ASN1Type;
028:
029: /**
030: * CRL's Issuing Distribution Point Extension (OID = 2.5.29.28).
031: * <pre>
032: * id-ce-issuingDistributionPoint OBJECT IDENTIFIER ::= { id-ce 28 }
033: *
034: * issuingDistributionPoint ::= SEQUENCE {
035: * distributionPoint [0] DistributionPointName OPTIONAL,
036: * onlyContainsUserCerts [1] BOOLEAN DEFAULT FALSE,
037: * onlyContainsCACerts [2] BOOLEAN DEFAULT FALSE,
038: * onlySomeReasons [3] ReasonFlags OPTIONAL,
039: * indirectCRL [4] BOOLEAN DEFAULT FALSE,
040: * onlyContainsAttributeCerts [5] BOOLEAN DEFAULT FALSE
041: * }
042: * </pre>
043: * (as specified in RFC 3280 http://www.ietf.org/rfc/rfc3280.txt)
044: */
045: public class IssuingDistributionPoint extends ExtensionValue {
046:
047: // values of the fields of the structure
048: private DistributionPointName distributionPoint;
049: private boolean onlyContainsUserCerts = false;
050: private boolean onlyContainsCACerts = false;
051: private ReasonFlags onlySomeReasons;
052: private boolean indirectCRL = false;
053: private boolean onlyContainsAttributeCerts = false;
054:
055: /**
056: * Constructs the object on the base of its distributionPoint and
057: * onlySomeReasons fields values.
058: */
059: public IssuingDistributionPoint(
060: DistributionPointName distributionPoint,
061: ReasonFlags onlySomeReasons) {
062: this .distributionPoint = distributionPoint;
063: this .onlySomeReasons = onlySomeReasons;
064: }
065:
066: /**
067: * Creates the extension object on the base of its encoded form.
068: */
069: public static IssuingDistributionPoint decode(byte[] encoding)
070: throws IOException {
071: IssuingDistributionPoint idp = (IssuingDistributionPoint) ASN1
072: .decode(encoding);
073: idp.encoding = encoding;
074: return idp;
075: }
076:
077: /**
078: * Sets the value of onlyContainsUserCerts field of the structure.
079: */
080: public void setOnlyContainsUserCerts(boolean onlyContainsUserCerts) {
081: this .onlyContainsUserCerts = onlyContainsUserCerts;
082: }
083:
084: /**
085: * Sets the value of onlyContainsCACerts field of the structure.
086: */
087: public void setOnlyContainsCACerts(boolean onlyContainsCACerts) {
088: this .onlyContainsCACerts = onlyContainsCACerts;
089: }
090:
091: /**
092: * Sets the value of indirectCRL field of the structure.
093: */
094: public void setIndirectCRL(boolean indirectCRL) {
095: this .indirectCRL = indirectCRL;
096: }
097:
098: /**
099: * Sets the value of onlyContainsAttributeCerts field of the structure.
100: */
101: public void setOnlyContainsAttributeCerts(
102: boolean onlyContainsAttributeCerts) {
103: this .onlyContainsAttributeCerts = onlyContainsAttributeCerts;
104: }
105:
106: /**
107: * Returns value of distributionPoint field of the structure.
108: */
109: public DistributionPointName getDistributionPoint() {
110: return distributionPoint;
111: }
112:
113: /**
114: * Returns value of onlyContainsUserCerts field of the structure.
115: */
116: public boolean getOnlyContainsUserCerts() {
117: return onlyContainsUserCerts;
118: }
119:
120: /**
121: * Returns value of onlyContainsCACerts field of the structure.
122: */
123: public boolean getOnlyContainsCACerts() {
124: return onlyContainsCACerts;
125: }
126:
127: /**
128: * Returns value of onlySomeReasons field of the structure.
129: */
130: public ReasonFlags getOnlySomeReasons() {
131: return onlySomeReasons;
132: }
133:
134: /**
135: * Returns value of indirectCRL field of the structure.
136: */
137: public boolean getIndirectCRL() {
138: return indirectCRL;
139: }
140:
141: /**
142: * Returns value of onlyContainsAttributeCerts field of the structure.
143: */
144: public boolean getOnlyContainsAttributeCerts() {
145: return onlyContainsAttributeCerts;
146: }
147:
148: /**
149: * Returns ASN.1 encoded form of this X.509 IssuingDistributionPoint value.
150: * @return a byte array containing ASN.1 encoded form.
151: */
152: public byte[] getEncoded() {
153: if (encoding == null) {
154: encoding = ASN1.encode(this );
155: }
156: return encoding;
157: }
158:
159: /**
160: * Places the string representation of extension value
161: * into the StringBuffer object.
162: */
163: public void dumpValue(StringBuffer buffer, String prefix) {
164: buffer.append(prefix).append("Issuing Distribution Point: [\n"); //$NON-NLS-1$
165: if (distributionPoint != null) {
166: distributionPoint.dumpValue(buffer, " " + prefix); //$NON-NLS-1$
167: }
168: buffer.append(prefix).append(" onlyContainsUserCerts: ") //$NON-NLS-1$
169: .append(onlyContainsUserCerts).append('\n');
170: buffer.append(prefix).append(" onlyContainsCACerts: ") //$NON-NLS-1$
171: .append(onlyContainsCACerts).append('\n');
172: if (onlySomeReasons != null) {
173: onlySomeReasons.dumpValue(buffer, prefix + " "); //$NON-NLS-1$
174: }
175: buffer.append(prefix).append(" indirectCRL: ") //$NON-NLS-1$
176: .append(indirectCRL).append('\n');
177: buffer.append(prefix).append(" onlyContainsAttributeCerts: ") //$NON-NLS-1$
178: .append(onlyContainsAttributeCerts).append('\n');
179: }
180:
181: /**
182: * ASN.1 Encoder/Decoder.
183: */
184: public static final ASN1Type ASN1 = new ASN1Sequence(
185: new ASN1Type[] {
186: // ASN.1 prohibits implicitly tagged CHOICE
187: new ASN1Explicit(0, DistributionPointName.ASN1),
188: new ASN1Implicit(1, ASN1Boolean.getInstance()),
189: new ASN1Implicit(2, ASN1Boolean.getInstance()),
190: new ASN1Implicit(3, ReasonFlags.ASN1),
191: new ASN1Implicit(4, ASN1Boolean.getInstance()),
192: new ASN1Implicit(5, ASN1Boolean.getInstance()) }) {
193: {
194: setOptional(0);
195: setOptional(3);
196: setDefault(Boolean.FALSE, 1);
197: setDefault(Boolean.FALSE, 2);
198: setDefault(Boolean.FALSE, 4);
199: setDefault(Boolean.FALSE, 5);
200: }
201:
202: protected Object getDecodedObject(BerInputStream in) {
203: Object[] values = (Object[]) in.content;
204: IssuingDistributionPoint idp = new IssuingDistributionPoint(
205: (DistributionPointName) values[0],
206: (ReasonFlags) values[3]);
207: idp.encoding = in.getEncoded();
208: if (values[1] != null) {
209: idp.setOnlyContainsUserCerts(((Boolean) values[1])
210: .booleanValue());
211: }
212: if (values[2] != null) {
213: idp.setOnlyContainsCACerts(((Boolean) values[2])
214: .booleanValue());
215: }
216: if (values[4] != null) {
217: idp
218: .setIndirectCRL(((Boolean) values[4])
219: .booleanValue());
220: }
221: if (values[5] != null) {
222: idp.setOnlyContainsAttributeCerts(((Boolean) values[5])
223: .booleanValue());
224: }
225: return idp;
226: }
227:
228: protected void getValues(Object object, Object[] values) {
229: IssuingDistributionPoint idp = (IssuingDistributionPoint) object;
230: values[0] = idp.distributionPoint;
231: values[1] = (idp.onlyContainsUserCerts) ? Boolean.TRUE
232: : null;
233: values[2] = (idp.onlyContainsCACerts) ? Boolean.TRUE : null;
234: values[3] = idp.onlySomeReasons;
235: values[4] = (idp.indirectCRL) ? Boolean.TRUE : null;
236: values[5] = (idp.onlyContainsAttributeCerts) ? Boolean.TRUE
237: : null;
238: }
239: };
240:
241: }
|