Example #1
0
  private List<DEREncodable> listPolicies(X509Certificate eec) throws AuthenticationException {
    byte[] encoded;
    try {
      encoded = getExtensionBytes(eec, OID_CERTIFICATE_POLICIES);
    } catch (IOException e) {
      LOG.warn(
          "Malformed policy extension {}: {}",
          eec.getIssuerX500Principal().getName(),
          e.getMessage());
      return Collections.emptyList();
    }

    if (encoded == null) { // has no Certificate Policies extension.
      return Collections.emptyList();
    }

    Enumeration<DEREncodable> policySource = ASN1Sequence.getInstance(encoded).getObjects();
    List<DEREncodable> policies = new ArrayList();
    while (policySource.hasMoreElements()) {
      DEREncodable policy = policySource.nextElement();
      if (!policy.equals(ANY_POLICY)) {
        policies.add(policy);
      }
    }
    return policies;
  }
Example #2
0
  /**
   * Constructor from ASN1Sequence
   *
   * <p>the principal will be a list of constructed sets, each containing an (OID, String) pair.
   */
  public X509Name(ASN1Sequence seq) {
    this.seq = seq;

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements()) {
      ASN1Set set = ASN1Set.getInstance(e.nextElement());

      for (int i = 0; i < set.size(); i++) {
        ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i));

        if (s.size() != 2) {
          throw new IllegalArgumentException("badly sized pair");
        }

        ordering.addElement(DERObjectIdentifier.getInstance(s.getObjectAt(0)));

        DEREncodable value = s.getObjectAt(1);
        if (value instanceof DERString) {
          values.addElement(((DERString) value).getString());
        } else {
          values.addElement("#" + bytesToString(Hex.encode(value.getDERObject().getDEREncoded())));
        }
        added.addElement((i != 0) ? TRUE : FALSE); // to allow earlier JDK compatibility
      }
    }
  }
  /**
   * return the ASN.1 encoded key derivation algorithm parameters, or null if there aren't any.
   *
   * @return ASN.1 encoding of key derivation algorithm parameters.
   */
  public byte[] getKeyDerivationAlgParams() {
    try {
      if (info.getKeyDerivationAlgorithm() != null) {
        DEREncodable params = info.getKeyDerivationAlgorithm().getParameters();
        if (params != null) {
          return params.getDERObject().getEncoded();
        }
      }

      return null;
    } catch (Exception e) {
      throw new RuntimeException("exception getting encryption parameters " + e);
    }
  }
  private byte[] encodeObj(DEREncodable obj) throws IOException {
    if (obj != null) {
      return obj.getDERObject().getEncoded();
    }

    return null;
  }
  /**
   * return an AlgorithmParameters object representing the parameters to the key derivation
   * algorithm to the recipient.
   *
   * @return AlgorithmParameters object, null if there aren't any.
   */
  public AlgorithmParameters getKeyDerivationAlgParameters(Provider provider) {
    try {
      if (info.getKeyDerivationAlgorithm() != null) {
        DEREncodable params = info.getKeyDerivationAlgorithm().getParameters();
        if (params != null) {
          AlgorithmParameters algP =
              AlgorithmParameters.getInstance(
                  info.getKeyDerivationAlgorithm().getObjectId().toString(), provider);

          algP.init(params.getDERObject().getEncoded());

          return algP;
        }
      }

      return null;
    } catch (Exception e) {
      throw new RuntimeException("exception getting encryption parameters " + e);
    }
  }