1 package org.bouncycastle.asn1.x509; 2 3 import java.io.IOException; 4 5 import org.bouncycastle.asn1.ASN1Boolean; 6 import org.bouncycastle.asn1.ASN1Encodable; 7 import org.bouncycastle.asn1.ASN1ObjectIdentifier; 8 import org.bouncycastle.asn1.ASN1OctetString; 9 import org.bouncycastle.asn1.ASN1Primitive; 10 11 /** 12 * an object for the elements in the X.509 V3 extension block. 13 * @deprecated use Extension 14 */ 15 public class X509Extension 16 { 17 /** 18 * Subject Directory Attributes 19 */ 20 public static final ASN1ObjectIdentifier subjectDirectoryAttributes = new ASN1ObjectIdentifier("2.5.29.9"); 21 22 /** 23 * Subject Key Identifier 24 */ 25 public static final ASN1ObjectIdentifier subjectKeyIdentifier = new ASN1ObjectIdentifier("2.5.29.14"); 26 27 /** 28 * Key Usage 29 */ 30 public static final ASN1ObjectIdentifier keyUsage = new ASN1ObjectIdentifier("2.5.29.15"); 31 32 /** 33 * Private Key Usage Period 34 */ 35 public static final ASN1ObjectIdentifier privateKeyUsagePeriod = new ASN1ObjectIdentifier("2.5.29.16"); 36 37 /** 38 * Subject Alternative Name 39 */ 40 public static final ASN1ObjectIdentifier subjectAlternativeName = new ASN1ObjectIdentifier("2.5.29.17"); 41 42 /** 43 * Issuer Alternative Name 44 */ 45 public static final ASN1ObjectIdentifier issuerAlternativeName = new ASN1ObjectIdentifier("2.5.29.18"); 46 47 /** 48 * Basic Constraints 49 */ 50 public static final ASN1ObjectIdentifier basicConstraints = new ASN1ObjectIdentifier("2.5.29.19"); 51 52 /** 53 * CRL Number 54 */ 55 public static final ASN1ObjectIdentifier cRLNumber = new ASN1ObjectIdentifier("2.5.29.20"); 56 57 /** 58 * Reason code 59 */ 60 public static final ASN1ObjectIdentifier reasonCode = new ASN1ObjectIdentifier("2.5.29.21"); 61 62 /** 63 * Hold Instruction Code 64 */ 65 public static final ASN1ObjectIdentifier instructionCode = new ASN1ObjectIdentifier("2.5.29.23"); 66 67 /** 68 * Invalidity Date 69 */ 70 public static final ASN1ObjectIdentifier invalidityDate = new ASN1ObjectIdentifier("2.5.29.24"); 71 72 /** 73 * Delta CRL indicator 74 */ 75 public static final ASN1ObjectIdentifier deltaCRLIndicator = new ASN1ObjectIdentifier("2.5.29.27"); 76 77 /** 78 * Issuing Distribution Point 79 */ 80 public static final ASN1ObjectIdentifier issuingDistributionPoint = new ASN1ObjectIdentifier("2.5.29.28"); 81 82 /** 83 * Certificate Issuer 84 */ 85 public static final ASN1ObjectIdentifier certificateIssuer = new ASN1ObjectIdentifier("2.5.29.29"); 86 87 /** 88 * Name Constraints 89 */ 90 public static final ASN1ObjectIdentifier nameConstraints = new ASN1ObjectIdentifier("2.5.29.30"); 91 92 /** 93 * CRL Distribution Points 94 */ 95 public static final ASN1ObjectIdentifier cRLDistributionPoints = new ASN1ObjectIdentifier("2.5.29.31"); 96 97 /** 98 * Certificate Policies 99 */ 100 public static final ASN1ObjectIdentifier certificatePolicies = new ASN1ObjectIdentifier("2.5.29.32"); 101 102 /** 103 * Policy Mappings 104 */ 105 public static final ASN1ObjectIdentifier policyMappings = new ASN1ObjectIdentifier("2.5.29.33"); 106 107 /** 108 * Authority Key Identifier 109 */ 110 public static final ASN1ObjectIdentifier authorityKeyIdentifier = new ASN1ObjectIdentifier("2.5.29.35"); 111 112 /** 113 * Policy Constraints 114 */ 115 public static final ASN1ObjectIdentifier policyConstraints = new ASN1ObjectIdentifier("2.5.29.36"); 116 117 /** 118 * Extended Key Usage 119 */ 120 public static final ASN1ObjectIdentifier extendedKeyUsage = new ASN1ObjectIdentifier("2.5.29.37"); 121 122 /** 123 * Freshest CRL 124 */ 125 public static final ASN1ObjectIdentifier freshestCRL = new ASN1ObjectIdentifier("2.5.29.46"); 126 127 /** 128 * Inhibit Any Policy 129 */ 130 public static final ASN1ObjectIdentifier inhibitAnyPolicy = new ASN1ObjectIdentifier("2.5.29.54"); 131 132 /** 133 * Authority Info Access 134 */ 135 public static final ASN1ObjectIdentifier authorityInfoAccess = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.1.1"); 136 137 /** 138 * Subject Info Access 139 */ 140 public static final ASN1ObjectIdentifier subjectInfoAccess = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.1.11"); 141 142 /** 143 * Logo Type 144 */ 145 public static final ASN1ObjectIdentifier logoType = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.1.12"); 146 147 /** 148 * BiometricInfo 149 */ 150 public static final ASN1ObjectIdentifier biometricInfo = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.1.2"); 151 152 /** 153 * QCStatements 154 */ 155 public static final ASN1ObjectIdentifier qCStatements = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.1.3"); 156 157 /** 158 * Audit identity extension in attribute certificates. 159 */ 160 public static final ASN1ObjectIdentifier auditIdentity = new ASN1ObjectIdentifier("1.3.6.1.5.5.7.1.4"); 161 162 /** 163 * NoRevAvail extension in attribute certificates. 164 */ 165 public static final ASN1ObjectIdentifier noRevAvail = new ASN1ObjectIdentifier("2.5.29.56"); 166 167 /** 168 * TargetInformation extension in attribute certificates. 169 */ 170 public static final ASN1ObjectIdentifier targetInformation = new ASN1ObjectIdentifier("2.5.29.55"); 171 172 boolean critical; 173 ASN1OctetString value; 174 175 public X509Extension( 176 ASN1Boolean critical, 177 ASN1OctetString value) 178 { 179 this.critical = critical.isTrue(); 180 this.value = value; 181 } 182 183 public X509Extension( 184 boolean critical, 185 ASN1OctetString value) 186 { 187 this.critical = critical; 188 this.value = value; 189 } 190 191 public boolean isCritical() 192 { 193 return critical; 194 } 195 196 public ASN1OctetString getValue() 197 { 198 return value; 199 } 200 201 public ASN1Encodable getParsedValue() 202 { 203 return convertValueToObject(this); 204 } 205 206 public int hashCode() 207 { 208 if (this.isCritical()) 209 { 210 return this.getValue().hashCode(); 211 } 212 213 return ~this.getValue().hashCode(); 214 } 215 216 public boolean equals( 217 Object o) 218 { 219 if (!(o instanceof X509Extension)) 220 { 221 return false; 222 } 223 224 X509Extension other = (X509Extension)o; 225 226 return other.getValue().equals(this.getValue()) 227 && (other.isCritical() == this.isCritical()); 228 } 229 230 /** 231 * Convert the value of the passed in extension to an object 232 * @param ext the extension to parse 233 * @return the object the value string contains 234 * @exception IllegalArgumentException if conversion is not possible 235 */ 236 public static ASN1Primitive convertValueToObject( 237 X509Extension ext) 238 throws IllegalArgumentException 239 { 240 try 241 { 242 return ASN1Primitive.fromByteArray(ext.getValue().getOctets()); 243 } 244 catch (IOException e) 245 { 246 throw new IllegalArgumentException("can't convert extension: " + e); 247 } 248 } 249 } 250