Package org.apache.commons.ssl.asn1

Examples of org.apache.commons.ssl.asn1.ASN1Set


  }
  if (value == null) {
      value = new ASN1Null();
  }
  type_ = oid;
  values_ = new ASN1Set(1);

  values_.add(value);

  add(oid);
  add(values_);
View Full Code Here


  type_ = value.getOID();

  if (type_ == null) {
      throw new NullPointerException("Value does not provide an OID!");
  }
  values_ = new ASN1Set(1);
  values_.add(value);

  add(type_);
  add(values_);
    }
View Full Code Here

  add(algorithm_);

  encodedKey_ = new ASN1OctetString(key);
  add(encodedKey_);

  attributes_ = new ASN1Set();
  add(new ASN1TaggedType(0, attributes_, false, true));
    }
View Full Code Here

      throw new InconsistentStateException("Caught ASN1Exception!");
  }
  encodedKey_ = new ASN1OctetString(code);
  add(encodedKey_);

  attributes_ = new ASN1Set();
  add(new ASN1TaggedType(0, attributes_, false, true));
    }
View Full Code Here

  ASN1ObjectIdentifier oid;
  RFC2253Parser p;
  ASN1Sequence seq;
  Iterator i;
  ASN1Set set;
  String key;
  String val;
  AVA entry;

  initMaps();

  if (encType == -1) {
      if (!allowDefaultEncoding_) {
    throw new BadNameException(
      "Use the other constructor with the explicit "
        + "encoding parameter!");
      }
      currentEncoding_ = defaultEncoding_;
  } else {
      if (encType != UTF8_ENCODING && encType != T61_ENCODING
        && encType != PRINTABLE_ENCODING && encType != IA5_ENCODING) {
    throw new BadNameException("Unknown EncodingType: " + encType);
      }
      currentEncoding_ = encType;
  }

  p = new RFC2253Parser();
  set = new ASN1Set(1);

  for (i = p.parse(rfc2253String).iterator(); i.hasNext();) {
      entry = (AVA) i.next();
      key = entry.getKey();
      key = key.toUpperCase();
      oid = (ASN1ObjectIdentifier) a2oid_.get(key);
      seq = new ASN1Sequence(2);

      if (oid == null) {
    try {
        oid = new ASN1ObjectIdentifier(key);
    } catch (Exception e) {
        throw new BadNameException("Unsupported attribute key: \""
          + key + "\"");
    }
      }
      seq.add(oid.clone());

      if (entry.isEncodedValue()) {
    ByteArrayInputStream in;
    BERDecoder dec;
    ASN1Type obj;
    byte[] buf;

    try {
        buf = entry.getEncodedValue();
        in = new ByteArrayInputStream(buf);
        dec = new BERDecoder(in);
        obj = dec.readType();

        dec.close();
    } catch (Exception e) {
        throw new BadNameException(
          "Binary data is not a valid BER encoding!");
    }
    seq.add(obj);
      } else {
    val = entry.getValue();

    /*
     * This is a workaround for email addresses which contain the
     * '@' symbol. This symbol is not in the character set of the
     * ASN.1 PrintableString. Hence, we have to take a IA5String
     * instead.
     */
    if (entry.getKey().equalsIgnoreCase("EMAILADDRESS")
      || entry.getKey().equalsIgnoreCase("UID")) {
        seq.add(new ASN1IA5String(val));
    } else if (entry.getKey().equalsIgnoreCase("C")
      || entry.getKey().equalsIgnoreCase("SERIALNUMBER")) {
        seq.add(new ASN1PrintableString(val));
    } else {
        switch (currentEncoding_) {
        case (ASN1.TAG_UTF8STRING):
      seq.add(new ASN1UTF8String(val));
      break;
        case (ASN1.TAG_IA5STRING):
      seq.add(new ASN1IA5String(val));
      break;
        case (ASN1.TAG_PRINTABLESTRING):
      if (checkPrintableSpelling(val)) {
          seq.add(new ASN1PrintableString(val));
      } else {
          throw new BadNameException(
            "Illegal characters for PrintableString "
              + "in characters");
      }
      break;
        case (ASN1.TAG_T61STRING):
      seq.add(new ASN1T61String(val));
      break;
        }
    }
      }
      set.add(seq);

      if (entry.hasSibling()) {
    continue;
      }
      set.trimToSize();

      super.add(0, set);
      set = new ASN1Set(1);
  }
  trimToSize();
    }
View Full Code Here

  ASN1Sequence ava;
  ArrayList list;
  ASN1Type obj;
  Iterator i;
  boolean sibling;
  ASN1Set rdn;
  String val;
  String key;
  AVA entry;
  int j;
  int n;

  list = new ArrayList(size());

  for (i = iterator(); i.hasNext();) {
      rdn = (ASN1Set) i.next();
      n = rdn.size();

      for (j = 0; j < n; j++) {
    /*
     * We have to mark siblings. An AVA has a sibling if it is not
     * the last AVA in the set.
     */
    sibling = (j < n - 1);

    /*
     * Convert key and value into strings. These values are then put
     * into an AVA instance.
     */
    ava = (ASN1Sequence) rdn.get(j);
    oid = (ASN1ObjectIdentifier) ava.get(0);
    obj = (ASN1Type) ava.get(1);
    key = (String) oid2a_.get(oid);

    if (key == null) {
View Full Code Here

  ASN1ObjectIdentifier oid;
  ASN1Sequence ava;
  ArrayList list;
  ASN1Type obj;
  boolean sibling;
  ASN1Set rdn;
  String val;
  String key;
  AVA entry;
  int i;
  int j;
  int n;

  list = new ArrayList(size());

  for (i = size() - 1; i >= 0; i--) {
      rdn = (ASN1Set) get(i);
      n = rdn.size();

      for (j = 0; j < n; j++) {
    /*
     * We have to mark siblings. An AVA has a sibling if it is not
     * the last AVA in the set.
     */
    sibling = (j < n - 1);

    /*
     * Convert key and value into strings. These values are then put
     * into an AVA instance.
     */
    ava = (ASN1Sequence) rdn.get(j);
    oid = (ASN1ObjectIdentifier) ava.get(0);
    obj = (ASN1Type) ava.get(1);
    key = (String) oid2a_.get(oid);

    if (key == null) {
View Full Code Here

     */
    public boolean add(ASN1Set o) {
  ASN1Sequence seq;
  Iterator it;
  // Iterator j;
  ASN1Set set;
  Object p;

  if (o == null) {
      throw new NullPointerException("parameter is null");
  }
  set = o;

  for (it = set.iterator(); it.hasNext();) {
      p = it.next();

      if (!(p instanceof ASN1Sequence)) {
    throw new IllegalArgumentException("not a sequence: "
      + p.getClass().getName());
View Full Code Here

  if (isOptional()) {
      super.encode(enc);
      return;
  }
  if (cache_ == null) {
      cache_ = new ASN1Set(size());
  }
  /*
   * Copy all relevant parameters into the cache instance, e.g. whether we
   * are tagged EXPLICT, are OPTIONAL etc.
   */
 
View Full Code Here

            PrivateKey key = (PrivateKey) ks.getKey(alias, password);
            Certificate[] chain = ks.getCertificateChain(alias);
            byte[] pkcs8DerBytes = null;
            if (key instanceof RSAPrivateCrtKey) {
                RSAPrivateCrtKey rsa = (RSAPrivateCrtKey) key;
                ASN1EncodableVector vec = new ASN1EncodableVector();
                vec.add(new DERInteger(BigInteger.ZERO));
                vec.add(new DERInteger(rsa.getModulus()));
                vec.add(new DERInteger(rsa.getPublicExponent()));
                vec.add(new DERInteger(rsa.getPrivateExponent()));
                vec.add(new DERInteger(rsa.getPrimeP()));
                vec.add(new DERInteger(rsa.getPrimeQ()));
                vec.add(new DERInteger(rsa.getPrimeExponentP()));
                vec.add(new DERInteger(rsa.getPrimeExponentQ()));
                vec.add(new DERInteger(rsa.getCrtCoefficient()));
                DERSequence seq = new DERSequence(vec);
                byte[] derBytes = PKCS8Key.encode(seq);
                PKCS8Key pkcs8 = new PKCS8Key(derBytes, null);
                pkcs8DerBytes = pkcs8.getDecryptedBytes();
            } else if (key instanceof DSAPrivateKey) {
                DSAPrivateKey dsa = (DSAPrivateKey) key;
                DSAParams params = dsa.getParams();
                BigInteger g = params.getG();
                BigInteger p = params.getP();
                BigInteger q = params.getQ();
                BigInteger x = dsa.getX();
                BigInteger y = q.modPow(x, p);

                ASN1EncodableVector vec = new ASN1EncodableVector();
                vec.add(new DERInteger(BigInteger.ZERO));
                vec.add(new DERInteger(p));
                vec.add(new DERInteger(q));
                vec.add(new DERInteger(g));
                vec.add(new DERInteger(y));
                vec.add(new DERInteger(x));
                DERSequence seq = new DERSequence(vec);
                byte[] derBytes = PKCS8Key.encode(seq);
                PKCS8Key pkcs8 = new PKCS8Key(derBytes, null);
                pkcs8DerBytes = pkcs8.getDecryptedBytes();
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.ssl.asn1.ASN1Set

Copyright © 2018 www.massapicom. 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.