Search in sources :

Example 11 with XMLSignatureInput

use of com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput in project jdk8u_jdk by JetBrains.

the class TransformC14N11_WithComments method enginePerformTransform.

protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, OutputStream os, Transform transform) throws CanonicalizationException {
    Canonicalizer11_WithComments c14n = new Canonicalizer11_WithComments();
    if (os != null) {
        c14n.setWriter(os);
    }
    byte[] result = null;
    result = c14n.engineCanonicalize(input);
    XMLSignatureInput output = new XMLSignatureInput(result);
    if (os != null) {
        output.setOutputStream(os);
    }
    return output;
}
Also used : XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) Canonicalizer11_WithComments(com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer11_WithComments)

Example 12 with XMLSignatureInput

use of com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput 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 13 with XMLSignatureInput

use of com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput 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 14 with XMLSignatureInput

use of com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput 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 15 with XMLSignatureInput

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

XMLSignatureInput (com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput)24 Element (org.w3c.dom.Element)11 XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)6 IOException (java.io.IOException)6 Node (org.w3c.dom.Node)6 ResourceResolverException (com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException)5 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)4 ResourceResolver (com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 Attr (org.w3c.dom.Attr)4 SAXException (org.xml.sax.SAXException)4 Base64DecodingException (com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException)3 TransformationException (com.sun.org.apache.xml.internal.security.transforms.TransformationException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 URISyntaxException (java.net.URISyntaxException)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 InvalidCanonicalizerException (com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException)2 RetrievalMethod (com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod)2 Transform (com.sun.org.apache.xml.internal.security.transforms.Transform)2 InclusiveNamespaces (com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces)2