Search in sources :

Example 11 with XMLSignatureException

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

the class TruncateHMAC method generate_hmac_sha1_40.

private static void generate_hmac_sha1_40() throws Exception {
    System.out.println("Generating ");
    Document doc = dbf.newDocumentBuilder().newDocument();
    XMLSignature sig = new XMLSignature(doc, null, XMLSignature.ALGO_ID_MAC_HMAC_SHA1, 40, Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
    try {
        sig.sign(getSecretKey("secret".getBytes("ASCII")));
        System.out.println("FAILED");
        atLeastOneFailed = true;
    } catch (XMLSignatureException xse) {
        System.out.println(xse.getMessage());
        System.out.println("PASSED");
    }
}
Also used : XMLSignature(com.sun.org.apache.xml.internal.security.signature.XMLSignature) Document(org.w3c.dom.Document) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)

Example 12 with XMLSignatureException

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

the class TruncateHMAC method validate.

private static void validate(String data, boolean pass) throws Exception {
    System.out.println("Validating " + data);
    File file = new File(DIR, data);
    Document doc = dbf.newDocumentBuilder().parse(file);
    NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature");
    if (nl.getLength() == 0) {
        throw new Exception("Couldn't find signature Element");
    }
    Element sigElement = (Element) nl.item(0);
    XMLSignature signature = new XMLSignature(sigElement, file.toURI().toString());
    SecretKey sk = signature.createSecretKey("secret".getBytes("ASCII"));
    try {
        System.out.println("Validation status: " + signature.checkSignatureValue(sk));
        if (!pass) {
            System.out.println("FAILED");
            atLeastOneFailed = true;
        } else {
            System.out.println("PASSED");
        }
    } catch (XMLSignatureException xse) {
        System.out.println(xse.getMessage());
        if (!pass) {
            System.out.println("PASSED");
        } else {
            System.out.println("FAILED");
            atLeastOneFailed = true;
        }
    }
}
Also used : SecretKey(javax.crypto.SecretKey) XMLSignature(com.sun.org.apache.xml.internal.security.signature.XMLSignature) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) File(java.io.File) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)

Example 13 with XMLSignatureException

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

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

the class SignatureAlgorithm method register.

/**
     * Registers implementing class of the SignatureAlgorithm with algorithmURI
     *
     * @param algorithmURI algorithmURI URI representation of <code>SignatureAlgorithm</code>.
     * @param implementingClass <code>implementingClass</code> the implementing class of
     * {@link SignatureAlgorithmSpi}
     * @throws AlgorithmAlreadyRegisteredException if specified algorithmURI is already registered
     * @throws XMLSignatureException
     * @throws SecurityException if a security manager is installed and the
     *    caller does not have permission to register the signature algorithm
     */
@SuppressWarnings("unchecked")
public static void register(String algorithmURI, String implementingClass) throws AlgorithmAlreadyRegisteredException, ClassNotFoundException, XMLSignatureException {
    JavaUtils.checkRegisterPermission();
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Try to register " + algorithmURI + " " + implementingClass);
    }
    // are we already registered?
    Class<? extends SignatureAlgorithmSpi> registeredClass = algorithmHash.get(algorithmURI);
    if (registeredClass != null) {
        Object[] exArgs = { algorithmURI, registeredClass };
        throw new AlgorithmAlreadyRegisteredException("algorithm.alreadyRegistered", exArgs);
    }
    try {
        Class<? extends SignatureAlgorithmSpi> clazz = (Class<? extends SignatureAlgorithmSpi>) ClassLoaderUtils.loadClass(implementingClass, SignatureAlgorithm.class);
        algorithmHash.put(algorithmURI, clazz);
    } catch (NullPointerException ex) {
        Object[] exArgs = { algorithmURI, ex.getMessage() };
        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs, ex);
    }
}
Also used : AlgorithmAlreadyRegisteredException(com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)

Example 15 with XMLSignatureException

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

the class IntegrityHmac method engineInitSign.

/**
     * Method engineInitSign
     *
     * @param secretKey
     * @throws XMLSignatureException
     */
protected void engineInitSign(Key secretKey) throws XMLSignatureException {
    if (!(secretKey instanceof SecretKey)) {
        String supplied = secretKey.getClass().getName();
        String needed = SecretKey.class.getName();
        Object[] exArgs = { supplied, needed };
        throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
    }
    try {
        this.macAlgorithm.init(secretKey);
    } catch (InvalidKeyException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
Also used : SecretKey(javax.crypto.SecretKey) InvalidKeyException(java.security.InvalidKeyException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)

Aggregations

XMLSignatureException (com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)17 InvalidKeyException (java.security.InvalidKeyException)12 PrivateKey (java.security.PrivateKey)6 XMLSignature (com.sun.org.apache.xml.internal.security.signature.XMLSignature)5 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)5 SecretKey (javax.crypto.SecretKey)4 NoSuchProviderException (java.security.NoSuchProviderException)3 PublicKey (java.security.PublicKey)3 Signature (java.security.Signature)3 SignatureException (java.security.SignatureException)3 IOException (java.io.IOException)2 Document (org.w3c.dom.Document)2 AlgorithmAlreadyRegisteredException (com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException)1 XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)1 X509Data (com.sun.org.apache.xml.internal.security.keys.content.X509Data)1 XMLX509IssuerSerial (com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509IssuerSerial)1 KeyResolverException (com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException)1 File (java.io.File)1 MessageDigest (java.security.MessageDigest)1 Certificate (java.security.cert.Certificate)1