Search in sources :

Example 16 with XMLSignatureException

use of org.apache.xml.security.signature.XMLSignatureException in project xades4j by luisgoncalves.

the class SignatureUtils method checkSignedPropertiesIncorporation.

static void checkSignedPropertiesIncorporation(Element qualifyingPropsElem, Reference signedPropsRef) throws QualifyingPropertiesIncorporationException {
    Element signedPropsElem = DOMHelper.getFirstChildElement(qualifyingPropsElem);
    if (signedPropsElem == null || !signedPropsElem.getLocalName().equals(QualifyingProperty.SIGNED_PROPS_TAG) || !signedPropsElem.getNamespaceURI().equals(QualifyingProperty.XADES_XMLNS)) {
        throw new QualifyingPropertiesIncorporationException("SignedProperties not found as the first child of QualifyingProperties.");
    }
    DOMHelper.useIdAsXmlId(signedPropsElem);
    // that consists of a hash sign ('#') followed by a fragment"
    if (!signedPropsRef.getURI().startsWith("#")) {
        throw new QualifyingPropertiesIncorporationException("Only QualifyingProperties in the signature's document are supported");
    }
    try {
        Node sPropsNode = signedPropsRef.getNodesetBeforeFirstCanonicalization().getSubNode();
        if (sPropsNode == null || sPropsNode.getNodeType() != Node.ELEMENT_NODE) {
            throw new QualifyingPropertiesIncorporationException("The supposed reference over signed properties doesn't cover an element.");
        }
        // The referenced signed properties element must be the child of qualifying properties.
        Element referencedSignedPropsElem = (Element) sPropsNode;
        if (referencedSignedPropsElem != signedPropsElem) {
            throw new QualifyingPropertiesIncorporationException("The referenced SignedProperties are not contained by the proper QualifyingProperties element");
        }
    } catch (XMLSignatureException ex) {
        throw new QualifyingPropertiesIncorporationException("Cannot get the referenced SignedProperties", ex);
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException)

Example 17 with XMLSignatureException

use of org.apache.xml.security.signature.XMLSignatureException in project xades4j by luisgoncalves.

the class TimeStampDigestInputImpl method addReference.

@Override
public void addReference(Reference r) throws CannotAddDataToDigestInputException {
    if (null == r) {
        throw new NullPointerException();
    }
    try {
        XMLSignatureInput refData = r.getContentsAfterTransformation();
        addToDigestInput(refData, r.getDocument());
    } catch (XMLSignatureException ex) {
        throw new CannotAddDataToDigestInputException(ex);
    }
}
Also used : XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException)

Example 18 with XMLSignatureException

use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.

the class BaltimoreTest method test_fifteen_enveloping_hmac_sha1_40.

/**
 * Method test_fifteen_enveloping_hmac_sha1_40
 *
 * @throws Exception
 */
@org.junit.Test
public void test_fifteen_enveloping_hmac_sha1_40() throws Exception {
    String filename = merlinsDir15 + "signature-enveloping-hmac-sha1-40.xml";
    ResourceResolverSpi resolver = new OfflineResolver();
    boolean followManifests = false;
    byte[] hmacKey = "secret".getBytes(StandardCharsets.US_ASCII);
    try {
        this.verifyHMAC(filename, resolver, followManifests, hmacKey);
        fail("HMACOutputLength Exception not caught");
    } catch (RuntimeException ex) {
        LOG.error("Verification crashed for " + filename);
        throw ex;
    } catch (XMLSignatureException ex) {
        if (!ex.getMsgID().equals("algorithms.HMACOutputLengthMin")) {
            fail(ex.getMessage());
        }
    }
}
Also used : ResourceResolverSpi(org.apache.xml.security.utils.resolver.ResourceResolverSpi) OfflineResolver(org.apache.xml.security.test.dom.utils.resolver.OfflineResolver) XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException)

Example 19 with XMLSignatureException

use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.

the class BaltimoreTest method test_twenty_three_enveloping_hmac_sha1_40.

/**
 * Method test_twenty_three_enveloping_hmac_sha1_40
 *
 * @throws Exception
 */
@org.junit.Test
public void test_twenty_three_enveloping_hmac_sha1_40() throws Exception {
    String filename = merlinsDir23 + "signature-enveloping-hmac-sha1-40.xml";
    ResourceResolverSpi resolver = new OfflineResolver();
    boolean followManifests = false;
    byte[] hmacKey = "secret".getBytes(StandardCharsets.US_ASCII);
    try {
        this.verifyHMAC(filename, resolver, followManifests, hmacKey);
        fail("HMACOutputLength Exception not caught");
    } catch (RuntimeException ex) {
        LOG.error("Verification crashed for " + filename);
        throw ex;
    } catch (XMLSignatureException ex) {
        if (!ex.getMsgID().equals("algorithms.HMACOutputLengthMin")) {
            fail(ex.getMessage());
        }
    }
}
Also used : ResourceResolverSpi(org.apache.xml.security.utils.resolver.ResourceResolverSpi) OfflineResolver(org.apache.xml.security.test.dom.utils.resolver.OfflineResolver) XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException)

Example 20 with XMLSignatureException

use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.

the class SignatureAlgorithm method getSignatureAlgorithmSpi.

/**
 * Get a SignatureAlgorithmSpi object corresponding to the algorithmURI argument
 */
private static SignatureAlgorithmSpi getSignatureAlgorithmSpi(String algorithmURI) throws XMLSignatureException {
    try {
        Class<? extends SignatureAlgorithmSpi> implementingClass = algorithmHash.get(algorithmURI);
        LOG.debug("Create URI \"{}\" class \"{}\"", algorithmURI, implementingClass);
        if (implementingClass == null) {
            Object[] exArgs = { algorithmURI };
            throw new XMLSignatureException("algorithms.NoSuchAlgorithmNoEx", exArgs);
        }
        return implementingClass.newInstance();
    } catch (IllegalAccessException | InstantiationException | NullPointerException ex) {
        Object[] exArgs = { algorithmURI, ex.getMessage() };
        throw new XMLSignatureException(ex, "algorithms.NoSuchAlgorithm", exArgs);
    }
}
Also used : XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException)

Aggregations

XMLSignatureException (org.apache.xml.security.signature.XMLSignatureException)28 InvalidKeyException (java.security.InvalidKeyException)8 XMLSignature (org.apache.xml.security.signature.XMLSignature)8 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)5 X509Certificate (java.security.cert.X509Certificate)5 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)5 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5 PrivateKey (java.security.PrivateKey)4 Transforms (org.apache.xml.security.transforms.Transforms)4 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)3 NoSuchProviderException (java.security.NoSuchProviderException)3 PublicKey (java.security.PublicKey)3 Signature (java.security.Signature)3 SignatureException (java.security.SignatureException)3 Reference (org.apache.xml.security.signature.Reference)3 OfflineResolver (org.apache.xml.security.test.dom.utils.resolver.OfflineResolver)3 ResourceResolverSpi (org.apache.xml.security.utils.resolver.ResourceResolverSpi)3 UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)3 IOException (java.io.IOException)2