You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2011/02/17 11:47:09 UTC
svn commit: r1071567 - in
/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations:
IntegrityHmac.java SignatureBaseRSA.java SignatureDSA.java
SignatureECDSA.java
Author: coheigea
Date: Thu Feb 17 10:47:08 2011
New Revision: 1071567
URL: http://svn.apache.org/viewvc?rev=1071567&view=rev
Log:
[SANTUARIO-259] - Algorithm implementation cleanup.
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/IntegrityHmac.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureBaseRSA.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureDSA.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/IntegrityHmac.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/IntegrityHmac.java?rev=1071567&r1=1071566&r2=1071567&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/IntegrityHmac.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/IntegrityHmac.java Thu Feb 17 10:47:08 2011
@@ -36,571 +36,498 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
-/**
- *
- * @author $Author$
- */
public abstract class IntegrityHmac extends SignatureAlgorithmSpi {
-
- /** {@link org.apache.commons.logging} logging facility */
- static org.apache.commons.logging.Log log =
+
+ /** {@link org.apache.commons.logging} logging facility */
+ private static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(IntegrityHmacSHA1.class.getName());
- /**
- * Method engineGetURI
- *
- *@inheritDoc
- */
- public abstract String engineGetURI();
-
- /**
- * Returns the output length of the hash/digest.
- */
- abstract int getDigestLength();
-
- /** Field _macAlgorithm */
- private Mac _macAlgorithm = null;
-
- /** Field _HMACOutputLength */
- int _HMACOutputLength = 0;
- private boolean _HMACOutputLengthSet = false;
-
- /**
- * Method IntegrityHmacSHA1das
- *
- * @throws XMLSignatureException
- */
- public IntegrityHmac() throws XMLSignatureException {
-
- String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
- if (log.isDebugEnabled())
- log.debug("Created IntegrityHmacSHA1 using " + algorithmID);
-
- try {
- this._macAlgorithm = Mac.getInstance(algorithmID);
- } catch (java.security.NoSuchAlgorithmException ex) {
- Object[] exArgs = { algorithmID,
- ex.getLocalizedMessage() };
-
- throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
- }
- }
-
- /**
- * Proxy method for {@link java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec)}
- * which is executed on the internal {@link java.security.Signature} object.
- *
- * @param params
- * @throws XMLSignatureException
- */
- protected void engineSetParameter(AlgorithmParameterSpec params)
- throws XMLSignatureException {
- throw new XMLSignatureException("empty");
- }
-
- public void reset() {
- _HMACOutputLength=0;
- _HMACOutputLengthSet = false;
- this._macAlgorithm.reset();
- }
-
- /**
- * 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())
-{
- if (log.isDebugEnabled()) {
- log.debug("HMACOutputLength must not be less than " + getDigestLength());
+ /** Field macAlgorithm */
+ private Mac macAlgorithm = null;
+
+ /** Field HMACOutputLength */
+ int HMACOutputLength = 0;
+ private boolean HMACOutputLengthSet = false;
+
+ /**
+ * Method engineGetURI
+ *
+ *@inheritDoc
+ */
+ public abstract String engineGetURI();
+
+ /**
+ * Returns the output length of the hash/digest.
+ */
+ abstract int getDigestLength();
+
+ /**
+ * Method IntegrityHmac
+ *
+ * @throws XMLSignatureException
+ */
+ public IntegrityHmac() throws XMLSignatureException {
+ String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+ if (log.isDebugEnabled()) {
+ log.debug("Created IntegrityHmacSHA1 using " + algorithmID);
+ }
+
+ try {
+ this.macAlgorithm = Mac.getInstance(algorithmID);
+ } catch (java.security.NoSuchAlgorithmException ex) {
+ Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
+
+ throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
+ }
+ }
+
+ /**
+ * Proxy method for {@link java.security.Signature#setParameter(
+ * java.security.spec.AlgorithmParameterSpec)}
+ * which is executed on the internal {@link java.security.Signature} object.
+ *
+ * @param params
+ * @throws XMLSignatureException
+ */
+ protected void engineSetParameter(AlgorithmParameterSpec params) throws XMLSignatureException {
+ throw new XMLSignatureException("empty");
+ }
+
+ public void reset() {
+ HMACOutputLength = 0;
+ HMACOutputLengthSet = false;
+ this.macAlgorithm.reset();
+ }
+
+ /**
+ * 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()) {
+ if (log.isDebugEnabled()) {
+ 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);
}
- 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("empty", ex);
- }
- }
-
- /**
- * 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) {
+ } catch (IllegalStateException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * 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;
+ Mac mac = this.macAlgorithm;
try {
- this._macAlgorithm = Mac.getInstance
- (_macAlgorithm.getAlgorithm());
+ this.macAlgorithm = Mac.getInstance(macAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous Mac
if (log.isDebugEnabled()) {
log.debug("Exception when reinstantiating Mac:" + e);
}
- this._macAlgorithm = mac;
+ this.macAlgorithm = mac;
}
throw new XMLSignatureException("empty", ex);
- }
- }
+ }
+ }
- /**
- * 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()) {
- if (log.isDebugEnabled()) {
- log.debug("HMACOutputLength must not be less than " + getDigestLength());
+ /**
+ * 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()) {
+ if (log.isDebugEnabled()) {
+ 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();
}
- Object[] exArgs = { String.valueOf(getDigestLength()) };
- throw new XMLSignatureException
- ("algorithms.HMACOutputLengthMin", exArgs);
- } else {
- return this._macAlgorithm.doFinal();
- }
- } catch (IllegalStateException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * Method reduceBitLength
- *
- * @param completeResult
- * @return the reduced bits.
- * @param length
- *
- */
- private static byte[] reduceBitLength(byte completeResult[], int length) {
-
- int bytes = length / 8;
- int abits = length % 8;
- byte[] strippedResult = new byte[bytes + ((abits == 0)
- ? 0
- : 1)];
-
- System.arraycopy(completeResult, 0, strippedResult, 0, bytes);
-
- if (abits > 0) {
- byte[] MASK = { (byte) 0x00, (byte) 0x80, (byte) 0xC0, (byte) 0xE0,
- (byte) 0xF0, (byte) 0xF8, (byte) 0xFC, (byte) 0xFE };
-
- strippedResult[bytes] = (byte) (completeResult[bytes] & MASK[abits]);
- }
-
- return strippedResult;
- }
-
- /**
- * 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);
- }
- }
-
- /**
- * Method engineInitSign
- *
- * @param secretKey
- * @param algorithmParameterSpec
- * @throws XMLSignatureException
- */
- protected void engineInitSign(
- Key secretKey, AlgorithmParameterSpec algorithmParameterSpec)
- 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, algorithmParameterSpec);
- } catch (InvalidKeyException ex) {
- throw new XMLSignatureException("empty", ex);
- } catch (InvalidAlgorithmParameterException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * Method engineInitSign
- *
- * @param secretKey
- * @param secureRandom
- * @throws XMLSignatureException
- */
- protected void engineInitSign(Key secretKey, SecureRandom secureRandom)
- throws XMLSignatureException {
- throw new XMLSignatureException("algorithms.CannotUseSecureRandomOnMAC");
- }
-
- /**
- * Proxy method for {@link java.security.Signature#update(byte[])}
- * which is executed on the internal {@link java.security.Signature} object.
- *
- * @param input
- * @throws XMLSignatureException
- */
- protected void engineUpdate(byte[] input) throws XMLSignatureException {
-
- try {
- this._macAlgorithm.update(input);
- } catch (IllegalStateException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * Proxy method for {@link java.security.Signature#update(byte)}
- * which is executed on the internal {@link java.security.Signature} object.
- *
- * @param input
- * @throws XMLSignatureException
- */
- protected void engineUpdate(byte input) throws XMLSignatureException {
-
- try {
- this._macAlgorithm.update(input);
- } catch (IllegalStateException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * Proxy method for {@link java.security.Signature#update(byte[], int, int)}
- * which is executed on the internal {@link java.security.Signature} object.
- *
- * @param buf
- * @param offset
- * @param len
- * @throws XMLSignatureException
- */
- protected void engineUpdate(byte buf[], int offset, int len)
- throws XMLSignatureException {
-
- try {
- this._macAlgorithm.update(buf, offset, len);
- } catch (IllegalStateException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /**
- * Method engineGetJCEAlgorithmString
- * @inheritDoc
- *
- */
- protected String engineGetJCEAlgorithmString() {
-
- log.debug("engineGetJCEAlgorithmString()");
-
- return this._macAlgorithm.getAlgorithm();
- }
-
- /**
- * Method engineGetJCEAlgorithmString
- *
- * @inheritDoc
- */
- protected String engineGetJCEProviderName() {
- return this._macAlgorithm.getProvider().getName();
- }
-
- /**
- * Method engineSetHMACOutputLength
- *
- * @param HMACOutputLength
- */
- protected void engineSetHMACOutputLength(int HMACOutputLength) {
- this._HMACOutputLength = HMACOutputLength;
- this._HMACOutputLengthSet = true;
- }
-
- /**
- * Method engineGetContextFromElement
- *
- * @param element
- */
- protected void engineGetContextFromElement(Element element) {
-
- super.engineGetContextFromElement(element);
-
- if (element == null) {
- throw new IllegalArgumentException("element null");
- }
-
- Text hmaclength =XMLUtils.selectDsNodeText(element.getFirstChild(),
- Constants._TAG_HMACOUTPUTLENGTH,0);
-
- if (hmaclength != null) {
- this._HMACOutputLength = Integer.parseInt(hmaclength.getData());
- this._HMACOutputLengthSet = true;
- }
- }
-
- /**
- * Method engineAddContextToElement
- *
- * @param element
- */
- public void engineAddContextToElement(Element element) {
-
- if (element == null) {
- throw new IllegalArgumentException("null element");
- }
-
- if (this._HMACOutputLengthSet) {
- Document doc = element.getOwnerDocument();
- Element HMElem = XMLUtils.createElementInSignatureSpace(doc,
- Constants._TAG_HMACOUTPUTLENGTH);
- Text HMText =
- doc.createTextNode(new Integer(this._HMACOutputLength).toString());
-
- HMElem.appendChild(HMText);
- XMLUtils.addReturnToElement(element);
- element.appendChild(HMElem);
- XMLUtils.addReturnToElement(element);
- }
- }
-
- /**
- * Class IntegrityHmacSHA1
- *
- * @author $Author$
- * @version $Revision$
- */
- public static class IntegrityHmacSHA1 extends IntegrityHmac {
-
- /**
- * Constructor IntegrityHmacSHA1
- *
- * @throws XMLSignatureException
- */
- public IntegrityHmacSHA1() throws XMLSignatureException {
- super();
- }
-
- /**
- * Method engineGetURI
- * @inheritDoc
- *
- */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_MAC_HMAC_SHA1;
- }
-
- int getDigestLength() {
- return 160;
- }
- }
-
- /**
- * Class IntegrityHmacSHA256
- *
- * @author $Author$
- * @version $Revision$
- */
- public static class IntegrityHmacSHA256 extends IntegrityHmac {
-
- /**
- * Constructor IntegrityHmacSHA256
- *
- * @throws XMLSignatureException
- */
- public IntegrityHmacSHA256() throws XMLSignatureException {
- super();
- }
-
- /**
- * Method engineGetURI
- *
- * @inheritDoc
- */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_MAC_HMAC_SHA256;
- }
-
- int getDigestLength() {
- return 256;
- }
- }
-
- /**
- * Class IntegrityHmacSHA384
- *
- * @author $Author$
- * @version $Revision$
- */
- public static class IntegrityHmacSHA384 extends IntegrityHmac {
-
- /**
- * Constructor IntegrityHmacSHA384
- *
- * @throws XMLSignatureException
- */
- public IntegrityHmacSHA384() throws XMLSignatureException {
- super();
- }
-
- /**
- * Method engineGetURI
- * @inheritDoc
- *
- */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_MAC_HMAC_SHA384;
- }
-
- int getDigestLength() {
- return 384;
- }
- }
-
- /**
- * Class IntegrityHmacSHA512
- *
- * @author $Author$
- * @version $Revision$
- */
- public static class IntegrityHmacSHA512 extends IntegrityHmac {
-
- /**
- * Constructor IntegrityHmacSHA512
- *
- * @throws XMLSignatureException
- */
- public IntegrityHmacSHA512() throws XMLSignatureException {
- super();
- }
-
- /**
- * Method engineGetURI
- * @inheritDoc
- *
- */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_MAC_HMAC_SHA512;
- }
-
- int getDigestLength() {
- return 512;
- }
- }
-
- /**
- * Class IntegrityHmacRIPEMD160
- *
- * @author $Author$
- * @version $Revision$
- */
- public static class IntegrityHmacRIPEMD160 extends IntegrityHmac {
-
- /**
- * Constructor IntegrityHmacRIPEMD160
- *
- * @throws XMLSignatureException
- */
- public IntegrityHmacRIPEMD160() throws XMLSignatureException {
- super();
- }
-
- /**
- * Method engineGetURI
- *
- * @inheritDoc
- */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_MAC_HMAC_RIPEMD160;
- }
-
- int getDigestLength() {
- return 160;
- }
- }
-
- /**
- * Class IntegrityHmacMD5
- *
- * @author $Author$
- * @version $Revision$
- */
- public static class IntegrityHmacMD5 extends IntegrityHmac {
-
- /**
- * Constructor IntegrityHmacMD5
- *
- * @throws XMLSignatureException
- */
- public IntegrityHmacMD5() throws XMLSignatureException {
- super();
- }
-
- /**
- * Method engineGetURI
- *
- * @inheritDoc
- */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5;
- }
-
- int getDigestLength() {
- return 128;
- }
- }
+ } catch (IllegalStateException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * 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);
+ }
+ }
+
+ /**
+ * Method engineInitSign
+ *
+ * @param secretKey
+ * @param algorithmParameterSpec
+ * @throws XMLSignatureException
+ */
+ protected void engineInitSign(
+ Key secretKey, AlgorithmParameterSpec algorithmParameterSpec
+ ) 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, algorithmParameterSpec);
+ } catch (InvalidKeyException ex) {
+ throw new XMLSignatureException("empty", ex);
+ } catch (InvalidAlgorithmParameterException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * Method engineInitSign
+ *
+ * @param secretKey
+ * @param secureRandom
+ * @throws XMLSignatureException
+ */
+ protected void engineInitSign(Key secretKey, SecureRandom secureRandom)
+ throws XMLSignatureException {
+ throw new XMLSignatureException("algorithms.CannotUseSecureRandomOnMAC");
+ }
+
+ /**
+ * Proxy method for {@link java.security.Signature#update(byte[])}
+ * which is executed on the internal {@link java.security.Signature} object.
+ *
+ * @param input
+ * @throws XMLSignatureException
+ */
+ protected void engineUpdate(byte[] input) throws XMLSignatureException {
+ try {
+ this.macAlgorithm.update(input);
+ } catch (IllegalStateException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * Proxy method for {@link java.security.Signature#update(byte)}
+ * which is executed on the internal {@link java.security.Signature} object.
+ *
+ * @param input
+ * @throws XMLSignatureException
+ */
+ protected void engineUpdate(byte input) throws XMLSignatureException {
+ try {
+ this.macAlgorithm.update(input);
+ } catch (IllegalStateException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * Proxy method for {@link java.security.Signature#update(byte[], int, int)}
+ * which is executed on the internal {@link java.security.Signature} object.
+ *
+ * @param buf
+ * @param offset
+ * @param len
+ * @throws XMLSignatureException
+ */
+ protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
+ try {
+ this.macAlgorithm.update(buf, offset, len);
+ } catch (IllegalStateException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /**
+ * Method engineGetJCEAlgorithmString
+ * @inheritDoc
+ *
+ */
+ protected String engineGetJCEAlgorithmString() {
+ return this.macAlgorithm.getAlgorithm();
+ }
+
+ /**
+ * Method engineGetJCEAlgorithmString
+ *
+ * @inheritDoc
+ */
+ protected String engineGetJCEProviderName() {
+ return this.macAlgorithm.getProvider().getName();
+ }
+
+ /**
+ * Method engineSetHMACOutputLength
+ *
+ * @param HMACOutputLength
+ */
+ protected void engineSetHMACOutputLength(int HMACOutputLength) {
+ this.HMACOutputLength = HMACOutputLength;
+ this.HMACOutputLengthSet = true;
+ }
+
+ /**
+ * Method engineGetContextFromElement
+ *
+ * @param element
+ */
+ protected void engineGetContextFromElement(Element element) {
+ super.engineGetContextFromElement(element);
+
+ if (element == null) {
+ throw new IllegalArgumentException("element null");
+ }
+
+ Text hmaclength =
+ XMLUtils.selectDsNodeText(element.getFirstChild(), Constants._TAG_HMACOUTPUTLENGTH, 0);
+
+ if (hmaclength != null) {
+ this.HMACOutputLength = Integer.parseInt(hmaclength.getData());
+ this.HMACOutputLengthSet = true;
+ }
+ }
+
+ /**
+ * Method engineAddContextToElement
+ *
+ * @param element
+ */
+ public void engineAddContextToElement(Element element) {
+ if (element == null) {
+ throw new IllegalArgumentException("null element");
+ }
+
+ if (this.HMACOutputLengthSet) {
+ Document doc = element.getOwnerDocument();
+ Element HMElem =
+ XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_HMACOUTPUTLENGTH);
+ Text HMText =
+ doc.createTextNode(new Integer(this.HMACOutputLength).toString());
+
+ HMElem.appendChild(HMText);
+ XMLUtils.addReturnToElement(element);
+ element.appendChild(HMElem);
+ XMLUtils.addReturnToElement(element);
+ }
+ }
+
+ /**
+ * Class IntegrityHmacSHA1
+ */
+ public static class IntegrityHmacSHA1 extends IntegrityHmac {
+
+ /**
+ * Constructor IntegrityHmacSHA1
+ *
+ * @throws XMLSignatureException
+ */
+ public IntegrityHmacSHA1() throws XMLSignatureException {
+ super();
+ }
+
+ /**
+ * Method engineGetURI
+ * @inheritDoc
+ *
+ */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_MAC_HMAC_SHA1;
+ }
+
+ int getDigestLength() {
+ return 160;
+ }
+ }
+
+ /**
+ * Class IntegrityHmacSHA256
+ */
+ public static class IntegrityHmacSHA256 extends IntegrityHmac {
+
+ /**
+ * Constructor IntegrityHmacSHA256
+ *
+ * @throws XMLSignatureException
+ */
+ public IntegrityHmacSHA256() throws XMLSignatureException {
+ super();
+ }
+
+ /**
+ * Method engineGetURI
+ *
+ * @inheritDoc
+ */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_MAC_HMAC_SHA256;
+ }
+
+ int getDigestLength() {
+ return 256;
+ }
+ }
+
+ /**
+ * Class IntegrityHmacSHA384
+ */
+ public static class IntegrityHmacSHA384 extends IntegrityHmac {
+
+ /**
+ * Constructor IntegrityHmacSHA384
+ *
+ * @throws XMLSignatureException
+ */
+ public IntegrityHmacSHA384() throws XMLSignatureException {
+ super();
+ }
+
+ /**
+ * Method engineGetURI
+ * @inheritDoc
+ *
+ */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_MAC_HMAC_SHA384;
+ }
+
+ int getDigestLength() {
+ return 384;
+ }
+ }
+
+ /**
+ * Class IntegrityHmacSHA512
+ */
+ public static class IntegrityHmacSHA512 extends IntegrityHmac {
+
+ /**
+ * Constructor IntegrityHmacSHA512
+ *
+ * @throws XMLSignatureException
+ */
+ public IntegrityHmacSHA512() throws XMLSignatureException {
+ super();
+ }
+
+ /**
+ * Method engineGetURI
+ * @inheritDoc
+ *
+ */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_MAC_HMAC_SHA512;
+ }
+
+ int getDigestLength() {
+ return 512;
+ }
+ }
+
+ /**
+ * Class IntegrityHmacRIPEMD160
+ */
+ public static class IntegrityHmacRIPEMD160 extends IntegrityHmac {
+
+ /**
+ * Constructor IntegrityHmacRIPEMD160
+ *
+ * @throws XMLSignatureException
+ */
+ public IntegrityHmacRIPEMD160() throws XMLSignatureException {
+ super();
+ }
+
+ /**
+ * Method engineGetURI
+ *
+ * @inheritDoc
+ */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_MAC_HMAC_RIPEMD160;
+ }
+
+ int getDigestLength() {
+ return 160;
+ }
+ }
+
+ /**
+ * Class IntegrityHmacMD5
+ */
+ public static class IntegrityHmacMD5 extends IntegrityHmac {
+
+ /**
+ * Constructor IntegrityHmacMD5
+ *
+ * @throws XMLSignatureException
+ */
+ public IntegrityHmacMD5() throws XMLSignatureException {
+ super();
+ }
+
+ /**
+ * Method engineGetURI
+ *
+ * @inheritDoc
+ */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5;
+ }
+
+ int getDigestLength() {
+ return 128;
+ }
+ }
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureBaseRSA.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureBaseRSA.java?rev=1071567&r1=1071566&r2=1071567&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureBaseRSA.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureBaseRSA.java Thu Feb 17 10:47:08 2011
@@ -32,22 +32,17 @@ import org.apache.xml.security.algorithm
import org.apache.xml.security.signature.XMLSignature;
import org.apache.xml.security.signature.XMLSignatureException;
-/**
- *
- * @author $Author$
- */
public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** {@link org.apache.commons.logging} logging facility */
- static org.apache.commons.logging.Log log =
- org.apache.commons.logging.LogFactory.getLog
- (SignatureBaseRSA.class.getName());
+ private static org.apache.commons.logging.Log log =
+ org.apache.commons.logging.LogFactory.getLog(SignatureBaseRSA.class.getName());
/** @inheritDoc */
public abstract String engineGetURI();
/** Field algorithm */
- private java.security.Signature _signatureAlgorithm = null;
+ private java.security.Signature signatureAlgorithm = null;
/**
* Constructor SignatureRSA
@@ -55,17 +50,17 @@ public abstract class SignatureBaseRSA e
* @throws XMLSignatureException
*/
public SignatureBaseRSA() throws XMLSignatureException {
-
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
log.debug("Created SignatureRSA using " + algorithmID);
- String provider=JCEMapper.getProviderId();
+ }
+ String provider = JCEMapper.getProviderId();
try {
- if (provider==null) {
- this._signatureAlgorithm = Signature.getInstance(algorithmID);
+ if (provider == null) {
+ this.signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
- this._signatureAlgorithm = Signature.getInstance(algorithmID,provider);
+ this.signatureAlgorithm = Signature.getInstance(algorithmID,provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
@@ -81,20 +76,17 @@ public abstract class SignatureBaseRSA e
/** @inheritDoc */
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
-
try {
- this._signatureAlgorithm.setParameter(params);
+ this.signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
- protected boolean engineVerify(byte[] signature)
- throws XMLSignatureException {
-
+ protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
try {
- return this._signatureAlgorithm.verify(signature);
+ return this.signatureAlgorithm.verify(signature);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -102,32 +94,29 @@ public abstract class SignatureBaseRSA e
/** @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);
+ throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
- this._signatureAlgorithm.initVerify((PublicKey) publicKey);
+ 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;
+ Signature sig = this.signatureAlgorithm;
try {
- this._signatureAlgorithm = Signature.getInstance
- (_signatureAlgorithm.getAlgorithm());
+ this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isDebugEnabled()) {
log.debug("Exception when reinstantiating Signature:" + e);
}
- this._signatureAlgorithm = sig;
+ this.signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex);
}
@@ -136,7 +125,7 @@ public abstract class SignatureBaseRSA e
/** @inheritDoc */
protected byte[] engineSign() throws XMLSignatureException {
try {
- return this._signatureAlgorithm.sign();
+ return this.signatureAlgorithm.sign();
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -145,19 +134,16 @@ public abstract class SignatureBaseRSA e
/** @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);
+ throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
- this._signatureAlgorithm.initSign
- ((PrivateKey) privateKey, secureRandom);
+ this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -165,18 +151,16 @@ public abstract class SignatureBaseRSA e
/** @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);
+ throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
- this._signatureAlgorithm.initSign((PrivateKey) privateKey);
+ this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -185,7 +169,7 @@ public abstract class SignatureBaseRSA e
/** @inheritDoc */
protected void engineUpdate(byte[] input) throws XMLSignatureException {
try {
- this._signatureAlgorithm.update(input);
+ this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -194,17 +178,16 @@ public abstract class SignatureBaseRSA e
/** @inheritDoc */
protected void engineUpdate(byte input) throws XMLSignatureException {
try {
- this._signatureAlgorithm.update(input);
+ this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
- protected void engineUpdate(byte buf[], int offset, int len)
- throws XMLSignatureException {
+ protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
try {
- this._signatureAlgorithm.update(buf, offset, len);
+ this.signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -212,34 +195,29 @@ public abstract class SignatureBaseRSA e
/** @inheritDoc */
protected String engineGetJCEAlgorithmString() {
- return this._signatureAlgorithm.getAlgorithm();
+ return this.signatureAlgorithm.getAlgorithm();
}
/** @inheritDoc */
protected String engineGetJCEProviderName() {
- return this._signatureAlgorithm.getProvider().getName();
+ return this.signatureAlgorithm.getProvider().getName();
}
/** @inheritDoc */
protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException {
- throw new XMLSignatureException
- ("algorithms.HMACOutputLengthOnlyForHMAC");
+ throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
}
/** @inheritDoc */
protected void engineInitSign(
- Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
- throws XMLSignatureException {
- throw new XMLSignatureException(
- "algorithms.CannotUseAlgorithmParameterSpecOnRSA");
+ Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
+ ) throws XMLSignatureException {
+ throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnRSA");
}
/**
* Class SignatureRSASHA1
- *
- * @author $Author$
- * @version $Revision$
*/
public static class SignatureRSASHA1 extends SignatureBaseRSA {
@@ -260,12 +238,9 @@ public abstract class SignatureBaseRSA e
/**
* Class SignatureRSASHA256
- *
- * @author $Author$
- * @version $Revision$
*/
public static class SignatureRSASHA256 extends SignatureBaseRSA {
-
+
/**
* Constructor SignatureRSASHA256
*
@@ -283,9 +258,6 @@ public abstract class SignatureBaseRSA e
/**
* Class SignatureRSASHA384
- *
- * @author $Author$
- * @version $Revision$
*/
public static class SignatureRSASHA384 extends SignatureBaseRSA {
@@ -306,9 +278,6 @@ public abstract class SignatureBaseRSA e
/**
* Class SignatureRSASHA512
- *
- * @author $Author$
- * @version $Revision$
*/
public static class SignatureRSASHA512 extends SignatureBaseRSA {
@@ -329,9 +298,6 @@ public abstract class SignatureBaseRSA e
/**
* Class SignatureRSARIPEMD160
- *
- * @author $Author$
- * @version $Revision$
*/
public static class SignatureRSARIPEMD160 extends SignatureBaseRSA {
@@ -352,9 +318,6 @@ public abstract class SignatureBaseRSA e
/**
* Class SignatureRSAMD5
- *
- * @author $Author$
- * @version $Revision$
*/
public static class SignatureRSAMD5 extends SignatureBaseRSA {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureDSA.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureDSA.java?rev=1071567&r1=1071566&r2=1071567&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureDSA.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureDSA.java Thu Feb 17 10:47:08 2011
@@ -33,21 +33,17 @@ import org.apache.xml.security.signature
import org.apache.xml.security.utils.Base64;
import org.apache.xml.security.utils.Constants;
-/**
- *
- * @author $Author$
- */
public class SignatureDSA extends SignatureAlgorithmSpi {
/** {@link org.apache.commons.logging} logging facility */
- static org.apache.commons.logging.Log log =
+ private static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(SignatureDSA.class.getName());
- /** Field _URI */
- public static final String _URI = Constants.SignatureSpecNS + "dsa-sha1";
+ /** Field URI */
+ public static final String URI = Constants.SignatureSpecNS + "dsa-sha1";
/** Field algorithm */
- private java.security.Signature _signatureAlgorithm = null;
+ private java.security.Signature signatureAlgorithm = null;
/**
* Method engineGetURI
@@ -55,7 +51,7 @@ public class SignatureDSA extends Signat
* @inheritDoc
*/
protected String engineGetURI() {
- return SignatureDSA._URI;
+ return SignatureDSA.URI;
}
/**
@@ -64,17 +60,17 @@ public class SignatureDSA extends Signat
* @throws XMLSignatureException
*/
public SignatureDSA() throws XMLSignatureException {
-
- String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA._URI);
- if (log.isDebugEnabled())
+ String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA.URI);
+ if (log.isDebugEnabled()) {
log.debug("Created SignatureDSA using " + algorithmID);
+ }
String provider = JCEMapper.getProviderId();
try {
if (provider == null) {
- this._signatureAlgorithm = Signature.getInstance(algorithmID);
+ this.signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
- this._signatureAlgorithm =
+ this.signatureAlgorithm =
Signature.getInstance(algorithmID, provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
@@ -91,9 +87,8 @@ public class SignatureDSA extends Signat
*/
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
-
try {
- this._signatureAlgorithm.setParameter(params);
+ this.signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -103,15 +98,15 @@ public class SignatureDSA extends Signat
* @inheritDoc
*/
protected boolean engineVerify(byte[] signature)
- throws XMLSignatureException {
-
+ throws XMLSignatureException {
try {
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
log.debug("Called DSA.verify() on " + Base64.encode(signature));
+ }
byte[] jcebytes = SignatureDSA.convertXMLDSIGtoASN1(signature);
- return this._signatureAlgorithm.verify(jcebytes);
+ return this.signatureAlgorithm.verify(jcebytes);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
} catch (IOException ex) {
@@ -123,32 +118,29 @@ public class SignatureDSA extends Signat
* @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);
+ throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
- this._signatureAlgorithm.initVerify((PublicKey) publicKey);
+ 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;
+ Signature sig = this.signatureAlgorithm;
try {
- this._signatureAlgorithm = Signature.getInstance
- (_signatureAlgorithm.getAlgorithm());
+ this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isDebugEnabled()) {
log.debug("Exception when reinstantiating Signature:" + e);
}
- this._signatureAlgorithm = sig;
+ this.signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex);
}
@@ -158,9 +150,8 @@ public class SignatureDSA extends Signat
* @inheritDoc
*/
protected byte[] engineSign() throws XMLSignatureException {
-
try {
- byte jcebytes[] = this._signatureAlgorithm.sign();
+ byte jcebytes[] = this.signatureAlgorithm.sign();
return SignatureDSA.convertASN1toXMLDSIG(jcebytes);
} catch (IOException ex) {
@@ -174,20 +165,17 @@ public class SignatureDSA extends Signat
* @inheritDoc
*/
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
- throws XMLSignatureException {
-
+ 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);
+ throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
- this._signatureAlgorithm.initSign((PrivateKey) privateKey,
- secureRandom);
+ this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -197,18 +185,16 @@ public class SignatureDSA extends Signat
* @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);
+ throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
- this._signatureAlgorithm.initSign((PrivateKey) privateKey);
+ this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -219,7 +205,7 @@ public class SignatureDSA extends Signat
*/
protected void engineUpdate(byte[] input) throws XMLSignatureException {
try {
- this._signatureAlgorithm.update(input);
+ this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -230,7 +216,7 @@ public class SignatureDSA extends Signat
*/
protected void engineUpdate(byte input) throws XMLSignatureException {
try {
- this._signatureAlgorithm.update(input);
+ this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -239,10 +225,9 @@ public class SignatureDSA extends Signat
/**
* @inheritDoc
*/
- protected void engineUpdate(byte buf[], int offset, int len)
- throws XMLSignatureException {
+ protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
try {
- this._signatureAlgorithm.update(buf, offset, len);
+ this.signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@@ -254,7 +239,7 @@ public class SignatureDSA extends Signat
* @inheritDoc
*/
protected String engineGetJCEAlgorithmString() {
- return this._signatureAlgorithm.getAlgorithm();
+ return this.signatureAlgorithm.getAlgorithm();
}
/**
@@ -263,7 +248,7 @@ public class SignatureDSA extends Signat
* @inheritDoc
*/
protected String engineGetJCEProviderName() {
- return this._signatureAlgorithm.getProvider().getName();
+ return this.signatureAlgorithm.getProvider().getName();
}
/**
@@ -278,8 +263,7 @@ public class SignatureDSA extends Signat
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
*/
- private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[])
- throws IOException {
+ private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[]) throws IOException {
byte rLength = asn1Bytes[3];
int i;
@@ -290,19 +274,18 @@ public class SignatureDSA extends Signat
int j;
for (j = sLength;
- (j > 0) && (asn1Bytes[(6 + rLength + sLength) - j] == 0); j--);
+ (j > 0) && (asn1Bytes[(6 + rLength + sLength) - j] == 0); j--);
if ((asn1Bytes[0] != 48) || (asn1Bytes[1] != asn1Bytes.length - 2)
- || (asn1Bytes[2] != 2) || (i > 20)
- || (asn1Bytes[4 + rLength] != 2) || (j > 20)) {
+ || (asn1Bytes[2] != 2) || (i > 20)
+ || (asn1Bytes[4 + rLength] != 2) || (j > 20)) {
throw new IOException("Invalid ASN.1 format of DSA signature");
}
byte xmldsigBytes[] = new byte[40];
- System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i,
- i);
+ System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i, i);
System.arraycopy(asn1Bytes, (6 + rLength + sLength) - j, xmldsigBytes,
- 40 - j, j);
+ 40 - j, j);
return xmldsigBytes;
}
@@ -319,8 +302,7 @@ public class SignatureDSA extends Signat
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
*/
- private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[])
- throws IOException {
+ private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[]) throws IOException {
if (xmldsigBytes.length != 40) {
throw new IOException("Invalid XMLDSIG format of DSA signature");
@@ -333,7 +315,7 @@ public class SignatureDSA extends Signat
int j = i;
if (xmldsigBytes[20 - i] < 0) {
- j += 1;
+ j += 1;
}
int k;
@@ -369,10 +351,8 @@ public class SignatureDSA extends Signat
* @param HMACOutputLength
* @throws XMLSignatureException
*/
- protected void engineSetHMACOutputLength(int HMACOutputLength)
- throws XMLSignatureException {
- throw new XMLSignatureException(
- "algorithms.HMACOutputLengthOnlyForHMAC");
+ protected void engineSetHMACOutputLength(int HMACOutputLength) throws XMLSignatureException {
+ throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
}
/**
@@ -383,9 +363,8 @@ public class SignatureDSA extends Signat
* @throws XMLSignatureException
*/
protected void engineInitSign(
- Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
- throws XMLSignatureException {
- throw new XMLSignatureException(
- "algorithms.CannotUseAlgorithmParameterSpecOnDSA");
+ Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
+ ) throws XMLSignatureException {
+ throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnDSA");
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java?rev=1071567&r1=1071566&r2=1071567&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/implementations/SignatureECDSA.java Thu Feb 17 10:47:08 2011
@@ -16,8 +16,6 @@
*/
package org.apache.xml.security.algorithms.implementations;
-
-
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@@ -36,7 +34,6 @@ import org.apache.xml.security.signature
import org.apache.xml.security.signature.XMLSignatureException;
import org.apache.xml.security.utils.Base64;
-
/**
*
* @author $Author: raul $
@@ -44,434 +41,410 @@ import org.apache.xml.security.utils.Bas
*/
public abstract class SignatureECDSA extends SignatureAlgorithmSpi {
- /** {@link org.apache.commons.logging} logging facility */
- static org.apache.commons.logging.Log log =
+ /** {@link org.apache.commons.logging} logging facility */
+ private static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(SignatureECDSA.class.getName());
/** @inheritDoc */
- public abstract String engineGetURI();
+ public abstract String engineGetURI();
+
+ /** Field algorithm */
+ private java.security.Signature signatureAlgorithm = null;
+
+ /**
+ * Converts an ASN.1 ECDSA value to a XML Signature ECDSA Value.
+ *
+ * The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
+ * pairs; the XML Signature requires the core BigInteger values.
+ *
+ * @param asn1Bytes
+ * @return the decode bytes
+ *
+ * @throws IOException
+ * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
+ * @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
+ */
+ public static byte[] convertASN1toXMLDSIG(byte asn1Bytes[]) throws IOException {
+
+ if (asn1Bytes.length < 8 || asn1Bytes[0] != 48) {
+ throw new IOException("Invalid ASN.1 format of ECDSA signature");
+ }
+ int offset;
+ if (asn1Bytes[1] > 0) {
+ offset = 2;
+ } else if (asn1Bytes[1] == (byte) 0x81) {
+ offset = 3;
+ } else {
+ throw new IOException("Invalid ASN.1 format of ECDSA signature");
+ }
+
+ byte rLength = asn1Bytes[offset + 1];
+ int i;
+
+ for (i = rLength; (i > 0) && (asn1Bytes[(offset + 2 + rLength) - i] == 0); i--);
+
+ byte sLength = asn1Bytes[offset + 2 + rLength + 1];
+ int j;
+
+ for (j = sLength;
+ (j > 0) && (asn1Bytes[(offset + 2 + rLength + 2 + sLength) - j] == 0); j--);
+
+ int rawLen = Math.max(i, j);
+
+ if ((asn1Bytes[offset - 1] & 0xff) != asn1Bytes.length - offset
+ || (asn1Bytes[offset - 1] & 0xff) != 2 + rLength + 2 + sLength
+ || asn1Bytes[offset] != 2
+ || asn1Bytes[offset + 2 + rLength] != 2) {
+ throw new IOException("Invalid ASN.1 format of ECDSA signature");
+ }
+ byte xmldsigBytes[] = new byte[2*rawLen];
+
+ System.arraycopy(asn1Bytes, (offset + 2 + rLength) - i, xmldsigBytes, rawLen - i, i);
+ System.arraycopy(asn1Bytes, (offset + 2 + rLength + 2 + sLength) - j, xmldsigBytes,
+ 2*rawLen - j, j);
+
+ return xmldsigBytes;
+ }
+
+ /**
+ * Converts a XML Signature ECDSA Value to an ASN.1 DSA value.
+ *
+ * The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
+ * pairs; the XML Signature requires the core BigInteger values.
+ *
+ * @param xmldsigBytes
+ * @return the encoded ASN.1 bytes
+ *
+ * @throws IOException
+ * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
+ * @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
+ */
+ public static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[]) throws IOException {
+
+ int rawLen = xmldsigBytes.length/2;
+
+ int i;
+
+ for (i = rawLen; (i > 0) && (xmldsigBytes[rawLen - i] == 0); i--);
+
+ int j = i;
+
+ if (xmldsigBytes[rawLen - i] < 0) {
+ j += 1;
+ }
+
+ int k;
+
+ for (k = rawLen; (k > 0) && (xmldsigBytes[2*rawLen - k] == 0); k--);
+
+ int l = k;
+
+ if (xmldsigBytes[2*rawLen - k] < 0) {
+ l += 1;
+ }
+
+ int len = 2 + j + 2 + l;
+ if (len > 255) {
+ throw new IOException("Invalid XMLDSIG format of ECDSA signature");
+ }
+ int offset;
+ byte asn1Bytes[];
+ if (len < 128) {
+ asn1Bytes = new byte[2 + 2 + j + 2 + l];
+ offset = 1;
+ } else {
+ asn1Bytes = new byte[3 + 2 + j + 2 + l];
+ asn1Bytes[1] = (byte) 0x81;
+ offset = 2;
+ }
+ asn1Bytes[0] = 48;
+ asn1Bytes[offset++] = (byte) len;
+ asn1Bytes[offset++] = 2;
+ asn1Bytes[offset++] = (byte) j;
+
+ System.arraycopy(xmldsigBytes, rawLen - i, asn1Bytes, (offset + j) - i, i);
+
+ offset += j;
+
+ asn1Bytes[offset++] = 2;
+ asn1Bytes[offset++] = (byte) l;
+
+ System.arraycopy(xmldsigBytes, 2*rawLen - k, asn1Bytes, (offset + l) - k, k);
+
+ return asn1Bytes;
+ }
+
+ /**
+ * Constructor SignatureRSA
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureECDSA() throws XMLSignatureException {
+
+ String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+
+ if (log.isDebugEnabled()) {
+ log.debug("Created SignatureECDSA using " + algorithmID);
+ }
+ String provider = JCEMapper.getProviderId();
+ try {
+ if (provider == null) {
+ this.signatureAlgorithm = Signature.getInstance(algorithmID);
+ } else {
+ this.signatureAlgorithm = Signature.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);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineSetParameter(AlgorithmParameterSpec params)
+ throws XMLSignatureException {
+ try {
+ this.signatureAlgorithm.setParameter(params);
+ } catch (InvalidAlgorithmParameterException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
+ try {
+ byte[] jcebytes = SignatureECDSA.convertXMLDSIGtoASN1(signature);
- /** Field algorithm */
- private java.security.Signature _signatureAlgorithm = null;
+ if (log.isDebugEnabled()) {
+ log.debug("Called ECDSA.verify() on " + Base64.encode(signature));
+ }
+
+ return this.signatureAlgorithm.verify(jcebytes);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ } catch (IOException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @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);
+ }
- /**
- * Converts an ASN.1 ECDSA value to a XML Signature ECDSA Value.
- *
- * The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
- * pairs; the XML Signature requires the core BigInteger values.
- *
- * @param asn1Bytes
- * @return the decode bytes
- *
- * @throws IOException
- * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
- * @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
- */
- public static byte[] convertASN1toXMLDSIG(byte asn1Bytes[])
- throws IOException {
-
- if (asn1Bytes.length < 8 || asn1Bytes[0] != 48) {
- throw new IOException("Invalid ASN.1 format of ECDSA signature");
- }
- int offset;
- if (asn1Bytes[1] > 0) {
- offset = 2;
- } else if (asn1Bytes[1] == (byte) 0x81) {
- offset = 3;
- } else {
- throw new IOException("Invalid ASN.1 format of ECDSA signature");
- }
-
- byte rLength = asn1Bytes[offset + 1];
- int i;
-
- for (i = rLength; (i > 0) && (asn1Bytes[(offset + 2 + rLength) - i] == 0); i--);
-
- byte sLength = asn1Bytes[offset + 2 + rLength + 1];
- int j;
-
- for (j = sLength;
- (j > 0) && (asn1Bytes[(offset + 2 + rLength + 2 + sLength) - j] == 0); j--);
-
- int rawLen = Math.max(i, j);
-
- if ((asn1Bytes[offset - 1] & 0xff) != asn1Bytes.length - offset
- || (asn1Bytes[offset - 1] & 0xff) != 2 + rLength + 2 + sLength
- || asn1Bytes[offset] != 2
- || asn1Bytes[offset + 2 + rLength] != 2) {
- throw new IOException("Invalid ASN.1 format of ECDSA signature");
- }
- byte xmldsigBytes[] = new byte[2*rawLen];
-
- System.arraycopy(asn1Bytes, (offset + 2 + rLength) - i, xmldsigBytes, rawLen - i,
- i);
- System.arraycopy(asn1Bytes, (offset + 2 + rLength + 2 + sLength) - j, xmldsigBytes,
- 2*rawLen - j, j);
-
- return xmldsigBytes;
- }
-
- /**
- * Converts a XML Signature ECDSA Value to an ASN.1 DSA value.
- *
- * The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
- * pairs; the XML Signature requires the core BigInteger values.
- *
- * @param xmldsigBytes
- * @return the encoded ASN.1 bytes
- *
- * @throws IOException
- * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
- * @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
- */
- public static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[])
- throws IOException {
-
- int rawLen = xmldsigBytes.length/2;
-
- int i;
-
- for (i = rawLen; (i > 0) && (xmldsigBytes[rawLen - i] == 0); i--);
-
- int j = i;
-
- if (xmldsigBytes[rawLen - i] < 0) {
- j += 1;
- }
-
- int k;
-
- for (k = rawLen; (k > 0) && (xmldsigBytes[2*rawLen - k] == 0); k--);
-
- int l = k;
-
- if (xmldsigBytes[2*rawLen - k] < 0) {
- l += 1;
- }
-
- int len = 2 + j + 2 + l;
- if (len > 255) {
- throw new IOException("Invalid XMLDSIG format of ECDSA signature");
- }
- int offset;
- byte asn1Bytes[];
- if (len < 128) {
- asn1Bytes = new byte[2 + 2 + j + 2 + l];
- offset = 1;
- } else {
- asn1Bytes = new byte[3 + 2 + j + 2 + l];
- asn1Bytes[1] = (byte) 0x81;
- offset = 2;
- }
- asn1Bytes[0] = 48;
- asn1Bytes[offset++] = (byte) len;
- asn1Bytes[offset++] = 2;
- asn1Bytes[offset++] = (byte) j;
-
- System.arraycopy(xmldsigBytes, rawLen - i, asn1Bytes, (offset + j) - i, i);
-
- offset += j;
-
- asn1Bytes[offset++] = 2;
- asn1Bytes[offset++] = (byte) l;
-
- System.arraycopy(xmldsigBytes, 2*rawLen - k, asn1Bytes, (offset + l) - k, k);
-
- return asn1Bytes;
- }
-
- /**
- * Constructor SignatureRSA
- *
- * @throws XMLSignatureException
- */
- public SignatureECDSA() throws XMLSignatureException {
-
- String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
-
- if (log.isDebugEnabled())
- log.debug("Created SignatureECDSA using " + algorithmID);
- String provider=JCEMapper.getProviderId();
- try {
- if (provider==null) {
- this._signatureAlgorithm = Signature.getInstance(algorithmID);
- } else {
- this._signatureAlgorithm = Signature.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);
- }
- }
-
- /** @inheritDoc */
- protected void engineSetParameter(AlgorithmParameterSpec params)
- throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.setParameter(params);
- } catch (InvalidAlgorithmParameterException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected boolean engineVerify(byte[] signature)
- throws XMLSignatureException {
-
- try {
- byte[] jcebytes = SignatureECDSA.convertXMLDSIGtoASN1(signature);
-
- if (log.isDebugEnabled())
- log.debug("Called ECDSA.verify() on " + Base64.encode(signature));
-
- return this._signatureAlgorithm.verify(jcebytes);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- } catch (IOException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @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) {
+ 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;
+ Signature sig = this.signatureAlgorithm;
try {
- this._signatureAlgorithm = Signature.getInstance
- (_signatureAlgorithm.getAlgorithm());
+ this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isDebugEnabled()) {
log.debug("Exception when reinstantiating Signature:" + e);
}
- this._signatureAlgorithm = sig;
+ this.signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex);
- }
- }
+ }
+ }
+
+ /** @inheritDoc */
+ protected byte[] engineSign() throws XMLSignatureException {
+ try {
+ byte jcebytes[] = this.signatureAlgorithm.sign();
+
+ return SignatureECDSA.convertASN1toXMLDSIG(jcebytes);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ } catch (IOException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
- /** @inheritDoc */
- protected byte[] engineSign() throws XMLSignatureException {
+ /** @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 {
- byte jcebytes[] = this._signatureAlgorithm.sign();
+ try {
+ this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
+ } catch (InvalidKeyException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @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);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineUpdate(byte[] input) throws XMLSignatureException {
+ try {
+ this.signatureAlgorithm.update(input);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected void engineUpdate(byte input) throws XMLSignatureException {
+ try {
+ this.signatureAlgorithm.update(input);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
- return SignatureECDSA.convertASN1toXMLDSIG(jcebytes);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- } catch (IOException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @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);
- }
- }
-
- /** @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);
- }
- }
-
- /** @inheritDoc */
- protected void engineUpdate(byte[] input) throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.update(input);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected void engineUpdate(byte input) throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.update(input);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected void engineUpdate(byte buf[], int offset, int len)
- throws XMLSignatureException {
-
- try {
- this._signatureAlgorithm.update(buf, offset, len);
- } catch (SignatureException ex) {
- throw new XMLSignatureException("empty", ex);
- }
- }
-
- /** @inheritDoc */
- protected String engineGetJCEAlgorithmString() {
- return this._signatureAlgorithm.getAlgorithm();
- }
-
- /** @inheritDoc */
- protected String engineGetJCEProviderName() {
- return this._signatureAlgorithm.getProvider().getName();
- }
-
- /** @inheritDoc */
- protected void engineSetHMACOutputLength(int HMACOutputLength)
- throws XMLSignatureException {
- throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
- }
-
- /** @inheritDoc */
- protected void engineInitSign(
- Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
- throws XMLSignatureException {
- throw new XMLSignatureException(
- "algorithms.CannotUseAlgorithmParameterSpecOnRSA");
- }
-
- /**
- * Class SignatureRSASHA1
- *
- * @author $Author: marcx $
- * @version $Revision: 351176 $
- */
- public static class SignatureECDSASHA1 extends SignatureECDSA {
-
- /**
- * Constructor SignatureRSASHA1
- *
- * @throws XMLSignatureException
- */
- public SignatureECDSASHA1() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1;
- }
- }
-
- /**
- * Class SignatureRSASHA256
- *
- * @author Alex Dupre
- * @version $Revision$
- */
- public static class SignatureECDSASHA256 extends SignatureECDSA {
-
- /**
- * Constructor SignatureRSASHA256
- *
- * @throws XMLSignatureException
- */
- public SignatureECDSASHA256() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256;
- }
- }
-
- /**
- * Class SignatureRSASHA384
- *
- * @author Alex Dupre
- * @version $Revision$
- */
- public static class SignatureECDSASHA384 extends SignatureECDSA {
-
- /**
- * Constructor SignatureRSASHA384
- *
- * @throws XMLSignatureException
- */
- public SignatureECDSASHA384() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA384;
- }
- }
-
- /**
- * Class SignatureRSASHA512
- *
- * @author Alex Dupre
- * @version $Revision$
- */
- public static class SignatureECDSASHA512 extends SignatureECDSA {
-
- /**
- * Constructor SignatureRSASHA512
- *
- * @throws XMLSignatureException
- */
- public SignatureECDSASHA512() throws XMLSignatureException {
- super();
- }
-
- /** @inheritDoc */
- public String engineGetURI() {
- return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512;
- }
- }
+ /** @inheritDoc */
+ protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
+ try {
+ this.signatureAlgorithm.update(buf, offset, len);
+ } catch (SignatureException ex) {
+ throw new XMLSignatureException("empty", ex);
+ }
+ }
+
+ /** @inheritDoc */
+ protected String engineGetJCEAlgorithmString() {
+ return this.signatureAlgorithm.getAlgorithm();
+ }
+
+ /** @inheritDoc */
+ protected String engineGetJCEProviderName() {
+ return this.signatureAlgorithm.getProvider().getName();
+ }
+
+ /** @inheritDoc */
+ protected void engineSetHMACOutputLength(int HMACOutputLength)
+ throws XMLSignatureException {
+ throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
+ }
+
+ /** @inheritDoc */
+ protected void engineInitSign(
+ Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
+ ) throws XMLSignatureException {
+ throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnRSA");
+ }
+
+ /**
+ * Class SignatureRSASHA1
+ *
+ * @author $Author: marcx $
+ */
+ public static class SignatureECDSASHA1 extends SignatureECDSA {
+ /**
+ * Constructor SignatureRSASHA1
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureECDSASHA1() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1;
+ }
+ }
+
+ /**
+ * Class SignatureRSASHA256
+ *
+ * @author Alex Dupre
+ */
+ public static class SignatureECDSASHA256 extends SignatureECDSA {
+
+ /**
+ * Constructor SignatureRSASHA256
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureECDSASHA256() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256;
+ }
+ }
+
+ /**
+ * Class SignatureRSASHA384
+ *
+ * @author Alex Dupre
+ */
+ public static class SignatureECDSASHA384 extends SignatureECDSA {
+
+ /**
+ * Constructor SignatureRSASHA384
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureECDSASHA384() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA384;
+ }
+ }
+
+ /**
+ * Class SignatureRSASHA512
+ *
+ * @author Alex Dupre
+ */
+ public static class SignatureECDSASHA512 extends SignatureECDSA {
+
+ /**
+ * Constructor SignatureRSASHA512
+ *
+ * @throws XMLSignatureException
+ */
+ public SignatureECDSASHA512() throws XMLSignatureException {
+ super();
+ }
+
+ /** @inheritDoc */
+ public String engineGetURI() {
+ return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512;
+ }
+ }
}