Search in sources :

Example 1 with Transform

use of com.sun.org.apache.xml.internal.security.transforms.Transform in project jdk8u_jdk by JetBrains.

the class Reference method getHTMLRepresentation.

/**
     * Method getHTMLRepresentation
     * @return The HTML of the transformation
     * @throws XMLSignatureException
     */
public String getHTMLRepresentation() throws XMLSignatureException {
    try {
        XMLSignatureInput nodes = this.getNodesetBeforeFirstCanonicalization();
        Transforms transforms = this.getTransforms();
        Transform c14nTransform = null;
        if (transforms != null) {
            doTransforms: for (int i = 0; i < transforms.getLength(); i++) {
                Transform t = transforms.item(i);
                String uri = t.getURI();
                if (uri.equals(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS) || uri.equals(Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS)) {
                    c14nTransform = t;
                    break doTransforms;
                }
            }
        }
        Set<String> inclusiveNamespaces = new HashSet<String>();
        if (c14nTransform != null && (c14nTransform.length(InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1)) {
            // there is one InclusiveNamespaces element
            InclusiveNamespaces in = new InclusiveNamespaces(XMLUtils.selectNode(c14nTransform.getElement().getFirstChild(), InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES, 0), this.getBaseURI());
            inclusiveNamespaces = InclusiveNamespaces.prefixStr2Set(in.getInclusiveNamespaces());
        }
        return nodes.getHTMLRepresentation(inclusiveNamespaces);
    } catch (TransformationException ex) {
        throw new XMLSignatureException("empty", ex);
    } catch (InvalidTransformException ex) {
        throw new XMLSignatureException("empty", ex);
    } catch (XMLSecurityException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
Also used : InvalidTransformException(com.sun.org.apache.xml.internal.security.transforms.InvalidTransformException) TransformationException(com.sun.org.apache.xml.internal.security.transforms.TransformationException) Transforms(com.sun.org.apache.xml.internal.security.transforms.Transforms) InclusiveNamespaces(com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces) Transform(com.sun.org.apache.xml.internal.security.transforms.Transform) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException) HashSet(java.util.HashSet)

Example 2 with Transform

use of com.sun.org.apache.xml.internal.security.transforms.Transform in project jdk8u_jdk by JetBrains.

the class ApacheCanonicalizer method transform.

public Data transform(Data data, XMLCryptoContext xc, OutputStream os) throws TransformException {
    if (data == null) {
        throw new NullPointerException("data must not be null");
    }
    if (os == null) {
        throw new NullPointerException("output stream must not be null");
    }
    if (ownerDoc == null) {
        throw new TransformException("transform must be marshalled");
    }
    if (apacheTransform == null) {
        try {
            apacheTransform = new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes());
            apacheTransform.setElement(transformElem, xc.getBaseURI());
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "Created transform for algorithm: " + getAlgorithm());
            }
        } catch (Exception ex) {
            throw new TransformException("Couldn't find Transform for: " + getAlgorithm(), ex);
        }
    }
    XMLSignatureInput in;
    if (data instanceof ApacheData) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "ApacheData = true");
        }
        in = ((ApacheData) data).getXMLSignatureInput();
    } else if (data instanceof NodeSetData) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "isNodeSet() = true");
        }
        if (data instanceof DOMSubTreeData) {
            DOMSubTreeData subTree = (DOMSubTreeData) data;
            in = new XMLSignatureInput(subTree.getRoot());
            in.setExcludeComments(subTree.excludeComments());
        } else {
            @SuppressWarnings("unchecked") Set<Node> nodeSet = Utils.toNodeSet(((NodeSetData) data).iterator());
            in = new XMLSignatureInput(nodeSet);
        }
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "isNodeSet() = false");
        }
        try {
            in = new XMLSignatureInput(((OctetStreamData) data).getOctetStream());
        } catch (Exception ex) {
            throw new TransformException(ex);
        }
    }
    try {
        in = apacheTransform.performTransform(in, os);
        if (!in.isNodeSet() && !in.isElement()) {
            return null;
        }
        if (in.isOctetStream()) {
            return new ApacheOctetStreamData(in);
        } else {
            return new ApacheNodeSetData(in);
        }
    } catch (Exception ex) {
        throw new TransformException(ex);
    }
}
Also used : Set(java.util.Set) TransformException(javax.xml.crypto.dsig.TransformException) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) Transform(com.sun.org.apache.xml.internal.security.transforms.Transform) InvalidCanonicalizerException(com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) TransformException(javax.xml.crypto.dsig.TransformException)

Example 3 with Transform

use of com.sun.org.apache.xml.internal.security.transforms.Transform in project jdk8u_jdk by JetBrains.

the class ApacheTransform method transformIt.

private Data transformIt(Data data, XMLCryptoContext xc, OutputStream os) throws TransformException {
    if (ownerDoc == null) {
        throw new TransformException("transform must be marshalled");
    }
    if (apacheTransform == null) {
        try {
            apacheTransform = new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes());
            apacheTransform.setElement(transformElem, xc.getBaseURI());
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "Created transform for algorithm: " + getAlgorithm());
            }
        } catch (Exception ex) {
            throw new TransformException("Couldn't find Transform for: " + getAlgorithm(), ex);
        }
    }
    if (Utils.secureValidation(xc)) {
        String algorithm = getAlgorithm();
        if (Policy.restrictAlg(algorithm)) {
            throw new TransformException("Transform " + algorithm + " is forbidden when secure validation is enabled");
        }
    }
    XMLSignatureInput in;
    if (data instanceof ApacheData) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "ApacheData = true");
        }
        in = ((ApacheData) data).getXMLSignatureInput();
    } else if (data instanceof NodeSetData) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "isNodeSet() = true");
        }
        if (data instanceof DOMSubTreeData) {
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "DOMSubTreeData = true");
            }
            DOMSubTreeData subTree = (DOMSubTreeData) data;
            in = new XMLSignatureInput(subTree.getRoot());
            in.setExcludeComments(subTree.excludeComments());
        } else {
            @SuppressWarnings("unchecked") Set<Node> nodeSet = Utils.toNodeSet(((NodeSetData) data).iterator());
            in = new XMLSignatureInput(nodeSet);
        }
    } else {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "isNodeSet() = false");
        }
        try {
            in = new XMLSignatureInput(((OctetStreamData) data).getOctetStream());
        } catch (Exception ex) {
            throw new TransformException(ex);
        }
    }
    try {
        if (os != null) {
            in = apacheTransform.performTransform(in, os);
            if (!in.isNodeSet() && !in.isElement()) {
                return null;
            }
        } else {
            in = apacheTransform.performTransform(in);
        }
        if (in.isOctetStream()) {
            return new ApacheOctetStreamData(in);
        } else {
            return new ApacheNodeSetData(in);
        }
    } catch (Exception ex) {
        throw new TransformException(ex);
    }
}
Also used : Set(java.util.Set) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) Transform(com.sun.org.apache.xml.internal.security.transforms.Transform) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException)

Example 4 with Transform

use of com.sun.org.apache.xml.internal.security.transforms.Transform in project jdk8u_jdk by JetBrains.

the class Reference method getNodesetBeforeFirstCanonicalization.

/**
     * This method returns the XMLSignatureInput which represents the node set before
     * some kind of canonicalization is applied for the first time.
     * @return Gets a the node doing everything till the first c14n is needed
     *
     * @throws XMLSignatureException
     */
public XMLSignatureInput getNodesetBeforeFirstCanonicalization() throws XMLSignatureException {
    try {
        XMLSignatureInput input = this.getContentsBeforeTransformation();
        cacheDereferencedElement(input);
        XMLSignatureInput output = input;
        Transforms transforms = this.getTransforms();
        if (transforms != null) {
            doTransforms: for (int i = 0; i < transforms.getLength(); i++) {
                Transform t = transforms.item(i);
                String uri = t.getURI();
                if (uri.equals(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS) || uri.equals(Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS) || uri.equals(Transforms.TRANSFORM_C14N_OMIT_COMMENTS) || uri.equals(Transforms.TRANSFORM_C14N_WITH_COMMENTS)) {
                    break doTransforms;
                }
                output = t.performTransform(output, null);
            }
            output.setSourceURI(input.getSourceURI());
        }
        return output;
    } catch (IOException ex) {
        throw new XMLSignatureException("empty", ex);
    } 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) IOException(java.io.IOException) ResourceResolverException(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException) Transform(com.sun.org.apache.xml.internal.security.transforms.Transform) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Aggregations

Transform (com.sun.org.apache.xml.internal.security.transforms.Transform)4 InvalidCanonicalizerException (com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException)2 XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)2 XMLSignatureInput (com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput)2 TransformationException (com.sun.org.apache.xml.internal.security.transforms.TransformationException)2 Transforms (com.sun.org.apache.xml.internal.security.transforms.Transforms)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 Set (java.util.Set)2 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)1 InvalidTransformException (com.sun.org.apache.xml.internal.security.transforms.InvalidTransformException)1 InclusiveNamespaces (com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces)1 ResourceResolverException (com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 TransformException (javax.xml.crypto.dsig.TransformException)1