1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.harmony.security.x509; 19 20 import java.io.IOException; 21 import org.apache.harmony.security.asn1.ASN1Boolean; 22 import org.apache.harmony.security.asn1.ASN1Explicit; 23 import org.apache.harmony.security.asn1.ASN1Implicit; 24 import org.apache.harmony.security.asn1.ASN1Sequence; 25 import org.apache.harmony.security.asn1.ASN1Type; 26 import org.apache.harmony.security.asn1.BerInputStream; 27 28 /** 29 * CRL's Issuing Distribution Point Extension (OID = 2.5.29.28). 30 * <pre> 31 * id-ce-issuingDistributionPoint OBJECT IDENTIFIER ::= { id-ce 28 } 32 * 33 * issuingDistributionPoint ::= SEQUENCE { 34 * distributionPoint [0] DistributionPointName OPTIONAL, 35 * onlyContainsUserCerts [1] BOOLEAN DEFAULT FALSE, 36 * onlyContainsCACerts [2] BOOLEAN DEFAULT FALSE, 37 * onlySomeReasons [3] ReasonFlags OPTIONAL, 38 * indirectCRL [4] BOOLEAN DEFAULT FALSE, 39 * onlyContainsAttributeCerts [5] BOOLEAN DEFAULT FALSE 40 * } 41 * </pre> 42 * (as specified in RFC 3280 http://www.ietf.org/rfc/rfc3280.txt) 43 */ 44 public final class IssuingDistributionPoint extends ExtensionValue { 45 // values of the fields of the structure 46 private DistributionPointName distributionPoint; 47 private boolean onlyContainsUserCerts = false; 48 private boolean onlyContainsCACerts = false; 49 private ReasonFlags onlySomeReasons; 50 private boolean indirectCRL = false; 51 private boolean onlyContainsAttributeCerts = false; 52 53 /** 54 * Constructs the object on the base of its distributionPoint and 55 * onlySomeReasons fields values. 56 */ 57 public IssuingDistributionPoint(DistributionPointName distributionPoint, 58 ReasonFlags onlySomeReasons) { 59 this.distributionPoint = distributionPoint; 60 this.onlySomeReasons = onlySomeReasons; 61 } 62 63 /** 64 * Creates the extension object on the base of its encoded form. 65 */ 66 public static IssuingDistributionPoint decode(byte[] encoding) 67 throws IOException { 68 IssuingDistributionPoint idp = 69 (IssuingDistributionPoint) ASN1.decode(encoding); 70 idp.encoding = encoding; 71 return idp; 72 } 73 74 /** 75 * Sets the value of onlyContainsUserCerts field of the structure. 76 */ 77 public void setOnlyContainsUserCerts(boolean onlyContainsUserCerts) { 78 this.onlyContainsUserCerts = onlyContainsUserCerts; 79 } 80 81 /** 82 * Sets the value of onlyContainsCACerts field of the structure. 83 */ 84 public void setOnlyContainsCACerts(boolean onlyContainsCACerts) { 85 this.onlyContainsCACerts = onlyContainsCACerts; 86 } 87 88 /** 89 * Sets the value of indirectCRL field of the structure. 90 */ 91 public void setIndirectCRL(boolean indirectCRL) { 92 this.indirectCRL = indirectCRL; 93 } 94 95 /** 96 * Sets the value of onlyContainsAttributeCerts field of the structure. 97 */ 98 public void setOnlyContainsAttributeCerts( 99 boolean onlyContainsAttributeCerts) { 100 this.onlyContainsAttributeCerts = onlyContainsAttributeCerts; 101 } 102 103 @Override public byte[] getEncoded() { 104 if (encoding == null) { 105 encoding = ASN1.encode(this); 106 } 107 return encoding; 108 } 109 110 @Override public void dumpValue(StringBuilder sb, String prefix) { 111 sb.append(prefix).append("Issuing Distribution Point: [\n"); 112 if (distributionPoint != null) { 113 distributionPoint.dumpValue(sb, " " + prefix); 114 } 115 sb.append(prefix).append(" onlyContainsUserCerts: ").append(onlyContainsUserCerts).append('\n'); 116 sb.append(prefix).append(" onlyContainsCACerts: ").append(onlyContainsCACerts).append('\n'); 117 if (onlySomeReasons != null) { 118 onlySomeReasons.dumpValue(sb, prefix + " "); 119 } 120 sb.append(prefix).append(" indirectCRL: ").append(indirectCRL).append('\n'); 121 sb.append(prefix).append(" onlyContainsAttributeCerts: ").append(onlyContainsAttributeCerts).append('\n'); 122 } 123 124 /** 125 * ASN.1 Encoder/Decoder. 126 */ 127 public static final ASN1Type ASN1 = new ASN1Sequence( 128 new ASN1Type[] { 129 // ASN.1 prohibits implicitly tagged CHOICE 130 new ASN1Explicit(0, DistributionPointName.ASN1), 131 new ASN1Implicit(1, ASN1Boolean.getInstance()), 132 new ASN1Implicit(2, ASN1Boolean.getInstance()), 133 new ASN1Implicit(3, ReasonFlags.ASN1), 134 new ASN1Implicit(4, ASN1Boolean.getInstance()), 135 new ASN1Implicit(5, ASN1Boolean.getInstance()) 136 }) { 137 { 138 setOptional(0); 139 setOptional(3); 140 setDefault(Boolean.FALSE, 1); 141 setDefault(Boolean.FALSE, 2); 142 setDefault(Boolean.FALSE, 4); 143 setDefault(Boolean.FALSE, 5); 144 } 145 146 protected Object getDecodedObject(BerInputStream in) { 147 Object[] values = (Object[]) in.content; 148 IssuingDistributionPoint idp = new IssuingDistributionPoint( 149 (DistributionPointName) values[0], (ReasonFlags) values[3]); 150 idp.encoding = in.getEncoded(); 151 if (values[1] != null) { 152 idp.setOnlyContainsUserCerts((Boolean) values[1]); 153 } 154 if (values[2] != null) { 155 idp.setOnlyContainsCACerts((Boolean) values[2]); 156 } 157 if (values[4] != null) { 158 idp.setIndirectCRL((Boolean) values[4]); 159 } 160 if (values[5] != null) { 161 idp.setOnlyContainsAttributeCerts((Boolean) values[5]); 162 } 163 return idp; 164 } 165 166 protected void getValues(Object object, Object[] values) { 167 IssuingDistributionPoint idp = (IssuingDistributionPoint) object; 168 values[0] = idp.distributionPoint; 169 values[1] = (idp.onlyContainsUserCerts) ? Boolean.TRUE : null; 170 values[2] = (idp.onlyContainsCACerts) ? Boolean.TRUE : null; 171 values[3] = idp.onlySomeReasons; 172 values[4] = (idp.indirectCRL) ? Boolean.TRUE : null; 173 values[5] = (idp.onlyContainsAttributeCerts) ? Boolean.TRUE : null; 174 } 175 }; 176 177 } 178