Ejemplo n.º 1
0
  public KeySelectorResult select(
      KeyInfo keyInfo,
      KeySelector.Purpose purpose,
      AlgorithmMethod method,
      XMLCryptoContext context)
      throws KeySelectorException {

    if (keyInfo == null) {
      throw new KeySelectorException("Null KeyInfo object!");
    }
    SignatureMethod sm = (SignatureMethod) method;
    List list = keyInfo.getContent();

    for (int i = 0; i < list.size(); i++) {
      XMLStructure xmlStructure = (XMLStructure) list.get(i);
      if (xmlStructure instanceof KeyValue) {
        PublicKey pk = null;
        try {
          pk = ((KeyValue) xmlStructure).getPublicKey();
        } catch (KeyException ke) {
          throw new KeySelectorException(ke);
        }
        // make sure algorithm is compatible with method
        if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
          curPK = pk;
          //           	System.out.println("Public Key is SOAP: " + getHexString(pk.getEncoded()));
          //            	System.out.println("Public Key is SOAP: " +getHexString(LoadPublicKey("",
          // "RSA").getEncoded()));
          return new SimpleKeySelectorResult(pk);
        }
      }
    }
    throw new KeySelectorException("No KeyValue element found!");
  }
Ejemplo n.º 2
0
  @Override
  public KeySelectorResult select(
      final KeyInfo ki, final Purpose p, final AlgorithmMethod m, final XMLCryptoContext c)
      throws KeySelectorException {

    if (ki == null) throw new KeySelectorException("KeyInfo is null");

    final SignatureMethod sm = (SignatureMethod) m;
    @SuppressWarnings("unchecked")
    final List<Object> list = ki.getContent();

    for (final Object l : list) {
      final XMLStructure s = (XMLStructure) l;
      PublicKey pk = null;
      if (s instanceof KeyValue) {
        try {
          pk = ((KeyValue) s).getPublicKey();
        } catch (final KeyException ke) {
          throw new KeySelectorException(ke);
        }

      } else if (s instanceof X509Data) {
        for (final Object d : ((X509Data) s).getContent()) {
          if (d instanceof X509Certificate) {
            pk = ((Certificate) d).getPublicKey();
          }
        }
      }

      if (pk != null) {
        final String sa = sm.getAlgorithm();
        final String ka = pk.getAlgorithm();
        if ("DSA".equalsIgnoreCase(ka) && "http://www.w3.org/2000/09/xmldsig#dsa-sha1".equals(sa)
            || "RSA".equalsIgnoreCase(ka)
                && "http://www.w3.org/2000/09/xmldsig#rsa-sha1".equals(sa)) {
          return new MyKeySelectorResult(pk);
        }
      }
    }

    throw new KeySelectorException("No KeyValue element found");
  }