private AttributeCertificateInfo(ASN1Sequence seq) {
    if (seq.size() < 6 || seq.size() > 9) {
      throw new IllegalArgumentException("Bad sequence size: " + seq.size());
    }

    int start;
    if (seq.getObjectAt(0) instanceof ASN1Integer) // in version 1 certs version is DEFAULT  v1(0)
    {
      this.version = ASN1Integer.getInstance(seq.getObjectAt(0));
      start = 1;
    } else {
      this.version = new ASN1Integer(0);
      start = 0;
    }

    this.holder = Holder.getInstance(seq.getObjectAt(start));
    this.issuer = AttCertIssuer.getInstance(seq.getObjectAt(start + 1));
    this.signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(start + 2));
    this.serialNumber = ASN1Integer.getInstance(seq.getObjectAt(start + 3));
    this.attrCertValidityPeriod = AttCertValidityPeriod.getInstance(seq.getObjectAt(start + 4));
    this.attributes = ASN1Sequence.getInstance(seq.getObjectAt(start + 5));

    for (int i = start + 6; i < seq.size(); i++) {
      ASN1Encodable obj = seq.getObjectAt(i);

      if (obj instanceof DERBitString) {
        this.issuerUniqueID = DERBitString.getInstance(seq.getObjectAt(i));
      } else if (obj instanceof ASN1Sequence || obj instanceof Extensions) {
        this.extensions = Extensions.getInstance(seq.getObjectAt(i));
      }
    }
  }
예제 #2
0
 private CrlIdentifier(ASN1Sequence seq) {
   if (seq.size() < 2 || seq.size() > 3) {
     throw new IllegalArgumentException();
   }
   this.crlIssuer = X500Name.getInstance(seq.getObjectAt(0));
   this.crlIssuedTime = ASN1UTCTime.getInstance(seq.getObjectAt(1));
   if (seq.size() > 2) {
     this.crlNumber = ASN1Integer.getInstance(seq.getObjectAt(2));
   }
 }
예제 #3
0
    public PEMKeyPair parse(byte[] encoding) throws IOException {
      try {
        ASN1Sequence seq = ASN1Sequence.getInstance(encoding);

        if (seq.size() != 9) {
          throw new PEMException("malformed sequence in RSA private key");
        }

        org.mightyfish.asn1.pkcs.RSAPrivateKey keyStruct =
            org.mightyfish.asn1.pkcs.RSAPrivateKey.getInstance(seq);

        RSAPublicKey pubSpec =
            new RSAPublicKey(keyStruct.getModulus(), keyStruct.getPublicExponent());

        AlgorithmIdentifier algId =
            new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE);

        return new PEMKeyPair(
            new SubjectPublicKeyInfo(algId, pubSpec), new PrivateKeyInfo(algId, keyStruct));
      } catch (IOException e) {
        throw e;
      } catch (Exception e) {
        throw new PEMException("problem creating RSA private key: " + e.toString(), e);
      }
    }
예제 #4
0
    public PEMKeyPair parse(byte[] encoding) throws IOException {
      try {
        ASN1Sequence seq = ASN1Sequence.getInstance(encoding);

        if (seq.size() != 6) {
          throw new PEMException("malformed sequence in DSA private key");
        }

        //            ASN1Integer              v = (ASN1Integer)seq.getObjectAt(0);
        ASN1Integer p = ASN1Integer.getInstance(seq.getObjectAt(1));
        ASN1Integer q = ASN1Integer.getInstance(seq.getObjectAt(2));
        ASN1Integer g = ASN1Integer.getInstance(seq.getObjectAt(3));
        ASN1Integer y = ASN1Integer.getInstance(seq.getObjectAt(4));
        ASN1Integer x = ASN1Integer.getInstance(seq.getObjectAt(5));

        return new PEMKeyPair(
            new SubjectPublicKeyInfo(
                new AlgorithmIdentifier(
                    X9ObjectIdentifiers.id_dsa,
                    new DSAParameter(p.getValue(), q.getValue(), g.getValue())),
                y),
            new PrivateKeyInfo(
                new AlgorithmIdentifier(
                    X9ObjectIdentifiers.id_dsa,
                    new DSAParameter(p.getValue(), q.getValue(), g.getValue())),
                x));
      } catch (IOException e) {
        throw e;
      } catch (Exception e) {
        throw new PEMException("problem creating DSA private key: " + e.toString(), e);
      }
    }