Java Code Examples for com.sun.org.apache.xml.internal.security.utils.XMLUtils#elementIsInSignatureSpace()

The following examples show how to use com.sun.org.apache.xml.internal.security.utils.XMLUtils#elementIsInSignatureSpace() . 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: SingleKeyResolver.java    From jdk8u_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 2
Source File: SingleKeyResolver.java    From openjdk-jdk8u-backup 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 3
Source File: SingleKeyResolver.java    From JDKSourceCode1.8 with MIT License 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: KeyInfoReferenceResolver.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate the Element referred to by the KeyInfoReference.
 *
 * @param referentElement
 *
 * @throws XMLSecurityException
 */
private void validateReference(Element referentElement) throws XMLSecurityException {
    if (!XMLUtils.elementIsInSignatureSpace(referentElement, Constants._TAG_KEYINFO)) {
        Object exArgs[] = { new QName(referentElement.getNamespaceURI(), referentElement.getLocalName()) };
        throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.WrongType", exArgs);
    }

    KeyInfo referent = new KeyInfo(referentElement, "");
    if (referent.containsKeyInfoReference()) {
        if (secureValidation) {
            throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithSecure");
        } else {
            // Don't support chains of references at this time. If do support in the future, this is where the code
            // would go to validate that don't have a cycle, resulting in an infinite loop. This may be unrealistic
            // to implement, and/or very expensive given remote URI references.
            throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithoutSecure");
        }
    }

}
 
Example 5
Source File: KeyInfoReferenceResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate the Element referred to by the KeyInfoReference.
 *
 * @param referentElement
 *
 * @throws XMLSecurityException
 */
private void validateReference(Element referentElement) throws XMLSecurityException {
    if (!XMLUtils.elementIsInSignatureSpace(referentElement, Constants._TAG_KEYINFO)) {
        Object exArgs[] = { new QName(referentElement.getNamespaceURI(), referentElement.getLocalName()) };
        throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.WrongType", exArgs);
    }

    KeyInfo referent = new KeyInfo(referentElement, "");
    if (referent.containsKeyInfoReference()) {
        if (secureValidation) {
            throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithSecure");
        } else {
            // Don't support chains of references at this time. If do support in the future, this is where the code
            // would go to validate that don't have a cycle, resulting in an infinite loop. This may be unrealistic
            // to implement, and/or very expensive given remote URI references.
            throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithoutSecure");
        }
    }

}
 
Example 6
Source File: SingleKeyResolver.java    From jdk8u60 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 7
Source File: SingleKeyResolver.java    From hottub 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 8
Source File: SingleKeyResolver.java    From jdk8u-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 9
Source File: PrivateKeyResolver.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method returns whether the KeyResolverSpi is able to perform the requested action.
 *
 * @param element
 * @param BaseURI
 * @param storage
 * @return whether the KeyResolverSpi is able to perform the requested action.
 */
public boolean engineCanResolve(Element element, String BaseURI, StorageResolver storage) {
    if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)
        || XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        return true;
    }

    return false;
}
 
Example 10
Source File: PrivateKeyResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method returns whether the KeyResolverSpi is able to perform the requested action.
 *
 * @param element
 * @param BaseURI
 * @param storage
 * @return whether the KeyResolverSpi is able to perform the requested action.
 */
public boolean engineCanResolve(Element element, String BaseURI, StorageResolver storage) {
    if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)
        || XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        return true;
    }

    return false;
}
 
Example 11
Source File: X509DigestResolver.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}. */
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
    if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)) {
        try {
            X509Data x509Data = new X509Data(element, baseURI);
            return x509Data.containsDigest();
        } catch (XMLSecurityException e) {
            return false;
        }
    } else {
        return false;
    }
}
 
Example 12
Source File: RSAKeyValueResolver.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** @inheritDoc */
public PublicKey engineLookupAndResolvePublicKey(
    Element element, String BaseURI, StorageResolver storage
) {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }
    if (element == null) {
        return null;
    }

    boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE);
    Element rsaKeyElement = null;
    if (isKeyValue) {
        rsaKeyElement =
            XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_RSAKEYVALUE, 0);
    } else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RSAKEYVALUE)) {
        // this trick is needed to allow the RetrievalMethodResolver to eat a
        // ds:RSAKeyValue directly (without KeyValue)
        rsaKeyElement = element;
    }

    if (rsaKeyElement == null) {
        return null;
    }

    try {
        RSAKeyValue rsaKeyValue = new RSAKeyValue(rsaKeyElement, BaseURI);

        return rsaKeyValue.getPublicKey();
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
        }
    }

    return null;
}
 
Example 13
Source File: PrivateKeyResolver.java    From openjdk-8-source with GNU General Public License v2.0 5 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 (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)) {
        PrivateKey privKey = resolveX509Data(element, baseURI);
        if (privKey != null) {
            return privKey;
        }
    } else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve KeyName?");
        String keyName = element.getFirstChild().getNodeValue();

        try {
            Key key = keyStore.getKey(keyName, password);
            if (key instanceof PrivateKey) {
                return (PrivateKey) 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 14
Source File: X509DigestResolver.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc}. */
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
    if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)) {
        try {
            X509Data x509Data = new X509Data(element, baseURI);
            return x509Data.containsDigest();
        } catch (XMLSecurityException e) {
            return false;
        }
    } else {
        return false;
    }
}
 
Example 15
Source File: PrivateKeyResolver.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method returns whether the KeyResolverSpi is able to perform the requested action.
 *
 * @param element
 * @param BaseURI
 * @param storage
 * @return whether the KeyResolverSpi is able to perform the requested action.
 */
public boolean engineCanResolve(Element element, String BaseURI, StorageResolver storage) {
    if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)
        || XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        return true;
    }

    return false;
}
 
Example 16
Source File: RSAKeyValueResolver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** @inheritDoc */
public PublicKey engineLookupAndResolvePublicKey(
    Element element, String BaseURI, StorageResolver storage
) {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }
    if (element == null) {
        return null;
    }

    boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE);
    Element rsaKeyElement = null;
    if (isKeyValue) {
        rsaKeyElement =
            XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_RSAKEYVALUE, 0);
    } else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RSAKEYVALUE)) {
        // this trick is needed to allow the RetrievalMethodResolver to eat a
        // ds:RSAKeyValue directly (without KeyValue)
        rsaKeyElement = element;
    }

    if (rsaKeyElement == null) {
        return null;
    }

    try {
        RSAKeyValue rsaKeyValue = new RSAKeyValue(rsaKeyElement, BaseURI);

        return rsaKeyValue.getPublicKey();
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
        }
    }

    return null;
}
 
Example 17
Source File: PrivateKeyResolver.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method returns whether the KeyResolverSpi is able to perform the requested action.
 *
 * @param element
 * @param BaseURI
 * @param storage
 * @return whether the KeyResolverSpi is able to perform the requested action.
 */
public boolean engineCanResolve(Element element, String BaseURI, StorageResolver storage) {
    if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)
        || XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        return true;
    }

    return false;
}
 
Example 18
Source File: PrivateKeyResolver.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method returns whether the KeyResolverSpi is able to perform the requested action.
 *
 * @param element
 * @param BaseURI
 * @param storage
 * @return whether the KeyResolverSpi is able to perform the requested action.
 */
public boolean engineCanResolve(Element element, String BaseURI, StorageResolver storage) {
    if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)
        || XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        return true;
    }

    return false;
}
 
Example 19
Source File: SecretKeyResolver.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * This method returns whether the KeyResolverSpi is able to perform the requested action.
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return whether the KeyResolverSpi is able to perform the requested action.
 */
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
    return XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME);
}
 
Example 20
Source File: SecretKeyResolver.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * This method returns whether the KeyResolverSpi is able to perform the requested action.
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return whether the KeyResolverSpi is able to perform the requested action.
 */
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
    return XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME);
}