Search in sources :

Example 1 with TransformationException

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

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

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

the class TransformEnvelopedSignature method searchSignatureElement.

/**
     * @param signatureElement
     * @return the node that is the signature
     * @throws TransformationException
     */
private static Node searchSignatureElement(Node signatureElement) throws TransformationException {
    boolean found = false;
    while (true) {
        if (signatureElement == null || signatureElement.getNodeType() == Node.DOCUMENT_NODE) {
            break;
        }
        Element el = (Element) signatureElement;
        if (el.getNamespaceURI().equals(Constants.SignatureSpecNS) && el.getLocalName().equals(Constants._TAG_SIGNATURE)) {
            found = true;
            break;
        }
        signatureElement = signatureElement.getParentNode();
    }
    if (!found) {
        throw new TransformationException("transform.envelopedSignatureTransformNotInSignatureElement");
    }
    return signatureElement;
}
Also used : TransformationException(com.sun.org.apache.xml.internal.security.transforms.TransformationException) Element(org.w3c.dom.Element)

Example 4 with TransformationException

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

the class TransformXPath method enginePerformTransform.

/**
     * Method enginePerformTransform
     * @inheritDoc
     * @param input
     *
     * @throws TransformationException
     */
protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, OutputStream os, Transform transformObject) throws TransformationException {
    try {
        /**
             * If the actual input is an octet stream, then the application MUST
             * convert the octet stream to an XPath node-set suitable for use by
             * Canonical XML with Comments. (A subsequent application of the
             * REQUIRED Canonical XML algorithm would strip away these comments.)
             *
             * ...
             *
             * The evaluation of this expression includes all of the document's nodes
             * (including comments) in the node-set representing the octet stream.
             */
        Element xpathElement = XMLUtils.selectDsNode(transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);
        if (xpathElement == null) {
            Object[] exArgs = { "ds:XPath", "Transform" };
            throw new TransformationException("xml.WrongContent", exArgs);
        }
        Node xpathnode = xpathElement.getChildNodes().item(0);
        String str = XMLUtils.getStrFromNode(xpathnode);
        input.setNeedsToBeExpanded(needsCircumvent(str));
        if (xpathnode == null) {
            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath");
        }
        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
        input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
        input.setNodeSet(true);
        return input;
    } catch (DOMException ex) {
        throw new TransformationException("empty", ex);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) XPathFactory(com.sun.org.apache.xml.internal.security.utils.XPathFactory) TransformationException(com.sun.org.apache.xml.internal.security.transforms.TransformationException) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) XPathAPI(com.sun.org.apache.xml.internal.security.utils.XPathAPI)

Example 5 with TransformationException

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

the class XMLCipherInput method getDecryptBytes.

/**
     * Internal method to get bytes in decryption mode
     * @return the decrypted bytes
     * @throws XMLEncryptionException
     */
private byte[] getDecryptBytes() throws XMLEncryptionException {
    String base64EncodedEncryptedOctets = null;
    if (cipherData.getDataType() == CipherData.REFERENCE_TYPE) {
        // Fun time!
        if (logger.isLoggable(java.util.logging.Level.FINE)) {
            logger.log(java.util.logging.Level.FINE, "Found a reference type CipherData");
        }
        CipherReference cr = cipherData.getCipherReference();
        // Need to wrap the uri in an Attribute node so that we can
        // Pass to the resource resolvers
        Attr uriAttr = cr.getURIAsAttr();
        XMLSignatureInput input = null;
        try {
            ResourceResolver resolver = ResourceResolver.getInstance(uriAttr, null, secureValidation);
            input = resolver.resolve(uriAttr, null, secureValidation);
        } catch (ResourceResolverException ex) {
            throw new XMLEncryptionException("empty", ex);
        }
        if (input != null) {
            if (logger.isLoggable(java.util.logging.Level.FINE)) {
                logger.log(java.util.logging.Level.FINE, "Managed to resolve URI \"" + cr.getURI() + "\"");
            }
        } else {
            if (logger.isLoggable(java.util.logging.Level.FINE)) {
                logger.log(java.util.logging.Level.FINE, "Failed to resolve URI \"" + cr.getURI() + "\"");
            }
        }
        // Lets see if there are any transforms
        Transforms transforms = cr.getTransforms();
        if (transforms != null) {
            if (logger.isLoggable(java.util.logging.Level.FINE)) {
                logger.log(java.util.logging.Level.FINE, "Have transforms in cipher reference");
            }
            try {
                com.sun.org.apache.xml.internal.security.transforms.Transforms dsTransforms = transforms.getDSTransforms();
                dsTransforms.setSecureValidation(secureValidation);
                input = dsTransforms.performTransforms(input);
            } catch (TransformationException ex) {
                throw new XMLEncryptionException("empty", ex);
            }
        }
        try {
            return input.getBytes();
        } catch (IOException ex) {
            throw new XMLEncryptionException("empty", ex);
        } catch (CanonicalizationException ex) {
            throw new XMLEncryptionException("empty", ex);
        }
    // retrieve the cipher text
    } else if (cipherData.getDataType() == CipherData.VALUE_TYPE) {
        base64EncodedEncryptedOctets = cipherData.getCipherValue().getValue();
    } else {
        throw new XMLEncryptionException("CipherData.getDataType() returned unexpected value");
    }
    if (logger.isLoggable(java.util.logging.Level.FINE)) {
        logger.log(java.util.logging.Level.FINE, "Encrypted octets:\n" + base64EncodedEncryptedOctets);
    }
    try {
        return Base64.decode(base64EncodedEncryptedOctets);
    } catch (Base64DecodingException bde) {
        throw new XMLEncryptionException("empty", bde);
    }
}
Also used : TransformationException(com.sun.org.apache.xml.internal.security.transforms.TransformationException) CanonicalizationException(com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) ResourceResolverException(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException) IOException(java.io.IOException) Attr(org.w3c.dom.Attr) Base64DecodingException(com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException) ResourceResolver(com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver)

Aggregations

TransformationException (com.sun.org.apache.xml.internal.security.transforms.TransformationException)9 XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)5 Element (org.w3c.dom.Element)5 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)4 IOException (java.io.IOException)4 InvalidCanonicalizerException (com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException)3 XMLSignatureInput (com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput)3 Transforms (com.sun.org.apache.xml.internal.security.transforms.Transforms)3 ResourceResolverException (com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException)3 Base64DecodingException (com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException)2 Transform (com.sun.org.apache.xml.internal.security.transforms.Transform)2 XPathAPI (com.sun.org.apache.xml.internal.security.utils.XPathAPI)2 XPathFactory (com.sun.org.apache.xml.internal.security.utils.XPathFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 DOMException (org.w3c.dom.DOMException)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 SAXException (org.xml.sax.SAXException)2 InvalidTransformException (com.sun.org.apache.xml.internal.security.transforms.InvalidTransformException)1