Search in sources :

Example 6 with DSAKeyValue

use of org.apache.xml.security.keys.content.keyvalues.DSAKeyValue in project santuario-java by apache.

the class DSAKeyValueResolver method engineLookupAndResolvePublicKey.

/**
 * Method engineResolvePublicKey
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return null if no {@link PublicKey} could be obtained
 */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage) {
    if (element == null) {
        return null;
    }
    Element dsaKeyElement = null;
    boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE);
    if (isKeyValue) {
        dsaKeyElement = XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_DSAKEYVALUE, 0);
    } else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_DSAKEYVALUE)) {
        // this trick is needed to allow the RetrievalMethodResolver to eat a
        // ds:DSAKeyValue directly (without KeyValue)
        dsaKeyElement = element;
    }
    if (dsaKeyElement == null) {
        return null;
    }
    try {
        DSAKeyValue dsaKeyValue = new DSAKeyValue(dsaKeyElement, baseURI);
        PublicKey pk = dsaKeyValue.getPublicKey();
        return pk;
    } catch (XMLSecurityException ex) {
        LOG.debug(ex.getMessage(), ex);
    // do nothing
    }
    return null;
}
Also used : DSAKeyValue(org.apache.xml.security.keys.content.keyvalues.DSAKeyValue) PublicKey(java.security.PublicKey) Element(org.w3c.dom.Element) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException)

Aggregations

DSAKeyValue (org.apache.xml.security.keys.content.keyvalues.DSAKeyValue)6 RSAKeyValue (org.apache.xml.security.keys.content.keyvalues.RSAKeyValue)5 PublicKey (java.security.PublicKey)4 Element (org.w3c.dom.Element)3 BigInteger (java.math.BigInteger)2 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)2 X509Data (org.apache.xml.security.keys.content.X509Data)2 XMLSignatureException (com.sun.identity.saml.xmlsig.XMLSignatureException)1 TransformerException (javax.xml.transform.TransformerException)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1