Search in sources :

Example 26 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException in project jdk8u_jdk by JetBrains.

the class X509IssuerSerialResolver method engineLookupResolveX509Certificate.

/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }
    X509Data x509data = null;
    try {
        x509data = new X509Data(element, baseURI);
    } catch (XMLSignatureException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "I can't");
        }
        return null;
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "I can't");
        }
        return null;
    }
    if (!x509data.containsIssuerSerial()) {
        return null;
    }
    try {
        if (storage == null) {
            Object[] exArgs = { Constants._TAG_X509ISSUERSERIAL };
            KeyResolverException ex = new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "", ex);
            }
            throw ex;
        }
        int noOfISS = x509data.lengthIssuerSerial();
        Iterator<Certificate> storageIterator = storage.getIterator();
        while (storageIterator.hasNext()) {
            X509Certificate cert = (X509Certificate) storageIterator.next();
            XMLX509IssuerSerial certSerial = new XMLX509IssuerSerial(element.getOwnerDocument(), cert);
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "Found Certificate Issuer: " + certSerial.getIssuerName());
                log.log(java.util.logging.Level.FINE, "Found Certificate Serial: " + certSerial.getSerialNumber().toString());
            }
            for (int i = 0; i < noOfISS; i++) {
                XMLX509IssuerSerial xmliss = x509data.itemIssuerSerial(i);
                if (log.isLoggable(java.util.logging.Level.FINE)) {
                    log.log(java.util.logging.Level.FINE, "Found Element Issuer:     " + xmliss.getIssuerName());
                    log.log(java.util.logging.Level.FINE, "Found Element Serial:     " + xmliss.getSerialNumber().toString());
                }
                if (certSerial.equals(xmliss)) {
                    if (log.isLoggable(java.util.logging.Level.FINE)) {
                        log.log(java.util.logging.Level.FINE, "match !!! ");
                    }
                    return cert;
                }
                if (log.isLoggable(java.util.logging.Level.FINE)) {
                    log.log(java.util.logging.Level.FINE, "no match...");
                }
            }
        }
        return null;
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
        }
        throw new KeyResolverException("generic.EmptyMessage", ex);
    }
}
Also used : KeyResolverException(com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException) XMLX509IssuerSerial(com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509IssuerSerial) X509Data(com.sun.org.apache.xml.internal.security.keys.content.X509Data) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 27 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException in project jdk8u_jdk by JetBrains.

the class Manifest method getVerificationResult.

/**
     * After verifying a {@link Manifest} or a {@link SignedInfo} using the
     * {@link Manifest#verifyReferences()} or {@link SignedInfo#verify()} methods,
     * the individual results can be retrieved with this method.
     *
     * @param index an index of into a {@link Manifest} or a {@link SignedInfo}
     * @return the results of reference validation at the specified index
     * @throws XMLSecurityException
     */
public boolean getVerificationResult(int index) throws XMLSecurityException {
    if ((index < 0) || (index > this.getLength() - 1)) {
        Object[] exArgs = { Integer.toString(index), Integer.toString(this.getLength()) };
        Exception e = new IndexOutOfBoundsException(I18n.translate("signature.Verification.IndexOutOfBounds", exArgs));
        throw new XMLSecurityException("generic.EmptyMessage", e);
    }
    if (this.verificationResults == null) {
        try {
            this.verifyReferences();
        } catch (Exception ex) {
            throw new XMLSecurityException("generic.EmptyMessage", ex);
        }
    }
    return this.verificationResults[index];
}
Also used : IOException(java.io.IOException) InvalidCanonicalizerException(com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException) CanonicalizationException(com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DOMException(org.w3c.dom.DOMException) SAXException(org.xml.sax.SAXException) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Example 28 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException 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 29 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException 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 30 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException in project jdk8u_jdk by JetBrains.

the class TransformC14NExclusive method enginePerformTransform.

protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, OutputStream os, Transform transformObject) throws CanonicalizationException {
    try {
        String inclusiveNamespaces = null;
        if (transformObject.length(InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1) {
            Element inclusiveElement = XMLUtils.selectNode(transformObject.getElement().getFirstChild(), InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES, 0);
            inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement, transformObject.getBaseURI()).getInclusiveNamespaces();
        }
        Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
        if (os != null) {
            c14n.setWriter(os);
        }
        byte[] result = c14n.engineCanonicalize(input, inclusiveNamespaces);
        XMLSignatureInput output = new XMLSignatureInput(result);
        if (os != null) {
            output.setOutputStream(os);
        }
        return output;
    } catch (XMLSecurityException ex) {
        throw new CanonicalizationException("empty", ex);
    }
}
Also used : CanonicalizationException(com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException) Element(org.w3c.dom.Element) InclusiveNamespaces(com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces) XMLSignatureInput(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput) Canonicalizer20010315ExclOmitComments(com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Aggregations

XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)32 Element (org.w3c.dom.Element)15 IOException (java.io.IOException)11 X509Certificate (java.security.cert.X509Certificate)9 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)8 KeyResolverException (com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException)8 PublicKey (java.security.PublicKey)7 XMLSignatureInput (com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput)6 Certificate (java.security.cert.Certificate)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6 SAXException (org.xml.sax.SAXException)6 InvalidCanonicalizerException (com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException)5 XMLX509Certificate (com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Certificate)5 TransformationException (com.sun.org.apache.xml.internal.security.transforms.TransformationException)5 Transforms (com.sun.org.apache.xml.internal.security.transforms.Transforms)4 InclusiveNamespaces (com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces)4 XMLX509SKI (com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI)3 UnsyncBufferedOutputStream (com.sun.org.apache.xml.internal.security.utils.UnsyncBufferedOutputStream)3 OutputStream (java.io.OutputStream)3 KeyFactory (java.security.KeyFactory)3