com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException Java Examples

The following examples show how to use com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyInfoReferenceResolver.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
        if (referent != null) {
            return referent.getPublicKey();
        }
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #2
Source File: KeyInfoReferenceResolver.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
        if (referent != null) {
            return referent.getPublicKey();
        }
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #3
Source File: SingleKeyResolver.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Method engineLookupAndResolvePublicKey
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return null if no {@link PublicKey} could be obtained
 * @throws KeyResolverException
 */
public PublicKey engineLookupAndResolvePublicKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (publicKey != null
        && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String name = element.getFirstChild().getNodeValue();
        if (keyName.equals(name)) {
            return publicKey;
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #4
Source File: KeyInfo.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 = this.constructionElement.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;
}
 
Example #5
Source File: KeyInfoReferenceResolver.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
        if (referent != null) {
            return referent.getPrivateKey();
        }
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #6
Source File: KeyInfoReferenceResolver.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
        if (referent != null) {
            return referent.getX509Certificate();
        }
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #7
Source File: KeyInfo.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Method getX509CertificateFromInternalResolvers
 *
 * @return The certificate contained in this KeyInfo
 * @throws KeyResolverException
 */
X509Certificate getX509CertificateFromInternalResolvers()
    throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE,
            "Start getX509CertificateFromInternalResolvers() with "
            + this.lengthInternalKeyResolver() + " resolvers"
        );
    }
    String uri = this.getBaseURI();
    for (KeyResolverSpi keyResolver : internalKeyResolvers) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName());
        }
        keyResolver.setSecureValidation(secureValidation);
        X509Certificate cert = applyCurrentResolver(uri, keyResolver);
        if (cert != null) {
            return cert;
        }
    }

    return null;
}
 
Example #8
Source File: KeyInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method uses each System-wide {@link KeyResolver} to search the
 * child elements. Each combination of {@link KeyResolver} and child element
 * is checked against all {@link StorageResolver}s.
 *
 * @return The certificate contained in this KeyInfo
 * @throws KeyResolverException
 */
X509Certificate getX509CertificateFromStaticResolvers()
    throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE,
            "Start getX509CertificateFromStaticResolvers() with " + KeyResolver.length()
            + " resolvers"
        );
    }
    String uri = this.getBaseURI();
    Iterator<KeyResolverSpi> it = KeyResolver.iterator();
    while (it.hasNext()) {
        KeyResolverSpi keyResolver = it.next();
        keyResolver.setSecureValidation(secureValidation);
        X509Certificate cert = applyCurrentResolver(uri, keyResolver);
        if (cert != null) {
            return cert;
        }
    }
    return null;
}
 
Example #9
Source File: KeyInfo.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private X509Certificate applyCurrentResolver(
    String uri, KeyResolverSpi keyResolver
) throws KeyResolverException {
    Node currentChild = this.constructionElement.getFirstChild();
    while (currentChild != null)      {
        if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
            for (StorageResolver storage : storageResolvers) {
                X509Certificate cert =
                    keyResolver.engineLookupResolveX509Certificate(
                        (Element) currentChild, uri, storage
                    );

                if (cert != null) {
                    return cert;
                }
            }
        }
        currentChild = currentChild.getNextSibling();
    }
    return null;
}
 
Example #10
Source File: KeyInfoReferenceResolver.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
        if (referent != null) {
            return referent.getPrivateKey();
        }
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #11
Source File: KeyInfo.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method getX509CertificateFromInternalResolvers
 *
 * @return The certificate contained in this KeyInfo
 * @throws KeyResolverException
 */
X509Certificate getX509CertificateFromInternalResolvers()
    throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE,
            "Start getX509CertificateFromInternalResolvers() with "
            + this.lengthInternalKeyResolver() + " resolvers"
        );
    }
    String uri = this.getBaseURI();
    for (KeyResolverSpi keyResolver : internalKeyResolvers) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName());
        }
        keyResolver.setSecureValidation(secureValidation);
        X509Certificate cert = applyCurrentResolver(uri, keyResolver);
        if (cert != null) {
            return cert;
        }
    }

    return null;
}
 
Example #12
Source File: DEREncodedKeyValueResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        DEREncodedKeyValue derKeyValue = new DEREncodedKeyValue(element, baseURI);
        return derKeyValue.getPublicKey();
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #13
Source File: SingleKeyResolver.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Method engineResolvePrivateKey
 * @inheritDoc
 * @param element
 * @param baseURI
 * @param storage
 * @return resolved PrivateKey key or null if no {@link PrivateKey} could be obtained
 * @throws KeyResolverException
 */
public PrivateKey engineLookupAndResolvePrivateKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (privateKey != null
        && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String name = element.getFirstChild().getNodeValue();
        if (keyName.equals(name)) {
            return privateKey;
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #14
Source File: KeyInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method getX509CertificateFromInternalResolvers
 *
 * @return The certificate contained in this KeyInfo
 * @throws KeyResolverException
 */
X509Certificate getX509CertificateFromInternalResolvers()
    throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE,
            "Start getX509CertificateFromInternalResolvers() with "
            + this.lengthInternalKeyResolver() + " resolvers"
        );
    }
    String uri = this.getBaseURI();
    for (KeyResolverSpi keyResolver : internalKeyResolvers) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName());
        }
        keyResolver.setSecureValidation(secureValidation);
        X509Certificate cert = applyCurrentResolver(uri, keyResolver);
        if (cert != null) {
            return cert;
        }
    }

    return null;
}
 
Example #15
Source File: SingleKeyResolver.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineResolvePrivateKey
 * @inheritDoc
 * @param element
 * @param baseURI
 * @param storage
 * @return resolved PrivateKey key or null if no {@link PrivateKey} could be obtained
 * @throws KeyResolverException
 */
public PrivateKey engineLookupAndResolvePrivateKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (privateKey != null
        && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String name = element.getFirstChild().getNodeValue();
        if (keyName.equals(name)) {
            return privateKey;
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #16
Source File: KeyInfo.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * This method uses each System-wide {@link KeyResolver} to search the
 * child elements. Each combination of {@link KeyResolver} and child element
 * is checked against all {@link StorageResolver}s.
 *
 * @return The certificate contained in this KeyInfo
 * @throws KeyResolverException
 */
X509Certificate getX509CertificateFromStaticResolvers()
    throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE,
            "Start getX509CertificateFromStaticResolvers() with " + KeyResolver.length()
            + " resolvers"
        );
    }
    String uri = this.getBaseURI();
    Iterator<KeyResolverSpi> it = KeyResolver.iterator();
    while (it.hasNext()) {
        KeyResolverSpi keyResolver = it.next();
        keyResolver.setSecureValidation(secureValidation);
        X509Certificate cert = applyCurrentResolver(uri, keyResolver);
        if (cert != null) {
            return cert;
        }
    }
    return null;
}
 
Example #17
Source File: DEREncodedKeyValueResolver.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        DEREncodedKeyValue derKeyValue = new DEREncodedKeyValue(element, baseURI);
        return derKeyValue.getPublicKey();
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #18
Source File: SingleKeyResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineLookupAndResolvePublicKey
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return null if no {@link PublicKey} could be obtained
 * @throws KeyResolverException
 */
public PublicKey engineLookupAndResolvePublicKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (publicKey != null
        && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String name = element.getFirstChild().getNodeValue();
        if (keyName.equals(name)) {
            return publicKey;
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #19
Source File: SecretKeyResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineResolveSecretKey
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return resolved SecretKey key or null if no {@link SecretKey} could be obtained
 *
 * @throws KeyResolverException
 */
public SecretKey engineResolveSecretKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String keyName = element.getFirstChild().getNodeValue();
        try {
            Key key = keyStore.getKey(keyName, password);
            if (key instanceof SecretKey) {
                return (SecretKey) key;
            }
        } catch (Exception e) {
            log.log(java.util.logging.Level.FINE, "Cannot recover the key", e);
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #20
Source File: KeyInfo.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 = this.constructionElement.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;
}
 
Example #21
Source File: X509DigestResolver.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        return resolveCertificate(element, baseURI, storage);
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #22
Source File: X509DigestResolver.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        return resolveCertificate(element, baseURI, storage);
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #23
Source File: SingleKeyResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineResolveSecretKey
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return resolved SecretKey key or null if no {@link SecretKey} could be obtained
 *
 * @throws KeyResolverException
 */
public SecretKey engineResolveSecretKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (secretKey != null
        && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String name = element.getFirstChild().getNodeValue();
        if (keyName.equals(name)) {
            return secretKey;
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #24
Source File: SingleKeyResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineResolvePrivateKey
 * @inheritDoc
 * @param element
 * @param baseURI
 * @param storage
 * @return resolved PrivateKey key or null if no {@link PrivateKey} could be obtained
 * @throws KeyResolverException
 */
public PrivateKey engineLookupAndResolvePrivateKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (privateKey != null
        && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String name = element.getFirstChild().getNodeValue();
        if (keyName.equals(name)) {
            return privateKey;
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #25
Source File: KeyInfoReferenceResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
        if (referent != null) {
            return referent.getX509Certificate();
        }
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #26
Source File: SingleKeyResolver.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineLookupAndResolvePublicKey
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return null if no {@link PublicKey} could be obtained
 * @throws KeyResolverException
 */
public PublicKey engineLookupAndResolvePublicKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (publicKey != null
        && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String name = element.getFirstChild().getNodeValue();
        if (keyName.equals(name)) {
            return publicKey;
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #27
Source File: KeyInfoReferenceResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc}. */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
        if (referent != null) {
            return referent.getPublicKey();
        }
    } catch (XMLSecurityException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
        }
    }

    return null;
}
 
Example #28
Source File: KeyInfo.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Searches the per-KeyInfo KeyResolvers for private keys
 *
 * @return the private key contained in this KeyInfo
 * @throws KeyResolverException
 */
PrivateKey getPrivateKeyFromInternalResolvers() throws KeyResolverException {
    for (KeyResolverSpi keyResolver : internalKeyResolvers) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName());
        }
        keyResolver.setSecureValidation(secureValidation);
        Node currentChild = this.constructionElement.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;
}
 
Example #29
Source File: RetrievalMethodResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves a x509Certificate from the given information
 * @param e
 * @param baseURI
 * @param storage
 * @return
 * @throws KeyResolverException
 */
private static X509Certificate resolveCertificate(
    Element e, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Now we have a {" + e.getNamespaceURI() + "}"
            + e.getLocalName() + " Element");
    }
    // An element has been provided
    if (e != null) {
        return KeyResolver.getX509Certificate(e, baseURI, storage);
    }
    return null;
}
 
Example #30
Source File: KeyInfo.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * This method returns a private key. This is for Key Transport in XML Encryption.
 * @return the private key contained in this KeyInfo
 * @throws KeyResolverException
 */
public PrivateKey getPrivateKey() throws KeyResolverException {
    PrivateKey pk = this.getPrivateKeyFromInternalResolvers();

    if (pk != null) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "I could find a private key using the per-KeyInfo key resolvers");
        }
        return pk;
    }
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "I couldn't find a secret key using the per-KeyInfo key resolvers");
    }

    pk = this.getPrivateKeyFromStaticResolvers();
    if (pk != null) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "I could find a private key using the system-wide key resolvers");
        }
        return pk;
    }
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "I couldn't find a private key using the system-wide key resolvers");
    }

    return null;
}