Search in sources :

Example 6 with XMLSignatureException

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

the class SignatureBaseRSA method engineInitSign.

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

Example 7 with XMLSignatureException

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

the class SignatureECDSA method engineInitSign.

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

Example 8 with XMLSignatureException

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

the class IntegrityHmac method engineSign.

/**
 * Proxy method for {@link java.security.Signature#sign()}
 * which is executed on the internal {@link java.security.Signature} object.
 *
 * @return the result of the {@link java.security.Signature#sign()} method
 * @throws XMLSignatureException
 */
protected byte[] engineSign() throws XMLSignatureException {
    try {
        if (this.HMACOutputLengthSet && this.HMACOutputLength < getDigestLength()) {
            LOG.debug("HMACOutputLength must not be less than {}", getDigestLength());
            Object[] exArgs = { String.valueOf(getDigestLength()) };
            throw new XMLSignatureException("algorithms.HMACOutputLengthMin", exArgs);
        } else {
            return this.macAlgorithm.doFinal();
        }
    } catch (IllegalStateException ex) {
        throw new XMLSignatureException(ex);
    }
}
Also used : XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException)

Example 9 with XMLSignatureException

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

the class SignatureDSA method engineInitSign.

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

Example 10 with XMLSignatureException

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

the class SignatureDSA method engineInitVerify.

/**
 * {@inheritDoc}
 */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
    if (!(publicKey instanceof PublicKey)) {
        String supplied = null;
        if (publicKey != null) {
            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) {
            // this shouldn't occur, but if it does, restore previous
            // Signature
            LOG.debug("Exception when reinstantiating Signature: {}", e);
            this.signatureAlgorithm = sig;
        }
        throw new XMLSignatureException(ex);
    }
    size = ((DSAKey) publicKey).getParams().getQ().bitLength();
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) XMLSignature(org.apache.xml.security.signature.XMLSignature) InvalidKeyException(java.security.InvalidKeyException) XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) InvalidKeyException(java.security.InvalidKeyException) XMLSignatureException(org.apache.xml.security.signature.XMLSignatureException)

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