Search in sources :

Example 1 with Transforms

use of com.sun.org.apache.xml.internal.security.transforms.Transforms 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 2 with Transforms

use of com.sun.org.apache.xml.internal.security.transforms.Transforms 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 3 with Transforms

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

the class Reference method calculateDigest.

/**
     * Method calculateDigest
     *
     * @param validating true if validating the reference
     * @return reference Calculate the digest of this reference.
     * @throws ReferenceNotInitializedException
     * @throws XMLSignatureException
     */
private byte[] calculateDigest(boolean validating) throws ReferenceNotInitializedException, XMLSignatureException {
    OutputStream os = null;
    try {
        MessageDigestAlgorithm mda = this.getMessageDigestAlgorithm();
        mda.reset();
        DigesterOutputStream diOs = new DigesterOutputStream(mda);
        os = new UnsyncBufferedOutputStream(diOs);
        XMLSignatureInput output = this.dereferenceURIandPerformTransforms(os);
        // C14N11 transform if needed
        if (Reference.useC14N11 && !validating && !output.isOutputStreamSet() && !output.isOctetStream()) {
            if (transforms == null) {
                transforms = new Transforms(this.doc);
                transforms.setSecureValidation(secureValidation);
                this.constructionElement.insertBefore(transforms.getElement(), digestMethodElem);
            }
            transforms.addTransform(Transforms.TRANSFORM_C14N11_OMIT_COMMENTS);
            output.updateOutputStream(os, true);
        } else {
            output.updateOutputStream(os);
        }
        os.flush();
        if (output.getOctetStreamReal() != null) {
            output.getOctetStreamReal().close();
        }
        return diOs.getDigestValue();
    } catch (XMLSecurityException ex) {
        throw new ReferenceNotInitializedException("empty", ex);
    } catch (IOException ex) {
        throw new ReferenceNotInitializedException("empty", ex);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException ex) {
                throw new ReferenceNotInitializedException("empty", ex);
            }
        }
    }
}
Also used : UnsyncBufferedOutputStream(com.sun.org.apache.xml.internal.security.utils.UnsyncBufferedOutputStream) OutputStream(java.io.OutputStream) DigesterOutputStream(com.sun.org.apache.xml.internal.security.utils.DigesterOutputStream) Transforms(com.sun.org.apache.xml.internal.security.transforms.Transforms) MessageDigestAlgorithm(com.sun.org.apache.xml.internal.security.algorithms.MessageDigestAlgorithm) DigesterOutputStream(com.sun.org.apache.xml.internal.security.utils.DigesterOutputStream) IOException(java.io.IOException) UnsyncBufferedOutputStream(com.sun.org.apache.xml.internal.security.utils.UnsyncBufferedOutputStream) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Example 4 with Transforms

use of com.sun.org.apache.xml.internal.security.transforms.Transforms 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)

Example 5 with Transforms

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

the class RetrievalMethodResolver method resolveInput.

/**
     * Resolves the input from the given retrieval method
     * @return
     * @throws XMLSecurityException
     */
private static XMLSignatureInput resolveInput(RetrievalMethod rm, String baseURI, boolean secureValidation) throws XMLSecurityException {
    Attr uri = rm.getURIAttr();
    // Apply the transforms
    Transforms transforms = rm.getTransforms();
    ResourceResolver resRes = ResourceResolver.getInstance(uri, baseURI, secureValidation);
    XMLSignatureInput resource = resRes.resolve(uri, baseURI, secureValidation);
    if (transforms != null) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "We have Transforms");
        }
        resource = transforms.performTransforms(resource);
    }
    return resource;
}
Also used : Transforms(com.sun.org.apache.xml.internal.security.transforms.Transforms) ResourceResolver(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) Attr(org.w3c.dom.Attr)

Aggregations

Transforms (com.sun.org.apache.xml.internal.security.transforms.Transforms)5 XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)4 TransformationException (com.sun.org.apache.xml.internal.security.transforms.TransformationException)3 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)2 InvalidCanonicalizerException (com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException)2 Transform (com.sun.org.apache.xml.internal.security.transforms.Transform)2 ResourceResolverException (com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException)2 IOException (java.io.IOException)2 MessageDigestAlgorithm (com.sun.org.apache.xml.internal.security.algorithms.MessageDigestAlgorithm)1 XMLSignatureInput (com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput)1 InvalidTransformException (com.sun.org.apache.xml.internal.security.transforms.InvalidTransformException)1 InclusiveNamespaces (com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces)1 DigesterOutputStream (com.sun.org.apache.xml.internal.security.utils.DigesterOutputStream)1 UnsyncBufferedOutputStream (com.sun.org.apache.xml.internal.security.utils.UnsyncBufferedOutputStream)1 ResourceResolver (com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 Attr (org.w3c.dom.Attr)1