Search in sources :

Example 26 with XMLSignatureException

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

the class X509IssuerSerialResolver method engineLookupResolveX509Certificate.

/**
 * {@inheritDoc}
 */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage) throws KeyResolverException {
    LOG.debug("Can I resolve {}?", element.getTagName());
    X509Data x509data = null;
    try {
        x509data = new X509Data(element, baseURI);
    } catch (XMLSignatureException ex) {
        LOG.debug("I can't");
        return null;
    } catch (XMLSecurityException ex) {
        LOG.debug("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);
            LOG.debug("", 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);
            LOG.debug("Found Certificate Issuer: {}", certSerial.getIssuerName());
            LOG.debug("Found Certificate Serial: {}", certSerial.getSerialNumber().toString());
            for (int i = 0; i < noOfISS; i++) {
                XMLX509IssuerSerial xmliss = x509data.itemIssuerSerial(i);
                LOG.debug("Found Element Issuer:     {}", xmliss.getIssuerName());
                LOG.debug("Found Element Serial:     {}", xmliss.getSerialNumber().toString());
                if (certSerial.equals(xmliss)) {
                    LOG.debug("match !!! ");
                    return cert;
                }
                LOG.debug("no match...");
            }
        }
        return null;
    } catch (XMLSecurityException ex) {
        LOG.debug("XMLSecurityException", ex);
        throw new KeyResolverException(ex);
    }
}
Also used : KeyResolverException(org.apache.xml.security.keys.keyresolver.KeyResolverException) XMLX509IssuerSerial(org.apache.xml.security.keys.content.x509.XMLX509IssuerSerial) X509Data(org.apache.xml.security.keys.content.X509Data) XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 27 with XMLSignatureException

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

the class IAIKTest method test_signatureAlgorithms_signatures_hMACShortSignature.

/**
 * Method test_signatureAlgorithms_signatures_hMACShortSignature
 *
 * @throws Exception
 */
@org.junit.Test
public void test_signatureAlgorithms_signatures_hMACShortSignature() throws Exception {
    String filename = gregorsDir + "signatureAlgorithms/signatures/hMACShortSignature.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 28 with XMLSignatureException

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

the class Bug45961Test method testBug.

@org.junit.Test
public void testBug() throws Exception {
    Document document = getSignedDocument();
    NodeList list = document.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE);
    Element element = (Element) list.item(0);
    XMLSignature signature = new XMLSignature(element, null);
    KeyInfo keyInfo = signature.getKeyInfo();
    X509Certificate certificate = keyInfo.getX509Certificate();
    assertNotNull(certificate);
    try {
        signature.checkSignatureValue(certificate);
    } catch (XMLSignatureException e) {
        fail(e.getMessage());
    }
}
Also used : KeyInfo(org.apache.xml.security.keys.KeyInfo) XMLSignature(org.apache.xml.security.signature.XMLSignature) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException) X509Certificate(java.security.cert.X509Certificate)

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