Home | History | Annotate | Download | only in x509
      1 package org.bouncycastle.asn1.x509;
      2 
      3 import org.bouncycastle.asn1.ASN1Integer;
      4 import org.bouncycastle.asn1.ASN1Object;
      5 import org.bouncycastle.asn1.ASN1Primitive;
      6 import org.bouncycastle.asn1.ASN1Sequence;
      7 import org.bouncycastle.asn1.ASN1TaggedObject;
      8 import org.bouncycastle.asn1.DERBitString;
      9 import org.bouncycastle.asn1.x500.X500Name;
     10 
     11 /**
     12  * an X509Certificate structure.
     13  * <pre>
     14  *  Certificate ::= SEQUENCE {
     15  *      tbsCertificate          TBSCertificate,
     16  *      signatureAlgorithm      AlgorithmIdentifier,
     17  *      signature               BIT STRING
     18  *  }
     19  * </pre>
     20  */
     21 public class Certificate
     22     extends ASN1Object
     23 {
     24     ASN1Sequence  seq;
     25     TBSCertificate tbsCert;
     26     AlgorithmIdentifier     sigAlgId;
     27     DERBitString            sig;
     28 
     29     public static Certificate getInstance(
     30         ASN1TaggedObject obj,
     31         boolean          explicit)
     32     {
     33         return getInstance(ASN1Sequence.getInstance(obj, explicit));
     34     }
     35 
     36     public static Certificate getInstance(
     37         Object  obj)
     38     {
     39         if (obj instanceof Certificate)
     40         {
     41             return (Certificate)obj;
     42         }
     43         else if (obj != null)
     44         {
     45             return new Certificate(ASN1Sequence.getInstance(obj));
     46         }
     47 
     48         return null;
     49     }
     50 
     51     private Certificate(
     52         ASN1Sequence seq)
     53     {
     54         this.seq = seq;
     55 
     56         //
     57         // correct x509 certficate
     58         //
     59         if (seq.size() == 3)
     60         {
     61             tbsCert = TBSCertificate.getInstance(seq.getObjectAt(0));
     62             sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
     63 
     64             sig = DERBitString.getInstance(seq.getObjectAt(2));
     65         }
     66         else
     67         {
     68             throw new IllegalArgumentException("sequence wrong size for a certificate");
     69         }
     70     }
     71 
     72     public TBSCertificate getTBSCertificate()
     73     {
     74         return tbsCert;
     75     }
     76 
     77     public ASN1Integer getVersion()
     78     {
     79         return tbsCert.getVersion();
     80     }
     81 
     82     public int getVersionNumber()
     83     {
     84         return tbsCert.getVersionNumber();
     85     }
     86 
     87     public ASN1Integer getSerialNumber()
     88     {
     89         return tbsCert.getSerialNumber();
     90     }
     91 
     92     public X500Name getIssuer()
     93     {
     94         return tbsCert.getIssuer();
     95     }
     96 
     97     public Time getStartDate()
     98     {
     99         return tbsCert.getStartDate();
    100     }
    101 
    102     public Time getEndDate()
    103     {
    104         return tbsCert.getEndDate();
    105     }
    106 
    107     public X500Name getSubject()
    108     {
    109         return tbsCert.getSubject();
    110     }
    111 
    112     public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
    113     {
    114         return tbsCert.getSubjectPublicKeyInfo();
    115     }
    116 
    117     public AlgorithmIdentifier getSignatureAlgorithm()
    118     {
    119         return sigAlgId;
    120     }
    121 
    122     public DERBitString getSignature()
    123     {
    124         return sig;
    125     }
    126 
    127     public ASN1Primitive toASN1Primitive()
    128     {
    129         return seq;
    130     }
    131 }
    132