Search in sources :

Example 1 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 2 with XMLSignatureException

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

the class MessageDigestAlgorithm method getDigestInstance.

private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
    String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
    if (algorithmID == null) {
        Object[] exArgs = { algorithmURI };
        throw new XMLSignatureException("algorithms.NoSuchMap", exArgs);
    }
    MessageDigest md;
    String provider = JCEMapper.getProviderId();
    try {
        if (provider == null) {
            md = MessageDigest.getInstance(algorithmID);
        } else {
            md = MessageDigest.getInstance(algorithmID, provider);
        }
    } catch (java.security.NoSuchAlgorithmException ex) {
        Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
    } catch (NoSuchProviderException ex) {
        Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
    }
    return md;
}
Also used : MessageDigest(java.security.MessageDigest) NoSuchProviderException(java.security.NoSuchProviderException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)

Example 3 with XMLSignatureException

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

the class SignatureBaseRSA method engineInitSign.

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

Example 4 with XMLSignatureException

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

the class SignatureBaseRSA method engineInitVerify.

/** @inheritDoc */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
    if (!(publicKey instanceof PublicKey)) {
        String supplied = publicKey.getClass().getName();
        String needed = PublicKey.class.getName();
        Object[] exArgs = { supplied, needed };
        throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
    }
    try {
        this.signatureAlgorithm.initVerify((PublicKey) publicKey);
    } catch (InvalidKeyException ex) {
        // reinstantiate Signature object to work around bug in JDK
        // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
        Signature sig = this.signatureAlgorithm;
        try {
            this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
        } catch (Exception e) {
            // Signature
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
            }
            this.signatureAlgorithm = sig;
        }
        throw new XMLSignatureException("empty", ex);
    }
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) XMLSignature(com.sun.org.apache.xml.internal.security.signature.XMLSignature) InvalidKeyException(java.security.InvalidKeyException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException) SignatureException(java.security.SignatureException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 5 with XMLSignatureException

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

the class SignatureBaseRSA method engineInitSign.

/** @inheritDoc */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom) throws XMLSignatureException {
    if (!(privateKey instanceof PrivateKey)) {
        String supplied = privateKey.getClass().getName();
        String needed = PrivateKey.class.getName();
        Object[] exArgs = { supplied, needed };
        throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
    }
    try {
        this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
    } catch (InvalidKeyException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
Also used : PrivateKey(java.security.PrivateKey) 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