Search in sources :

Example 1 with ResourceResolverException

use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.

the class ResolverFragment method engineResolveURI.

/**
     * Method engineResolve
     *
     * @inheritDoc
     * @param uri
     * @param baseURI
     */
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException {
    Document doc = context.attr.getOwnerElement().getOwnerDocument();
    Node selectedElem = null;
    if (context.uriToResolve.equals("")) {
        /*
             * Identifies the node-set (minus any comment nodes) of the XML
             * resource containing the signature
             */
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "ResolverFragment with empty URI (means complete document)");
        }
        selectedElem = doc;
    } else {
        /*
             * URI="#chapter1"
             * Identifies a node-set containing the element with ID attribute
             * value 'chapter1' of the XML resource containing the signature.
             * XML Signature (and its applications) modify this node-set to
             * include the element plus all descendants including namespaces and
             * attributes -- but not comments.
             */
        String id = context.uriToResolve.substring(1);
        selectedElem = doc.getElementById(id);
        if (selectedElem == null) {
            Object[] exArgs = { id };
            throw new ResourceResolverException("signature.Verification.MissingID", exArgs, context.attr, context.baseUri);
        }
        if (context.secureValidation) {
            Element start = context.attr.getOwnerDocument().getDocumentElement();
            if (!XMLUtils.protectAgainstWrappingAttack(start, id)) {
                Object[] exArgs = { id };
                throw new ResourceResolverException("signature.Verification.MultipleIDs", exArgs, context.attr, context.baseUri);
            }
        }
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Try to catch an Element with ID " + id + " and Element was " + selectedElem);
        }
    }
    XMLSignatureInput result = new XMLSignatureInput(selectedElem);
    result.setExcludeComments(true);
    result.setMIMEType("text/xml");
    if (context.baseUri != null && context.baseUri.length() > 0) {
        result.setSourceURI(context.baseUri.concat(context.uriToResolve));
    } else {
        result.setSourceURI(context.uriToResolve);
    }
    return result;
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) ResourceResolverException(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException) Document(org.w3c.dom.Document)

Example 2 with ResourceResolverException

use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.

the class ResolverLocalFilesystem method engineResolveURI.

/**
     * @inheritDoc
     */
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException {
    try {
        // calculate new URI
        URI uriNew = getNewURI(context.uriToResolve, context.baseUri);
        String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString());
        FileInputStream inputStream = new FileInputStream(fileName);
        XMLSignatureInput result = new XMLSignatureInput(inputStream);
        result.setSourceURI(uriNew.toString());
        return result;
    } catch (Exception e) {
        throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri);
    }
}
Also used : XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) ResourceResolverException(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException) URI(java.net.URI) FileInputStream(java.io.FileInputStream) URISyntaxException(java.net.URISyntaxException) ResourceResolverException(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException)

Example 3 with ResourceResolverException

use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.

the class ResolverXPointer method engineResolveURI.

/**
     * @inheritDoc
     */
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException {
    Node resultNode = null;
    Document doc = context.attr.getOwnerElement().getOwnerDocument();
    if (isXPointerSlash(context.uriToResolve)) {
        resultNode = doc;
    } else if (isXPointerId(context.uriToResolve)) {
        String id = getXPointerId(context.uriToResolve);
        resultNode = doc.getElementById(id);
        if (context.secureValidation) {
            Element start = context.attr.getOwnerDocument().getDocumentElement();
            if (!XMLUtils.protectAgainstWrappingAttack(start, id)) {
                Object[] exArgs = { id };
                throw new ResourceResolverException("signature.Verification.MultipleIDs", exArgs, context.attr, context.baseUri);
            }
        }
        if (resultNode == null) {
            Object[] exArgs = { id };
            throw new ResourceResolverException("signature.Verification.MissingID", exArgs, context.attr, context.baseUri);
        }
    }
    XMLSignatureInput result = new XMLSignatureInput(resultNode);
    result.setMIMEType("text/xml");
    if (context.baseUri != null && context.baseUri.length() > 0) {
        result.setSourceURI(context.baseUri.concat(context.uriToResolve));
    } else {
        result.setSourceURI(context.uriToResolve);
    }
    return result;
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) ResourceResolverException(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException) Document(org.w3c.dom.Document)

Example 4 with ResourceResolverException

use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.

the class Reference method getContentsAfterTransformation.

private XMLSignatureInput getContentsAfterTransformation(XMLSignatureInput input, OutputStream os) throws XMLSignatureException {
    try {
        Transforms transforms = this.getTransforms();
        XMLSignatureInput output = null;
        if (transforms != null) {
            output = transforms.performTransforms(input, os);
            //new XMLSignatureInput(output.getBytes());
            this.transformsOutput = output;
        //this.transformsOutput.setSourceURI(output.getSourceURI());
        } else {
            output = input;
        }
        return output;
    } catch (ResourceResolverException ex) {
        throw new XMLSignatureException("empty", ex);
    } catch (CanonicalizationException ex) {
        throw new XMLSignatureException("empty", ex);
    } catch (InvalidCanonicalizerException ex) {
        throw new XMLSignatureException("empty", ex);
    } catch (TransformationException ex) {
        throw new XMLSignatureException("empty", ex);
    } catch (XMLSecurityException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
Also used : TransformationException(com.sun.org.apache.xml.internal.security.transforms.TransformationException) CanonicalizationException(com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException) InvalidCanonicalizerException(com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException) Transforms(com.sun.org.apache.xml.internal.security.transforms.Transforms) ResourceResolverException(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Example 5 with ResourceResolverException

use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.

the class Reference method getContentsBeforeTransformation.

/**
     * Returns the XMLSignatureInput which is created by de-referencing the URI attribute.
     * @return the XMLSignatureInput of the source of this reference
     * @throws ReferenceNotInitializedException If the resolver found any
     * problem resolving the reference
     */
public XMLSignatureInput getContentsBeforeTransformation() throws ReferenceNotInitializedException {
    try {
        Attr uriAttr = this.constructionElement.getAttributeNodeNS(null, Constants._ATT_URI);
        ResourceResolver resolver = ResourceResolver.getInstance(uriAttr, this.baseURI, this.manifest.getPerManifestResolvers(), secureValidation);
        resolver.addProperties(this.manifest.getResolverProperties());
        return resolver.resolve(uriAttr, this.baseURI, secureValidation);
    } catch (ResourceResolverException ex) {
        throw new ReferenceNotInitializedException("empty", ex);
    }
}
Also used : ResourceResolver(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver) ResourceResolverException(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException) Attr(org.w3c.dom.Attr)

Aggregations

ResourceResolverException (com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException)8 XMLSignatureInput (com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput)5 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)3 TransformationException (com.sun.org.apache.xml.internal.security.transforms.TransformationException)3 IOException (java.io.IOException)3 InvalidCanonicalizerException (com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException)2 XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)2 Transforms (com.sun.org.apache.xml.internal.security.transforms.Transforms)2 ResourceResolver (com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Attr (org.w3c.dom.Attr)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 Base64DecodingException (com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException)1 Transform (com.sun.org.apache.xml.internal.security.transforms.Transform)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1