Search in sources :

Example 6 with XMLSignatureException

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

the class SignatureDSA 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);
    }
    size = ((DSAKey) privateKey).getParams().getQ().bitLength();
}
Also used : PrivateKey(java.security.PrivateKey) InvalidKeyException(java.security.InvalidKeyException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException)

Example 7 with XMLSignatureException

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

the class SignatureDSA 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);
    }
    size = ((DSAKey) publicKey).getParams().getQ().bitLength();
}
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) IOException(java.io.IOException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) InvalidKeyException(java.security.InvalidKeyException)

Example 8 with XMLSignatureException

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

the class SignatureECDSA 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)

Example 9 with XMLSignatureException

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

the class SignatureECDSA 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) IOException(java.io.IOException) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 10 with XMLSignatureException

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

the class IntegrityHmac method engineInitVerify.

/**
     * Proxy method for {@link java.security.Signature#initVerify(java.security.PublicKey)}
     * which is executed on the internal {@link java.security.Signature} object.
     *
     * @param secretKey
     * @throws XMLSignatureException
     */
protected void engineInitVerify(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) {
        // reinstantiate Mac object to work around bug in JDK
        // see: http://bugs.sun.com/view_bug.do?bug_id=4953555
        Mac mac = this.macAlgorithm;
        try {
            this.macAlgorithm = Mac.getInstance(macAlgorithm.getAlgorithm());
        } catch (Exception e) {
            // this shouldn't occur, but if it does, restore previous Mac
            if (log.isLoggable(java.util.logging.Level.FINE)) {
                log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Mac:" + e);
            }
            this.macAlgorithm = mac;
        }
        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) Mac(javax.crypto.Mac) XMLSignatureException(com.sun.org.apache.xml.internal.security.signature.XMLSignatureException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) InvalidKeyException(java.security.InvalidKeyException)

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