public X509CertificateStructure(ASN1Sequence seq) {
    this.seq = seq;

    //
    // correct x509 certficate
    //
    if (seq.size() == 3) {
      tbsCert = TBSCertificateStructure.getInstance(seq.getObjectAt(0));
      sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));

      sig = (DERBitString) seq.getObjectAt(2);
    }
  }
Example #2
0
  /**
   * Constructor from ASN1Sequence.
   *
   * <p>the extensions are a list of constructed sequences, either with (OID, OctetString) or (OID,
   * Boolean, OctetString)
   */
  public X509Extensions(ASN1Sequence seq) {
    Enumeration e = seq.getObjects();

    while (e.hasMoreElements()) {
      ASN1Sequence s = (ASN1Sequence) e.nextElement();

      if (s.size() == 3) {
        extensions.put(
            s.getObjectAt(0),
            new X509Extension((DERBoolean) s.getObjectAt(1), (ASN1OctetString) s.getObjectAt(2)));
      } else {
        extensions.put(
            s.getObjectAt(0), new X509Extension(false, (ASN1OctetString) s.getObjectAt(1)));
      }

      ordering.addElement(s.getObjectAt(0));
    }
  }
  public TBSCertificateStructure(ASN1Sequence seq) {
    int seqStart = 0;

    this.seq = seq;

    //
    // some certficates don't include a version number - we assume v1
    //
    if (seq.getObjectAt(0) instanceof DERTaggedObject) {
      version = DERInteger.getInstance(seq.getObjectAt(0));
    } else {
      seqStart = -1; // field 0 is missing!
      version = new DERInteger(0);
    }

    serialNumber = DERInteger.getInstance(seq.getObjectAt(seqStart + 1));

    signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(seqStart + 2));
    issuer = X509Name.getInstance(seq.getObjectAt(seqStart + 3));

    //
    // before and after dates
    //
    ASN1Sequence dates = (ASN1Sequence) seq.getObjectAt(seqStart + 4);

    startDate = Time.getInstance(dates.getObjectAt(0));
    endDate = Time.getInstance(dates.getObjectAt(1));

    subject = X509Name.getInstance(seq.getObjectAt(seqStart + 5));

    //
    // public key info.
    //
    subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(seqStart + 6));

    for (int extras = seq.size() - (seqStart + 6) - 1; extras > 0; extras--) {
      DERTaggedObject extra = (DERTaggedObject) seq.getObjectAt(seqStart + 6 + extras);

      switch (extra.getTagNo()) {
        case 1:
          issuerUniqueId = DERBitString.getInstance(extra);
          break;
        case 2:
          subjectUniqueId = DERBitString.getInstance(extra);
          break;
        case 3:
          extensions = X509Extensions.getInstance(extra);
      }
    }
  }