use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class SignatureBaseRSA 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);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
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 = null;
if (secretKey != null) {
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
LOG.debug("Exception when reinstantiating Mac: {}", e);
this.macAlgorithm = mac;
}
throw new XMLSignatureException(ex);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class IntegrityHmac method engineInitSign.
/**
* Method engineInitSign
*
* @param secretKey
* @param algorithmParameterSpec
* @throws XMLSignatureException
*/
protected void engineInitSign(Key secretKey, AlgorithmParameterSpec algorithmParameterSpec) throws XMLSignatureException {
if (!(secretKey instanceof SecretKey)) {
String supplied = null;
if (secretKey != null) {
supplied = secretKey.getClass().getName();
}
String needed = SecretKey.class.getName();
Object[] exArgs = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
if (algorithmParameterSpec == null) {
this.macAlgorithm.init(secretKey);
} else {
this.macAlgorithm.init(secretKey, algorithmParameterSpec);
}
} catch (InvalidKeyException ex) {
throw new XMLSignatureException(ex);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException(ex);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class IntegrityHmac method engineVerify.
/**
* Proxy method for {@link java.security.Signature#verify(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param signature
* @return true if the signature is correct
* @throws XMLSignatureException
*/
protected boolean engineVerify(byte[] signature) 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 {
byte[] completeResult = this.macAlgorithm.doFinal();
return MessageDigestAlgorithm.isEqual(completeResult, signature);
}
} catch (IllegalStateException ex) {
throw new XMLSignatureException(ex);
}
}
use of org.apache.xml.security.signature.XMLSignatureException in project santuario-java by apache.
the class SignatureECDSA 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);
}
}
Aggregations