001package org.apache.commons.ssl.org.bouncycastle.asn1.x509;
002
003import java.io.IOException;
004
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Boolean;
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Encodable;
007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1ObjectIdentifier;
008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1OctetString;
009import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
010
011/**
012 * an object for the elements in the X.509 V3 extension block.
013 * @deprecated use Extension
014 */
015public class X509Extension
016{
017    /**
018     * Subject Directory Attributes
019     */
020    public static final ASN1ObjectIdentifier subjectDirectoryAttributes = new ASN1ObjectIdentifier("2.5.29.9");
021    
022    /**
023     * Subject Key Identifier 
024     */
025    public static final ASN1ObjectIdentifier subjectKeyIdentifier = new ASN1ObjectIdentifier("2.5.29.14");
026
027    /**
028     * Key Usage 
029     */
030    public static final ASN1ObjectIdentifier keyUsage = new ASN1ObjectIdentifier("2.5.29.15");
031
032    /**
033     * Private Key Usage Period 
034     */
035    public static final ASN1ObjectIdentifier privateKeyUsagePeriod = new ASN1ObjectIdentifier("2.5.29.16");
036
037    /**
038     * Subject Alternative Name 
039     */
040    public static final ASN1ObjectIdentifier subjectAlternativeName = new ASN1ObjectIdentifier("2.5.29.17");
041
042    /**
043     * Issuer Alternative Name 
044     */
045    public static final ASN1ObjectIdentifier issuerAlternativeName = new ASN1ObjectIdentifier("2.5.29.18");
046
047    /**
048     * Basic Constraints 
049     */
050    public static final ASN1ObjectIdentifier basicConstraints = new ASN1ObjectIdentifier("2.5.29.19");
051
052    /**
053     * CRL Number 
054     */
055    public static final ASN1ObjectIdentifier cRLNumber = new ASN1ObjectIdentifier("2.5.29.20");
056
057    /**
058     * Reason code 
059     */
060    public static final ASN1ObjectIdentifier reasonCode = new ASN1ObjectIdentifier("2.5.29.21");
061
062    /**
063     * Hold Instruction Code 
064     */
065    public static final ASN1ObjectIdentifier instructionCode = new ASN1ObjectIdentifier("2.5.29.23");
066
067    /**
068     * Invalidity Date 
069     */
070    public static final ASN1ObjectIdentifier invalidityDate = new ASN1ObjectIdentifier("2.5.29.24");
071
072    /**
073     * Delta CRL indicator 
074     */
075    public static final ASN1ObjectIdentifier deltaCRLIndicator = new ASN1ObjectIdentifier("2.5.29.27");
076
077    /**
078     * Issuing Distribution Point 
079     */
080    public static final ASN1ObjectIdentifier issuingDistributionPoint = new ASN1ObjectIdentifier("2.5.29.28");
081
082    /**
083     * Certificate Issuer 
084     */
085    public static final ASN1ObjectIdentifier certificateIssuer = new ASN1ObjectIdentifier("2.5.29.29");
086
087    /**
088     * Name Constraints 
089     */
090    public static final ASN1ObjectIdentifier nameConstraints = new ASN1ObjectIdentifier("2.5.29.30");
091
092    /**
093     * CRL Distribution Points 
094     */
095    public static final ASN1ObjectIdentifier cRLDistributionPoints = new ASN1ObjectIdentifier("2.5.29.31");
096
097    /**
098     * Certificate Policies 
099     */
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}