Search in sources :

Example 1 with XMLX509Digest

use of org.apache.xml.security.keys.content.x509.XMLX509Digest in project santuario-java by apache.

the class X509DigestResolver method resolveCertificate.

/**
 * Resolves from the storage resolver the actual certificate represented by the digest.
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return the certificate represented by the digest.
 * @throws XMLSecurityException
 */
private X509Certificate resolveCertificate(Element element, String baseURI, StorageResolver storage) throws XMLSecurityException {
    XMLX509Digest[] x509Digests = null;
    Element[] x509childNodes = XMLUtils.selectDs11Nodes(element.getFirstChild(), Constants._TAG_X509DIGEST);
    if (x509childNodes == null || x509childNodes.length <= 0) {
        return null;
    }
    try {
        checkStorage(storage);
        x509Digests = new XMLX509Digest[x509childNodes.length];
        for (int i = 0; i < x509childNodes.length; i++) {
            x509Digests[i] = new XMLX509Digest(x509childNodes[i], baseURI);
        }
        Iterator<Certificate> storageIterator = storage.getIterator();
        while (storageIterator.hasNext()) {
            X509Certificate cert = (X509Certificate) storageIterator.next();
            for (int i = 0; i < x509Digests.length; i++) {
                XMLX509Digest keyInfoDigest = x509Digests[i];
                byte[] certDigestBytes = XMLX509Digest.getDigestBytesFromCert(cert, keyInfoDigest.getAlgorithm());
                if (Arrays.equals(keyInfoDigest.getDigestBytes(), certDigestBytes)) {
                    LOG.debug("Found certificate with: {}", cert.getSubjectX500Principal().getName());
                    return cert;
                }
            }
        }
    } catch (XMLSecurityException ex) {
        throw new KeyResolverException(ex);
    }
    return null;
}
Also used : XMLX509Digest(org.apache.xml.security.keys.content.x509.XMLX509Digest) Element(org.w3c.dom.Element) KeyResolverException(org.apache.xml.security.keys.keyresolver.KeyResolverException) X509Certificate(java.security.cert.X509Certificate) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 2 with XMLX509Digest

use of org.apache.xml.security.keys.content.x509.XMLX509Digest in project santuario-java by apache.

the class XMLX509DigestTest method testDigestOnConstructionWithBytes.

@org.junit.Test
public void testDigestOnConstructionWithBytes() throws Exception {
    XMLX509Digest x509Digest = new XMLX509Digest(documentBuilder.newDocument(), digestControl, algorithmURIControl);
    assertEquals(algorithmURIControl, x509Digest.getAlgorithm());
    assertArrayEquals(digestControl, x509Digest.getDigestBytes());
}
Also used : XMLX509Digest(org.apache.xml.security.keys.content.x509.XMLX509Digest)

Example 3 with XMLX509Digest

use of org.apache.xml.security.keys.content.x509.XMLX509Digest in project santuario-java by apache.

the class XMLX509DigestTest method testSchema.

@org.junit.Test
public void testSchema() throws Exception {
    XMLX509Digest x509Digest = new XMLX509Digest(documentBuilder.newDocument(), digestControl, algorithmURIControl);
    Element element = x509Digest.getElement();
    assertEquals("http://www.w3.org/2009/xmldsig11#", element.getNamespaceURI());
    assertEquals("X509Digest", element.getLocalName());
}
Also used : XMLX509Digest(org.apache.xml.security.keys.content.x509.XMLX509Digest) Element(org.w3c.dom.Element)

Example 4 with XMLX509Digest

use of org.apache.xml.security.keys.content.x509.XMLX509Digest in project santuario-java by apache.

the class XMLX509DigestTest method testDigestFromElement.

@org.junit.Test
public void testDigestFromElement() throws Exception {
    Document doc = loadXML("X509Digest.xml");
    NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_X509DIGEST);
    Element element = (Element) nl.item(0);
    XMLX509Digest x509Digest = new XMLX509Digest(element, "");
    assertEquals(algorithmURIControl, x509Digest.getAlgorithm());
    assertArrayEquals(digestControl, x509Digest.getDigestBytes());
}
Also used : XMLX509Digest(org.apache.xml.security.keys.content.x509.XMLX509Digest) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 5 with XMLX509Digest

use of org.apache.xml.security.keys.content.x509.XMLX509Digest in project jdk8u_jdk by JetBrains.

the class X509DigestResolver method resolveCertificate.

/**
     * Resolves from the storage resolver the actual certificate represented by the digest.
     *
     * @param element
     * @param baseURI
     * @param storage
     * @return
     * @throws XMLSecurityException
     */
private X509Certificate resolveCertificate(Element element, String baseURI, StorageResolver storage) throws XMLSecurityException {
    XMLX509Digest[] x509Digests = null;
    Element[] x509childNodes = XMLUtils.selectDs11Nodes(element.getFirstChild(), Constants._TAG_X509DIGEST);
    if (x509childNodes == null || x509childNodes.length <= 0) {
        return null;
    }
    try {
        checkStorage(storage);
        x509Digests = new XMLX509Digest[x509childNodes.length];
        for (int i = 0; i < x509childNodes.length; i++) {
            x509Digests[i] = new XMLX509Digest(x509childNodes[i], baseURI);
        }
        Iterator<Certificate> storageIterator = storage.getIterator();
        while (storageIterator.hasNext()) {
            X509Certificate cert = (X509Certificate) storageIterator.next();
            for (int i = 0; i < x509Digests.length; i++) {
                XMLX509Digest keyInfoDigest = x509Digests[i];
                byte[] certDigestBytes = XMLX509Digest.getDigestBytesFromCert(cert, keyInfoDigest.getAlgorithm());
                if (Arrays.equals(keyInfoDigest.getDigestBytes(), certDigestBytes)) {
                    if (log.isLoggable(java.util.logging.Level.FINE)) {
                        log.log(java.util.logging.Level.FINE, "Found certificate with: " + cert.getSubjectX500Principal().getName());
                    }
                    return cert;
                }
            }
        }
    } catch (XMLSecurityException ex) {
        throw new KeyResolverException("empty", ex);
    }
    return null;
}
Also used : XMLX509Digest(com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Digest) Element(org.w3c.dom.Element) KeyResolverException(com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException) X509Certificate(java.security.cert.X509Certificate) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

XMLX509Digest (org.apache.xml.security.keys.content.x509.XMLX509Digest)5 Element (org.w3c.dom.Element)4 Certificate (java.security.cert.Certificate)2 X509Certificate (java.security.cert.X509Certificate)2 XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)1 XMLX509Digest (com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Digest)1 KeyResolverException (com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 KeyResolverException (org.apache.xml.security.keys.keyresolver.KeyResolverException)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1