Search in sources :

Example 1 with RetrievalMethod

use of com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod in project jdk8u_jdk by JetBrains.

the class RetrievalMethodResolver method engineLookupAndResolvePublicKey.

/**
     * Method engineResolvePublicKey
     * @inheritDoc
     * @param element
     * @param baseURI
     * @param storage
     */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage) {
    if (!XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RETRIEVALMETHOD)) {
        return null;
    }
    try {
        // Create a retrieval method over the given element
        RetrievalMethod rm = new RetrievalMethod(element, baseURI);
        String type = rm.getType();
        XMLSignatureInput resource = resolveInput(rm, baseURI, secureValidation);
        if (RetrievalMethod.TYPE_RAWX509.equals(type)) {
            // a raw certificate, direct parsing is done!
            X509Certificate cert = getRawCertificate(resource);
            if (cert != null) {
                return cert.getPublicKey();
            }
            return null;
        }
        Element e = obtainReferenceElement(resource);
        // which points to this element
        if (XMLUtils.elementIsInSignatureSpace(e, Constants._TAG_RETRIEVALMETHOD)) {
            if (secureValidation) {
                String error = "Error: It is forbidden to have one RetrievalMethod " + "point to another with secure validation";
                if (log.isLoggable(java.util.logging.Level.FINE)) {
                    log.log(java.util.logging.Level.FINE, error);
                }
                return null;
            }
            RetrievalMethod rm2 = new RetrievalMethod(e, baseURI);
            XMLSignatureInput resource2 = resolveInput(rm2, baseURI, secureValidation);
            Element e2 = obtainReferenceElement(resource2);
            if (e2 == element) {
                if (log.isLoggable(java.util.logging.Level.FINE)) {
                    log.log(java.util.logging.Level.FINE, "Error: Can't have RetrievalMethods pointing to each other");
                }
                return null;
            }
        }
        return resolveKey(e, baseURI, storage);
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
        }
    } catch (CertificateException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "CertificateException", ex);
        }
    } catch (IOException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "IOException", ex);
        }
    } catch (ParserConfigurationException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "ParserConfigurationException", e);
        }
    } catch (SAXException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "SAXException", e);
        }
    }
    return null;
}
Also used : RetrievalMethod(com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod) Element(org.w3c.dom.Element) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) X509Certificate(java.security.cert.X509Certificate) XMLX509Certificate(com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Certificate) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException) SAXException(org.xml.sax.SAXException)

Example 2 with RetrievalMethod

use of com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod in project jdk8u_jdk by JetBrains.

the class RetrievalMethodResolver method engineLookupResolveX509Certificate.

/**
     * Method engineResolveX509Certificate
     * @inheritDoc
     * @param element
     * @param baseURI
     * @param storage
     */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage) {
    if (!XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RETRIEVALMETHOD)) {
        return null;
    }
    try {
        RetrievalMethod rm = new RetrievalMethod(element, baseURI);
        String type = rm.getType();
        XMLSignatureInput resource = resolveInput(rm, baseURI, secureValidation);
        if (RetrievalMethod.TYPE_RAWX509.equals(type)) {
            return getRawCertificate(resource);
        }
        Element e = obtainReferenceElement(resource);
        // which points to this element
        if (XMLUtils.elementIsInSignatureSpace(e, Constants._TAG_RETRIEVALMETHOD)) {
            if (secureValidation) {
                String error = "Error: It is forbidden to have one RetrievalMethod " + "point to another with secure validation";
                if (log.isLoggable(java.util.logging.Level.FINE)) {
                    log.log(java.util.logging.Level.FINE, error);
                }
                return null;
            }
            RetrievalMethod rm2 = new RetrievalMethod(e, baseURI);
            XMLSignatureInput resource2 = resolveInput(rm2, baseURI, secureValidation);
            Element e2 = obtainReferenceElement(resource2);
            if (e2 == element) {
                if (log.isLoggable(java.util.logging.Level.FINE)) {
                    log.log(java.util.logging.Level.FINE, "Error: Can't have RetrievalMethods pointing to each other");
                }
                return null;
            }
        }
        return resolveCertificate(e, baseURI, storage);
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
        }
    } catch (CertificateException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "CertificateException", ex);
        }
    } catch (IOException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "IOException", ex);
        }
    } catch (ParserConfigurationException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "ParserConfigurationException", e);
        }
    } catch (SAXException e) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "SAXException", e);
        }
    }
    return null;
}
Also used : RetrievalMethod(com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod) Element(org.w3c.dom.Element) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException) SAXException(org.xml.sax.SAXException)

Aggregations

XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)2 RetrievalMethod (com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod)2 XMLSignatureInput (com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput)2 IOException (java.io.IOException)2 CertificateException (java.security.cert.CertificateException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Element (org.w3c.dom.Element)2 SAXException (org.xml.sax.SAXException)2 XMLX509Certificate (com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Certificate)1 X509Certificate (java.security.cert.X509Certificate)1