Search in sources :

Example 6 with KeyResolverSpi

use of org.apache.xml.security.keys.keyresolver.KeyResolverSpi in project santuario-java by apache.

the class KeyInfo method getSecretKeyFromInternalResolvers.

/**
 * Searches the per-KeyInfo KeyResolvers for secret keys
 *
 * @return the secret key contained in this KeyInfo
 * @throws KeyResolverException
 */
SecretKey getSecretKeyFromInternalResolvers() throws KeyResolverException {
    for (KeyResolverSpi keyResolver : internalKeyResolvers) {
        LOG.debug("Try {}", keyResolver.getClass().getName());
        keyResolver.setSecureValidation(secureValidation);
        Node currentChild = getFirstChild();
        String uri = this.getBaseURI();
        while (currentChild != null) {
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                for (StorageResolver storage : storageResolvers) {
                    SecretKey sk = keyResolver.engineLookupAndResolveSecretKey((Element) currentChild, uri, storage);
                    if (sk != null) {
                        return sk;
                    }
                }
            }
            currentChild = currentChild.getNextSibling();
        }
    }
    return null;
}
Also used : SecretKey(javax.crypto.SecretKey) StorageResolver(org.apache.xml.security.keys.storage.StorageResolver) Node(org.w3c.dom.Node) KeyResolverSpi(org.apache.xml.security.keys.keyresolver.KeyResolverSpi)

Example 7 with KeyResolverSpi

use of org.apache.xml.security.keys.keyresolver.KeyResolverSpi in project santuario-java by apache.

the class KeyInfo method getSecretKeyFromStaticResolvers.

/**
 * Searches the library wide KeyResolvers for Secret keys
 *
 * @return the secret key contained in this KeyInfo
 * @throws KeyResolverException
 */
SecretKey getSecretKeyFromStaticResolvers() throws KeyResolverException {
    Iterator<KeyResolverSpi> it = KeyResolver.iterator();
    while (it.hasNext()) {
        KeyResolverSpi keyResolver = it.next();
        keyResolver.setSecureValidation(secureValidation);
        Node currentChild = getFirstChild();
        String uri = this.getBaseURI();
        while (currentChild != null) {
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                for (StorageResolver storage : storageResolvers) {
                    SecretKey sk = keyResolver.engineLookupAndResolveSecretKey((Element) currentChild, uri, storage);
                    if (sk != null) {
                        return sk;
                    }
                }
            }
            currentChild = currentChild.getNextSibling();
        }
    }
    return null;
}
Also used : SecretKey(javax.crypto.SecretKey) StorageResolver(org.apache.xml.security.keys.storage.StorageResolver) Node(org.w3c.dom.Node) KeyResolverSpi(org.apache.xml.security.keys.keyresolver.KeyResolverSpi)

Example 8 with KeyResolverSpi

use of org.apache.xml.security.keys.keyresolver.KeyResolverSpi in project santuario-java by apache.

the class KeyInfo method getPublicKeyFromInternalResolvers.

/**
 * Searches the per-KeyInfo KeyResolvers for public keys
 *
 * @return The public key contained in this Node.
 * @throws KeyResolverException
 */
PublicKey getPublicKeyFromInternalResolvers() throws KeyResolverException {
    for (KeyResolverSpi keyResolver : internalKeyResolvers) {
        LOG.debug("Try {}", keyResolver.getClass().getName());
        keyResolver.setSecureValidation(secureValidation);
        Node currentChild = getFirstChild();
        String uri = this.getBaseURI();
        while (currentChild != null) {
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                for (StorageResolver storage : storageResolvers) {
                    PublicKey pk = keyResolver.engineLookupAndResolvePublicKey((Element) currentChild, uri, storage);
                    if (pk != null) {
                        return pk;
                    }
                }
            }
            currentChild = currentChild.getNextSibling();
        }
    }
    return null;
}
Also used : StorageResolver(org.apache.xml.security.keys.storage.StorageResolver) PublicKey(java.security.PublicKey) Node(org.w3c.dom.Node) KeyResolverSpi(org.apache.xml.security.keys.keyresolver.KeyResolverSpi)

Example 9 with KeyResolverSpi

use of org.apache.xml.security.keys.keyresolver.KeyResolverSpi in project santuario-java by apache.

the class KeyInfo method getPublicKeyFromStaticResolvers.

/**
 * Searches the library wide KeyResolvers for public keys
 *
 * @return The public key contained in this Node.
 * @throws KeyResolverException
 */
PublicKey getPublicKeyFromStaticResolvers() throws KeyResolverException {
    Iterator<KeyResolverSpi> it = KeyResolver.iterator();
    while (it.hasNext()) {
        KeyResolverSpi keyResolver = it.next();
        keyResolver.setSecureValidation(secureValidation);
        Node currentChild = getFirstChild();
        String uri = this.getBaseURI();
        while (currentChild != null) {
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                for (StorageResolver storage : storageResolvers) {
                    PublicKey pk = keyResolver.engineLookupAndResolvePublicKey((Element) currentChild, uri, storage);
                    if (pk != null) {
                        return pk;
                    }
                }
            }
            currentChild = currentChild.getNextSibling();
        }
    }
    return null;
}
Also used : StorageResolver(org.apache.xml.security.keys.storage.StorageResolver) PublicKey(java.security.PublicKey) Node(org.w3c.dom.Node) KeyResolverSpi(org.apache.xml.security.keys.keyresolver.KeyResolverSpi)

Example 10 with KeyResolverSpi

use of org.apache.xml.security.keys.keyresolver.KeyResolverSpi in project santuario-java by apache.

the class KeyInfo method getPrivateKeyFromStaticResolvers.

/**
 * Searches the library wide KeyResolvers for Private keys
 *
 * @return the private key contained in this KeyInfo
 * @throws KeyResolverException
 */
PrivateKey getPrivateKeyFromStaticResolvers() throws KeyResolverException {
    Iterator<KeyResolverSpi> it = KeyResolver.iterator();
    while (it.hasNext()) {
        KeyResolverSpi keyResolver = it.next();
        keyResolver.setSecureValidation(secureValidation);
        Node currentChild = getFirstChild();
        String uri = this.getBaseURI();
        while (currentChild != null) {
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                // not using StorageResolvers at the moment
                // since they cannot return private keys
                PrivateKey pk = keyResolver.engineLookupAndResolvePrivateKey((Element) currentChild, uri, null);
                if (pk != null) {
                    return pk;
                }
            }
            currentChild = currentChild.getNextSibling();
        }
    }
    return null;
}
Also used : PrivateKey(java.security.PrivateKey) Node(org.w3c.dom.Node) KeyResolverSpi(org.apache.xml.security.keys.keyresolver.KeyResolverSpi)

Aggregations

KeyResolverSpi (org.apache.xml.security.keys.keyresolver.KeyResolverSpi)10 Node (org.w3c.dom.Node)6 StorageResolver (org.apache.xml.security.keys.storage.StorageResolver)5 PrivateKey (java.security.PrivateKey)3 PublicKey (java.security.PublicKey)3 X509Certificate (java.security.cert.X509Certificate)3 SecretKey (javax.crypto.SecretKey)3 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)2 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 KeyInfo (org.apache.xml.security.keys.KeyInfo)2 Document (org.w3c.dom.Document)2 FileInputStream (java.io.FileInputStream)1 BigInteger (java.math.BigInteger)1 KeyFactory (java.security.KeyFactory)1 KeyStore (java.security.KeyStore)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 RSAPrivateKeySpec (java.security.spec.RSAPrivateKeySpec)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1