TBSCertificateStructure.java
上传用户:lior1029
上传日期:2013-05-07
资源大小:209k
文件大小:5k
源码类别:

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.x509;
  2. import org.bouncycastle.asn1.*;
  3. import org.bouncycastle.asn1.pkcs.*;
  4. /**
  5.  * <pre>
  6.  * TBSCertificate ::= SEQUENCE {
  7.  *      version          [ 0 ]  Version DEFAULT v1(0),
  8.  *      serialNumber            CertificateSerialNumber,
  9.  *      signature               AlgorithmIdentifier,
  10.  *      issuer                  Name,
  11.  *      validity                Validity,
  12.  *      subject                 Name,
  13.  *      subjectPublicKeyInfo    SubjectPublicKeyInfo,
  14.  *      issuerUniqueID    [ 1 ] IMPLICIT UniqueIdentifier OPTIONAL,
  15.  *      subjectUniqueID   [ 2 ] IMPLICIT UniqueIdentifier OPTIONAL,
  16.  *      extensions        [ 3 ] Extensions OPTIONAL
  17.  *      }
  18.  * </pre>
  19.  * <p>
  20.  * Note: issuerUniqueID and subjectUniqueID are both deprecated by the IETF. This class
  21.  * will parse them, but you really shouldn't be creating new ones.
  22.  */
  23. public class TBSCertificateStructure
  24.     implements DEREncodable, X509ObjectIdentifiers, PKCSObjectIdentifiers
  25. {
  26.     ASN1Sequence            seq;
  27.     DERInteger              version;
  28.     DERInteger              serialNumber;
  29.     AlgorithmIdentifier     signature;
  30.     X509Name                issuer;
  31.     Time                    startDate, endDate;
  32.     X509Name                subject;
  33.     SubjectPublicKeyInfo    subjectPublicKeyInfo;
  34.     DERBitString            issuerUniqueId;
  35.     DERBitString            subjectUniqueId;
  36.     X509Extensions          extensions;
  37.     public static TBSCertificateStructure getInstance(
  38.         ASN1TaggedObject obj,
  39.         boolean          explicit)
  40.     {
  41.         return getInstance(ASN1Sequence.getInstance(obj, explicit));
  42.     }
  43.     public static TBSCertificateStructure getInstance(
  44.         Object  obj)
  45.     {
  46.         if (obj instanceof TBSCertificateStructure)
  47.         {
  48.             return (TBSCertificateStructure)obj;
  49.         }
  50.         else if (obj instanceof ASN1Sequence)
  51.         {
  52.             return new TBSCertificateStructure((ASN1Sequence)obj);
  53.         }
  54.         throw new IllegalArgumentException("unknown object in factory");
  55.     }
  56.     public TBSCertificateStructure(
  57.         ASN1Sequence  seq)
  58.     {
  59.         int         seqStart = 0;
  60.         this.seq = seq;
  61.         //
  62.         // some certficates don't include a version number - we assume v1
  63.         //
  64.         if (seq.getObjectAt(0) instanceof DERTaggedObject)
  65.         {
  66.             version = DERInteger.getInstance(seq.getObjectAt(0));
  67.         }
  68.         else
  69.         {
  70.             seqStart = -1;          // field 0 is missing!
  71.             version = new DERInteger(0);
  72.         }
  73.         serialNumber = DERInteger.getInstance(seq.getObjectAt(seqStart + 1));
  74.         signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(seqStart + 2));
  75.         issuer = X509Name.getInstance(seq.getObjectAt(seqStart + 3));
  76.         //
  77.         // before and after dates
  78.         //
  79.         ASN1Sequence  dates = (ASN1Sequence)seq.getObjectAt(seqStart + 4);
  80.         startDate = Time.getInstance(dates.getObjectAt(0));
  81.         endDate = Time.getInstance(dates.getObjectAt(1));
  82.         subject = X509Name.getInstance(seq.getObjectAt(seqStart + 5));
  83.         //
  84.         // public key info.
  85.         //
  86.         subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(seqStart + 6));
  87.         for (int extras = seq.size() - (seqStart + 6) - 1; extras > 0; extras--)
  88.         {
  89.             DERTaggedObject extra = (DERTaggedObject)seq.getObjectAt(seqStart + 6 + extras);
  90.             switch (extra.getTagNo())
  91.             {
  92.             case 1:
  93.                 issuerUniqueId = DERBitString.getInstance(extra);
  94.                 break;
  95.             case 2:
  96.                 subjectUniqueId = DERBitString.getInstance(extra);
  97.                 break;
  98.             case 3:
  99.                 extensions = X509Extensions.getInstance(extra);
  100.             }
  101.         }
  102.     }
  103.     public int getVersion()
  104.     {
  105.         return version.getValue().intValue() + 1;
  106.     }
  107.     public DERInteger getVersionNumber()
  108.     {
  109.         return version;
  110.     }
  111.     public DERInteger getSerialNumber()
  112.     {
  113.         return serialNumber;
  114.     }
  115.     public AlgorithmIdentifier getSignature()
  116.     {
  117.         return signature;
  118.     }
  119.     public X509Name getIssuer()
  120.     {
  121.         return issuer;
  122.     }
  123.     public Time getStartDate()
  124.     {
  125.         return startDate;
  126.     }
  127.     public Time getEndDate()
  128.     {
  129.         return endDate;
  130.     }
  131.     public X509Name getSubject()
  132.     {
  133.         return subject;
  134.     }
  135.     public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
  136.     {
  137.         return subjectPublicKeyInfo;
  138.     }
  139.     public DERBitString getIssuerUniqueId()
  140.     {
  141.         return issuerUniqueId;
  142.     }
  143.     public DERBitString getSubjectUniqueId()
  144.     {
  145.         return subjectUniqueId;
  146.     }
  147.     public X509Extensions getExtensions()
  148.     {
  149.         return extensions;
  150.     }
  151.     public DERObject getDERObject()
  152.     {
  153.         return seq;
  154.     }
  155. }