TBSCertList.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.  * PKIX RFC-2459
  6.  *
  7.  * <pre>
  8.  * TBSCertList  ::=  SEQUENCE  {
  9.  *      version                 Version OPTIONAL,
  10.  *                                   -- if present, shall be v2
  11.  *      signature               AlgorithmIdentifier,
  12.  *      issuer                  Name,
  13.  *      thisUpdate              Time,
  14.  *      nextUpdate              Time OPTIONAL,
  15.  *      revokedCertificates     SEQUENCE OF SEQUENCE  {
  16.  *           userCertificate         CertificateSerialNumber,
  17.  *           revocationDate          Time,
  18.  *           crlEntryExtensions      Extensions OPTIONAL
  19.  *                                         -- if present, shall be v2
  20.  *                                }  OPTIONAL,
  21.  *      crlExtensions           [0]  EXPLICIT Extensions OPTIONAL
  22.  *                                         -- if present, shall be v2
  23.  *                                }
  24.  * </pre>
  25.  */
  26. public class TBSCertList
  27.     implements DEREncodable
  28. {
  29.     public class CRLEntry
  30.         implements DEREncodable
  31.     {
  32.         ASN1Sequence  seq;
  33.         DERInteger          userCertificate;
  34.         Time                revocationDate;
  35.         X509Extensions      crlEntryExtensions;
  36.         public CRLEntry(
  37.             ASN1Sequence  seq)
  38.         {
  39.             this.seq = seq;
  40.             userCertificate = (DERInteger)seq.getObjectAt(0);
  41.             revocationDate = Time.getInstance(seq.getObjectAt(1));
  42.             if (seq.size() == 3)
  43.             {
  44.                 crlEntryExtensions = X509Extensions.getInstance(seq.getObjectAt(2));
  45.             }
  46.         }
  47.         public DERInteger getUserCertificate()
  48.         {
  49.             return userCertificate;
  50.         }
  51.         public Time getRevocationDate()
  52.         {
  53.             return revocationDate;
  54.         }
  55.         public X509Extensions getExtensions()
  56.         {
  57.             return crlEntryExtensions;
  58.         }
  59.         public DERObject getDERObject()
  60.         {
  61.             return seq;
  62.         }
  63.     }
  64.     ASN1Sequence     seq;
  65.     DERInteger              version;
  66.     AlgorithmIdentifier     signature;
  67.     X509Name                issuer;
  68.     Time                    thisUpdate;
  69.     Time                    nextUpdate;
  70.     CRLEntry[]              revokedCertificates;
  71.     X509Extensions          crlExtensions;
  72.     public static TBSCertList getInstance(
  73.         ASN1TaggedObject obj,
  74.         boolean          explicit)
  75.     {
  76.         return getInstance(ASN1Sequence.getInstance(obj, explicit));
  77.     }
  78.     public static TBSCertList getInstance(
  79.         Object  obj)
  80.     {
  81.         if (obj instanceof TBSCertList)
  82.         {
  83.             return (TBSCertList)obj;
  84.         }
  85.         else if (obj instanceof ASN1Sequence)
  86.         {
  87.             return new TBSCertList((ASN1Sequence)obj);
  88.         }
  89.         throw new IllegalArgumentException("unknown object in factory");
  90.     }
  91.     public TBSCertList(
  92.         ASN1Sequence  seq)
  93.     {
  94.         int seqPos = 0;
  95.         this.seq = seq;
  96.         if (seq.getObjectAt(seqPos) instanceof DERInteger)
  97.         {
  98.             version = (DERInteger)seq.getObjectAt(seqPos++);
  99.         }
  100.         else
  101.         {
  102.             version = new DERInteger(0);
  103.         }
  104.         signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(seqPos++));
  105.         issuer = X509Name.getInstance(seq.getObjectAt(seqPos++));
  106.         thisUpdate = Time.getInstance(seq.getObjectAt(seqPos++));
  107.         if (seqPos < seq.size()
  108.             && (seq.getObjectAt(seqPos) instanceof DERUTCTime
  109.                || seq.getObjectAt(seqPos) instanceof DERGeneralizedTime
  110.                || seq.getObjectAt(seqPos) instanceof Time))
  111.         {
  112.             nextUpdate = Time.getInstance(seq.getObjectAt(seqPos++));
  113.         }
  114.         if (seqPos < seq.size()
  115.             && !(seq.getObjectAt(seqPos) instanceof DERTaggedObject))
  116.         {
  117.             ASN1Sequence certs = (ASN1Sequence)seq.getObjectAt(seqPos++);
  118.             revokedCertificates = new CRLEntry[certs.size()];
  119.             for ( int i = 0; i < revokedCertificates.length; i++)
  120.             {
  121.                 revokedCertificates[i] = new CRLEntry((ASN1Sequence)certs.getObjectAt(i));
  122.             }
  123.         }
  124.         if (seqPos < seq.size()
  125.             && seq.getObjectAt(seqPos) instanceof DERTaggedObject)
  126.         {
  127.             crlExtensions = X509Extensions.getInstance(seq.getObjectAt(seqPos++));
  128.         }
  129.     }
  130.     public int getVersion()
  131.     {
  132.         return version.getValue().intValue() + 1;
  133.     }
  134.     public DERInteger getVersionNumber()
  135.     {
  136.         return version;
  137.     }
  138.     public AlgorithmIdentifier getSignature()
  139.     {
  140.         return signature;
  141.     }
  142.     public X509Name getIssuer()
  143.     {
  144.         return issuer;
  145.     }
  146.     public Time getThisUpdate()
  147.     {
  148.         return thisUpdate;
  149.     }
  150.     public Time getNextUpdate()
  151.     {
  152.         return nextUpdate;
  153.     }
  154.     public CRLEntry[] getRevokedCertificates()
  155.     {
  156.         return revokedCertificates;
  157.     }
  158.     public X509Extensions getExtensions()
  159.     {
  160.         return crlExtensions;
  161.     }
  162.     public DERObject getDERObject()
  163.     {
  164.         return seq;
  165.     }
  166. }