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