Examples of BEREncodingException


Examples of gnu.java.security.ber.BEREncodingException

  {
    DERValue val = ber.read();
    if (Configuration.DEBUG)
      log.fine("SignerInfo: " + val);
    if (!val.isConstructed())
      throw new BEREncodingException("malformed SignerInfo");

    val = ber.read();
    if (val.getTag() != BER.INTEGER)
      throw new BEREncodingException("malformed Version");

    version = (BigInteger) val.getValue();
    if (Configuration.DEBUG)
      log.fine("  Version: " + version);

    val = ber.read();
    if (!val.isConstructed())
      throw new BEREncodingException("malformed IssuerAndSerialNumber");
    if (Configuration.DEBUG)
      log.fine("  IssuerAndSerialNumber: " + val);

    val = ber.read();
    if (!val.isConstructed())
      throw new BEREncodingException("malformed Issuer");

    issuer = new X500Principal(val.getEncoded());
    ber.skip(val.getLength());
    if (Configuration.DEBUG)
      log.fine("    Issuer: " + issuer);

    val = ber.read();
    if (val.getTag() != BER.INTEGER)
      throw new BEREncodingException("malformed SerialNumber");

    serialNumber = (BigInteger) val.getValue();
    if (Configuration.DEBUG)
      log.fine("    SerialNumber: " + serialNumber);

    val = ber.read();
    if (!val.isConstructed())
      throw new BEREncodingException("malformed DigestAlgorithmIdentifier");
    if (Configuration.DEBUG)
      log.fine("  DigestAlgorithmIdentifier: " + val);

    int count = 0;
    DERValue val2 = ber.read();
    if (val2.getTag() != BER.OBJECT_IDENTIFIER)
      throw new BEREncodingException("malformed AlgorithmIdentifier");

    digestAlgorithmId = (OID) val2.getValue();
    if (Configuration.DEBUG)
      log.fine("    digestAlgorithm OID: " + digestAlgorithmId);

    if (BERValue.isIndefinite(val))
      {
        val2 = ber.read();
        if (val2 != BER.END_OF_SEQUENCE)
          {
            digestAlgorithmParams = val2.getEncoded();
            val2 = ber.read();
            if (val2 != BER.END_OF_SEQUENCE)
              throw new BEREncodingException("expecting BER end-of-sequence");
          }
        else
          digestAlgorithmParams = null;
      }
    else if (val2.getEncodedLength() < val.getLength())
      {
        val2 = ber.read();
        digestAlgorithmParams = val2.getEncoded();
        if (val2.isConstructed())
          ber.skip(val2.getLength());
      }
    else
      digestAlgorithmParams = null;

    if (Configuration.DEBUG)
      {
        log.fine("    digestAlgorithm params: ");
        log.fine(Util.dumpString(digestAlgorithmParams,
                                 "    digestAlgorithm params: "));
      }
    val = ber.read();
    if (val.getTag() == 0)
      {
        authenticatedAttributes = val.getEncoded();
        val = ber.read();
        if (val.isConstructed())
          ber.skip(val.getLength());

        val = ber.read();
      }
    else
      authenticatedAttributes = null;

    if (Configuration.DEBUG)
      {
        log.fine("  AuthenticatedAttributes: ");
        log.fine(Util.dumpString(authenticatedAttributes,
                                 "  AuthenticatedAttributes: "));
      }
    if (!val.isConstructed())
      throw new BEREncodingException("malformed DigestEncryptionAlgorithmIdentifier");
    if (Configuration.DEBUG)
      log.fine("  DigestEncryptionAlgorithmIdentifier: " + val);
    count = 0;
    val2 = ber.read();
    if (val2.getTag() != BER.OBJECT_IDENTIFIER)
      throw new BEREncodingException("malformed AlgorithmIdentifier");

    digestEncryptionAlgorithmId = (OID) val2.getValue();
    if (Configuration.DEBUG)
      log.fine("    digestEncryptionAlgorithm OID: " + digestEncryptionAlgorithmId);

    if (BERValue.isIndefinite(val))
      {
        val2 = ber.read();
        if (val2 != BER.END_OF_SEQUENCE)
          {
            digestEncryptionAlgorithmParams = val2.getEncoded();
            val2 = ber.read();
            if (val2 != BER.END_OF_SEQUENCE)
              throw new BEREncodingException("expecting BER end-of-sequence");
          }
        else
          digestEncryptionAlgorithmParams = null;
      }
    else if (val2.getEncodedLength() < val.getLength())
      {
        val2 = ber.read();
        digestEncryptionAlgorithmParams = val2.getEncoded();
        if (val2.isConstructed())
          ber.skip(val2.getLength());
      }
    else
      digestEncryptionAlgorithmParams = null;

    if (Configuration.DEBUG)
      {
        log.fine("    digestEncryptionAlgorithm params: ");
        log.fine(Util.dumpString(digestEncryptionAlgorithmParams,
                                 "    digestEncryptionAlgorithm params: "));
      }
    val = ber.read();
    if (val.getTag() != BER.OCTET_STRING)
      throw new BEREncodingException("malformed EncryptedDigest");

    encryptedDigest = (byte[]) val.getValue();
    if (Configuration.DEBUG)
      {
        log.fine("  EncryptedDigest: ");
View Full Code Here

Examples of gnu.java.security.ber.BEREncodingException

    throws CRLException, CertificateException, IOException
  {
    CertificateFactory x509 = CertificateFactory.getInstance("X509");
    DERValue val = ber.read();
    if (!val.isConstructed())
      throw new BEREncodingException("malformed ContentInfo");

    val = ber.read();
    if (val.getTag() != BER.OBJECT_IDENTIFIER)
      throw new BEREncodingException("malformed ContentType");

    if (!PKCS7_SIGNED_DATA.equals(val.getValue()))
      throw new BEREncodingException("content is not SignedData");

    val = ber.read();
    if (val.getTag() != 0)
      throw new BEREncodingException("malformed Content");

    val = ber.read();
    if (!val.isConstructed())
      throw new BEREncodingException("malformed SignedData");

    if (Configuration.DEBUG)
      log.fine("SignedData: " + val);

    val = ber.read();
    if (val.getTag() != BER.INTEGER)
      throw new BEREncodingException("expecting Version");
    version = (BigInteger) val.getValue();
    if (Configuration.DEBUG)
      log.fine("  Version: " + version);

    digestAlgorithms = new HashSet();
    val = ber.read();
    if (!val.isConstructed())
      throw new BEREncodingException("malformed DigestAlgorithmIdentifiers");
    if (Configuration.DEBUG)
      log.fine("  DigestAlgorithmIdentifiers: " + val);
    int count = 0;
    DERValue val2 = ber.read();
    while (val2 != BER.END_OF_SEQUENCE &&
           (val.getLength() > 0 && val.getLength() > count))
      {
        if (!val2.isConstructed())
          throw new BEREncodingException("malformed AlgorithmIdentifier");
        if (Configuration.DEBUG)
          log.fine("    AlgorithmIdentifier: " + val2);
        count += val2.getEncodedLength();
        val2 = ber.read();
        if (val2.getTag() != BER.OBJECT_IDENTIFIER)
          throw new BEREncodingException("malformed AlgorithmIdentifier");
        if (Configuration.DEBUG)
          log.fine("      digestAlgorithmIdentifiers OID: " + val2.getValue());
        List algId = new ArrayList(2);
        algId.add(val2.getValue());
        val2 = ber.read();
        if (val2 != BER.END_OF_SEQUENCE)
          {
            count += val2.getEncodedLength();
            if (val2.getTag() == BER.NULL)
              algId.add(null);
            else
              algId.add(val2.getEncoded());

            if (val2.isConstructed())
              ber.skip(val2.getLength());

            if (BERValue.isIndefinite(val))
              val2 = ber.read();
          }
        else
          algId.add(null);

        if (Configuration.DEBUG)
          {
            log.fine("      digestAlgorithmIdentifiers params: ");
            log.fine(Util.dumpString((byte[]) algId.get(1),
                                     "      digestAlgorithmIdentifiers params: "));
          }
        digestAlgorithms.add(algId);
      }

    val = ber.read();
    if (!val.isConstructed())
      throw new BEREncodingException("malformed ContentInfo");
    if (Configuration.DEBUG)
      log.fine("  ContentInfo: " + val);
    val2 = ber.read();
    if (val2.getTag() != BER.OBJECT_IDENTIFIER)
      throw new BEREncodingException("malformed ContentType");

    contentType = (OID) val2.getValue();
    if (Configuration.DEBUG)
      log.fine("    ContentType OID: " + contentType);
    if (BERValue.isIndefinite(val)
        || (val.getLength() > 0 && val.getLength() > val2.getEncodedLength()))
      {
        val2 = ber.read();
        if (val2 != BER.END_OF_SEQUENCE)
          {
            content = val2.getEncoded();
            if (BERValue.isIndefinite(val))
              val2 = ber.read();
          }
      }
    if (Configuration.DEBUG)
      {
        log.fine("    Content: ");
        log.fine(Util.dumpString(content, "    Content: "));
      }
    val = ber.read();
    if (val.getTag() == 0)
      {
        if (!val.isConstructed())
          throw new BEREncodingException("malformed ExtendedCertificatesAndCertificates");
        if (Configuration.DEBUG)
          log.fine("  ExtendedCertificatesAndCertificates: " + val);
        count = 0;
        val2 = ber.read();
        List certs = new LinkedList();
        while (val2 != BER.END_OF_SEQUENCE &&
               (val.getLength() > 0 && val.getLength() > count))
          {
            Certificate cert =
              x509.generateCertificate(new ByteArrayInputStream(val2.getEncoded()));
            if (Configuration.DEBUG)
              log.fine("    Certificate: " + cert);
            certs.add(cert);
            count += val2.getEncodedLength();
            ber.skip(val2.getLength());
            if (BERValue.isIndefinite(val) || val.getLength() > count)
              val2 = ber.read();
          }
        certificates = (Certificate[]) certs.toArray(new Certificate[certs.size()]);
        val = ber.read();
      }

    if (val.getTag() == 1)
      {
        if (!val.isConstructed())
          throw new BEREncodingException("malformed CertificateRevocationLists");
        if (Configuration.DEBUG)
          log.fine("  CertificateRevocationLists: " + val);
        count = 0;
        val2 = ber.read();
        List crls = new LinkedList();
        while (val2 != BER.END_OF_SEQUENCE &&
               (val.getLength() > 0 && val.getLength() > count))
          {
            CRL crl = x509.generateCRL(new ByteArrayInputStream(val2.getEncoded()));
            if (Configuration.DEBUG)
              log.fine("    CRL: " + crl);
            crls.add(crl);
            count += val2.getEncodedLength();
            ber.skip(val2.getLength());
            if (BERValue.isIndefinite(val) || val.getLength() > count)
              val2 = ber.read();
          }
        this.crls = (CRL[]) crls.toArray(new CRL[crls.size()]);
        val = ber.read();
      }

    signerInfos = new HashSet();
    if (!val.isConstructed())
      throw new BEREncodingException("malformed SignerInfos");
    if (Configuration.DEBUG)
      log.fine("  SignerInfos: " + val);

    // FIXME read this more carefully.
    // Since we are just reading a file (probably) we just read until we
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.