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 2019/09/02 09:55:20 UTC
svn commit: r1866270 - in /santuario/xml-security-java/trunk/src:
main/java/org/apache/xml/security/algorithms/
main/java/org/apache/xml/security/algorithms/implementations/
main/java/org/apache/xml/security/signature/
test/java/org/apache/xml/security...
Author: coheigea
Date: Mon Sep 2 09:55:19 2019
New Revision: 1866270
URL: http://svn.apache.org/viewvc?rev=1866270&view=rev
Log:
SANTUARIO-509 - XMLSignature with a specified security Provider
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/SignatureAlgorithm.java
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
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/SignedInfo.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignature.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/SignatureAlgorithm.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/SignatureAlgorithm.java?rev=1866270&r1=1866269&r2=1866270&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/SignatureAlgorithm.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/algorithms/SignatureAlgorithm.java Mon Sep 2 09:55:19 2019
@@ -18,7 +18,10 @@
*/
package org.apache.xml.security.algorithms;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.security.Key;
+import java.security.Provider;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Map;
@@ -66,10 +69,14 @@ public class SignatureAlgorithm extends
* @throws XMLSecurityException
*/
public SignatureAlgorithm(Document doc, String algorithmURI) throws XMLSecurityException {
+ this(doc, algorithmURI, null);
+ }
+
+ public SignatureAlgorithm(Document doc, String algorithmURI, Provider provider) throws XMLSecurityException {
super(doc, algorithmURI);
this.algorithmURI = algorithmURI;
- signatureAlgorithmSpi = getSignatureAlgorithmSpi(algorithmURI);
+ signatureAlgorithmSpi = getSignatureAlgorithmSpi(algorithmURI, provider);
signatureAlgorithmSpi.engineGetContextFromElement(getElement());
}
@@ -84,10 +91,16 @@ public class SignatureAlgorithm extends
public SignatureAlgorithm(
Document doc, String algorithmURI, int hmacOutputLength
) throws XMLSecurityException {
+ this(doc, algorithmURI, hmacOutputLength, null);
+ }
+
+ public SignatureAlgorithm(
+ Document doc, String algorithmURI, int hmacOutputLength, Provider provider
+ ) throws XMLSecurityException {
super(doc, algorithmURI);
this.algorithmURI = algorithmURI;
- signatureAlgorithmSpi = getSignatureAlgorithmSpi(algorithmURI);
+ signatureAlgorithmSpi = getSignatureAlgorithmSpi(algorithmURI, provider);
signatureAlgorithmSpi.engineGetContextFromElement(getElement());
signatureAlgorithmSpi.engineSetHMACOutputLength(hmacOutputLength);
@@ -102,7 +115,11 @@ public class SignatureAlgorithm extends
* @throws XMLSecurityException
*/
public SignatureAlgorithm(Element element, String baseURI) throws XMLSecurityException {
- this(element, baseURI, true);
+ this(element, baseURI, true, null);
+ }
+
+ public SignatureAlgorithm(Element element, String baseURI, Provider provider) throws XMLSecurityException {
+ this(element, baseURI, true, provider);
}
/**
@@ -116,6 +133,12 @@ public class SignatureAlgorithm extends
public SignatureAlgorithm(
Element element, String baseURI, boolean secureValidation
) throws XMLSecurityException {
+ this(element, baseURI, secureValidation, null);
+ }
+
+ public SignatureAlgorithm(
+ Element element, String baseURI, boolean secureValidation, Provider provider
+ ) throws XMLSecurityException {
super(element, baseURI);
algorithmURI = this.getURI();
@@ -131,14 +154,14 @@ public class SignatureAlgorithm extends
throw new XMLSecurityException("signature.signatureAlgorithm", exArgs);
}
- signatureAlgorithmSpi = getSignatureAlgorithmSpi(algorithmURI);
+ signatureAlgorithmSpi = getSignatureAlgorithmSpi(algorithmURI, provider);
signatureAlgorithmSpi.engineGetContextFromElement(getElement());
}
/**
* Get a SignatureAlgorithmSpi object corresponding to the algorithmURI argument
*/
- private static SignatureAlgorithmSpi getSignatureAlgorithmSpi(String algorithmURI)
+ private static SignatureAlgorithmSpi getSignatureAlgorithmSpi(String algorithmURI, Provider provider)
throws XMLSignatureException {
try {
Class<? extends SignatureAlgorithmSpi> implementingClass =
@@ -148,8 +171,20 @@ public class SignatureAlgorithm extends
Object[] exArgs = { algorithmURI };
throw new XMLSignatureException("algorithms.NoSuchAlgorithmNoEx", exArgs);
}
+
+ if (provider != null) {
+ try {
+ Constructor<? extends SignatureAlgorithmSpi> constructor = implementingClass.getConstructor(Provider.class);
+ return constructor.newInstance(provider);
+
+ } catch (NoSuchMethodException e) {
+ LOG.warn("Class \"{}\" does not have a constructor with Provider", implementingClass);
+ }
+ }
+
return implementingClass.newInstance();
- } catch (IllegalAccessException | InstantiationException | NullPointerException ex) {
+
+ } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NullPointerException ex) {
Object[] exArgs = { algorithmURI, ex.getMessage() };
throw new XMLSignatureException(ex, "algorithms.NoSuchAlgorithm", exArgs);
}
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=1866270&r1=1866269&r2=1866270&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 Mon Sep 2 09:55:19 2019
@@ -21,6 +21,7 @@ package org.apache.xml.security.algorith
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
+import java.security.Provider;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
@@ -69,11 +70,15 @@ public abstract class IntegrityHmac exte
* @throws XMLSignatureException
*/
public IntegrityHmac() throws XMLSignatureException {
+ this(null);
+ }
+
+ public IntegrityHmac(Provider provider) throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
LOG.debug("Created IntegrityHmacSHA1 using {}", algorithmID);
try {
- this.macAlgorithm = Mac.getInstance(algorithmID);
+ this.macAlgorithm = (provider == null) ? Mac.getInstance(algorithmID) : Mac.getInstance(algorithmID, provider);
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
@@ -370,6 +375,10 @@ public abstract class IntegrityHmac exte
super();
}
+ public IntegrityHmacSHA1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/**
* Method engineGetURI
* {@inheritDoc}
@@ -398,6 +407,10 @@ public abstract class IntegrityHmac exte
super();
}
+ public IntegrityHmacSHA224(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/**
* Method engineGetURI
*
@@ -426,6 +439,10 @@ public abstract class IntegrityHmac exte
super();
}
+ public IntegrityHmacSHA256(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/**
* Method engineGetURI
*
@@ -454,6 +471,10 @@ public abstract class IntegrityHmac exte
super();
}
+ public IntegrityHmacSHA384(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/**
* Method engineGetURI
* {@inheritDoc}
@@ -482,6 +503,10 @@ public abstract class IntegrityHmac exte
super();
}
+ public IntegrityHmacSHA512(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/**
* Method engineGetURI
* {@inheritDoc}
@@ -510,6 +535,10 @@ public abstract class IntegrityHmac exte
super();
}
+ public IntegrityHmacRIPEMD160(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/**
* Method engineGetURI
*
@@ -538,6 +567,10 @@ public abstract class IntegrityHmac exte
super();
}
+ public IntegrityHmacMD5(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/**
* Method engineGetURI
*
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=1866270&r1=1866269&r2=1866270&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 Mon Sep 2 09:55:19 2019
@@ -21,8 +21,10 @@ package org.apache.xml.security.algorith
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
+import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
+import java.security.Provider;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
@@ -51,23 +53,33 @@ public abstract class SignatureBaseRSA e
* @throws XMLSignatureException
*/
public SignatureBaseRSA() throws XMLSignatureException {
- String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+ this(null);
+ }
+ public SignatureBaseRSA(Provider provider) throws XMLSignatureException {
+ String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
LOG.debug("Created SignatureRSA using {}", algorithmID);
- String provider = JCEMapper.getProviderId();
+
try {
if (provider == null) {
- this.signatureAlgorithm = Signature.getInstance(algorithmID);
+ String providerId = JCEMapper.getProviderId();
+ if (providerId == null) {
+ this.signatureAlgorithm = Signature.getInstance(algorithmID);
+
+ } else {
+ this.signatureAlgorithm = Signature.getInstance(algorithmID, providerId);
+ }
+
} else {
this.signatureAlgorithm = Signature.getInstance(algorithmID, provider);
}
- } catch (java.security.NoSuchAlgorithmException ex) {
- Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
+ } catch (NoSuchAlgorithmException ex) {
+ Object[] exArgs = {algorithmID, ex.getLocalizedMessage()};
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
- } catch (NoSuchProviderException ex) {
- Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
+ } catch (NoSuchProviderException ex) {
+ Object[] exArgs = {algorithmID, ex.getLocalizedMessage()};
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
}
}
@@ -225,6 +237,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1;
@@ -245,6 +261,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA224(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA224;
@@ -265,6 +285,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA256(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256;
@@ -285,6 +309,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA384(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA384;
@@ -305,6 +333,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA512(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512;
@@ -325,6 +357,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSARIPEMD160(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_RIPEMD160;
@@ -345,6 +381,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSAMD5(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5;
@@ -365,6 +405,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA1MGF1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1_MGF1;
@@ -385,6 +429,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA224MGF1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA224_MGF1;
@@ -405,6 +453,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA256MGF1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256_MGF1;
@@ -425,6 +477,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA384MGF1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA384_MGF1;
@@ -445,6 +501,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA512MGF1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512_MGF1;
@@ -465,6 +525,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA3_224MGF1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_224_MGF1;
@@ -485,6 +549,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA3_256MGF1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_256_MGF1;
@@ -505,6 +573,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA3_384MGF1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_384_MGF1;
@@ -525,6 +597,10 @@ public abstract class SignatureBaseRSA e
super();
}
+ public SignatureRSASHA3_512MGF1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA3_512_MGF1;
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=1866270&r1=1866269&r2=1866270&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 Mon Sep 2 09:55:19 2019
@@ -22,7 +22,10 @@ import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
import java.security.PrivateKey;
+import java.security.Provider;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
@@ -66,22 +69,33 @@ public class SignatureDSA extends Signat
* @throws XMLSignatureException
*/
public SignatureDSA() throws XMLSignatureException {
+ this(null);
+ }
+
+ public SignatureDSA(Provider provider) throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(engineGetURI());
LOG.debug("Created SignatureDSA using {}", algorithmID);
- String provider = JCEMapper.getProviderId();
try {
if (provider == null) {
- this.signatureAlgorithm = Signature.getInstance(algorithmID);
+ String providerId = JCEMapper.getProviderId();
+ if (providerId == null) {
+ this.signatureAlgorithm = Signature.getInstance(algorithmID);
+
+ } else {
+ this.signatureAlgorithm = Signature.getInstance(algorithmID, providerId);
+ }
+
} else {
- this.signatureAlgorithm =
- Signature.getInstance(algorithmID, provider);
+ this.signatureAlgorithm = Signature.getInstance(algorithmID, provider);
}
- } catch (java.security.NoSuchAlgorithmException ex) {
- Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
+
+ } catch (NoSuchAlgorithmException ex) {
+ Object[] exArgs = {algorithmID, ex.getLocalizedMessage()};
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
- } catch (java.security.NoSuchProviderException ex) {
- Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
+
+ } catch (NoSuchProviderException ex) {
+ Object[] exArgs = {algorithmID, ex.getLocalizedMessage()};
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
}
}
@@ -283,6 +297,10 @@ public class SignatureDSA extends Signat
super();
}
+ public SHA256(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_DSA_SHA256;
}
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=1866270&r1=1866269&r2=1866270&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 Mon Sep 2 09:55:19 2019
@@ -24,6 +24,7 @@ import java.security.InvalidKeyException
import java.security.Key;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
+import java.security.Provider;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
@@ -90,24 +91,33 @@ public abstract class SignatureECDSA ext
* @throws XMLSignatureException
*/
public SignatureECDSA() throws XMLSignatureException {
+ this(null);
+ }
+ public SignatureECDSA(Provider provider) throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
-
LOG.debug("Created SignatureECDSA using {}", algorithmID);
- String provider = JCEMapper.getProviderId();
+
try {
if (provider == null) {
- this.signatureAlgorithm = Signature.getInstance(algorithmID);
+ String providerId = JCEMapper.getProviderId();
+ if (providerId == null) {
+ this.signatureAlgorithm = Signature.getInstance(algorithmID);
+
+ } else {
+ this.signatureAlgorithm = Signature.getInstance(algorithmID, providerId);
+ }
+
} 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);
}
}
@@ -278,6 +288,10 @@ public abstract class SignatureECDSA ext
super();
}
+ public SignatureECDSASHA1(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1;
@@ -298,6 +312,10 @@ public abstract class SignatureECDSA ext
super();
}
+ public SignatureECDSASHA224(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA224;
@@ -319,6 +337,10 @@ public abstract class SignatureECDSA ext
super();
}
+ public SignatureECDSASHA256(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256;
@@ -340,6 +362,10 @@ public abstract class SignatureECDSA ext
super();
}
+ public SignatureECDSASHA384(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA384;
@@ -361,6 +387,10 @@ public abstract class SignatureECDSA ext
super();
}
+ public SignatureECDSASHA512(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512;
@@ -381,6 +411,10 @@ public abstract class SignatureECDSA ext
super();
}
+ public SignatureECDSARIPEMD160(Provider provider) throws XMLSignatureException {
+ super(provider);
+ }
+
/** {@inheritDoc} */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_RIPEMD160;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/SignedInfo.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/SignedInfo.java?rev=1866270&r1=1866269&r2=1866270&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/SignedInfo.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/SignedInfo.java Mon Sep 2 09:55:19 2019
@@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.security.Provider;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
@@ -49,7 +50,7 @@ import org.xml.sax.SAXException;
public class SignedInfo extends Manifest {
/** Field signatureAlgorithm */
- private SignatureAlgorithm signatureAlgorithm;
+ private final SignatureAlgorithm signatureAlgorithm;
/** Field c14nizedBytes */
private byte[] c14nizedBytes;
@@ -84,7 +85,25 @@ public class SignedInfo extends Manifest
public SignedInfo(
Document doc, String signatureMethodURI, String canonicalizationMethodURI
) throws XMLSecurityException {
- this(doc, signatureMethodURI, 0, canonicalizationMethodURI);
+ this(doc, signatureMethodURI, 0, canonicalizationMethodURI, null);
+ }
+
+ /**
+ * Constructs {@link SignedInfo} using given Canonicalization algorithm and
+ * Signature algorithm.
+ *
+ * @param doc <code>SignedInfo</code> is placed in this document
+ * @param signatureMethodURI URI representation of the Digest and
+ * Signature algorithm
+ * @param canonicalizationMethodURI URI representation of the
+ * Canonicalization method
+ * @param provider security provider to use
+ * @throws XMLSecurityException
+ */
+ public SignedInfo(
+ Document doc, String signatureMethodURI, String canonicalizationMethodURI, Provider provider
+ ) throws XMLSecurityException {
+ this(doc, signatureMethodURI, 0, canonicalizationMethodURI, provider);
}
/**
@@ -102,6 +121,13 @@ public class SignedInfo extends Manifest
Document doc, String signatureMethodURI,
int hMACOutputLength, String canonicalizationMethodURI
) throws XMLSecurityException {
+ this(doc, signatureMethodURI, hMACOutputLength, canonicalizationMethodURI, null);
+ }
+
+ public SignedInfo(
+ Document doc, String signatureMethodURI,
+ int hMACOutputLength, String canonicalizationMethodURI, Provider provider
+ ) throws XMLSecurityException {
super(doc);
c14nMethod =
@@ -113,9 +139,9 @@ public class SignedInfo extends Manifest
if (hMACOutputLength > 0) {
this.signatureAlgorithm =
- new SignatureAlgorithm(getDocument(), signatureMethodURI, hMACOutputLength);
+ new SignatureAlgorithm(getDocument(), signatureMethodURI, hMACOutputLength, provider);
} else {
- this.signatureAlgorithm = new SignatureAlgorithm(getDocument(), signatureMethodURI);
+ this.signatureAlgorithm = new SignatureAlgorithm(getDocument(), signatureMethodURI, provider);
}
signatureMethod = this.signatureAlgorithm.getElement();
@@ -132,6 +158,12 @@ public class SignedInfo extends Manifest
public SignedInfo(
Document doc, Element signatureMethodElem, Element canonicalizationMethodElem
) throws XMLSecurityException {
+ this(doc, signatureMethodElem, canonicalizationMethodElem, null);
+ }
+
+ public SignedInfo(
+ Document doc, Element signatureMethodElem, Element canonicalizationMethodElem, Provider provider
+ ) throws XMLSecurityException {
super(doc);
// Check this?
this.c14nMethod = canonicalizationMethodElem;
@@ -139,7 +171,7 @@ public class SignedInfo extends Manifest
addReturnToSelf();
this.signatureAlgorithm =
- new SignatureAlgorithm(signatureMethodElem, null);
+ new SignatureAlgorithm(signatureMethodElem, null, provider);
signatureMethod = this.signatureAlgorithm.getElement();
appendSelf(signatureMethod);
@@ -159,7 +191,7 @@ public class SignedInfo extends Manifest
* Answer</A>
*/
public SignedInfo(Element element, String baseURI) throws XMLSecurityException {
- this(element, baseURI, true);
+ this(element, baseURI, true, null);
}
/**
@@ -177,13 +209,32 @@ public class SignedInfo extends Manifest
public SignedInfo(
Element element, String baseURI, boolean secureValidation
) throws XMLSecurityException {
+ this(element, baseURI, secureValidation, null);
+ }
+
+ /**
+ * Build a {@link SignedInfo} from an {@link Element}
+ *
+ * @param element <code>SignedInfo</code>
+ * @param baseURI the URI of the resource where the XML instance was stored
+ * @param secureValidation whether secure validation is enabled or not
+ * @param provider security provider to use
+ * @throws XMLSecurityException
+ * @see <A HREF="http://lists.w3.org/Archives/Public/w3c-ietf-xmldsig/2001OctDec/0033.html">
+ * Question</A>
+ * @see <A HREF="http://lists.w3.org/Archives/Public/w3c-ietf-xmldsig/2001OctDec/0054.html">
+ * Answer</A>
+ */
+ public SignedInfo(
+ Element element, String baseURI, boolean secureValidation, Provider provider
+ ) throws XMLSecurityException {
// Parse the Reference children and Id attribute in the Manifest
super(reparseSignedInfoElem(element, secureValidation), baseURI, secureValidation);
c14nMethod = XMLUtils.getNextElement(element.getFirstChild());
signatureMethod = XMLUtils.getNextElement(c14nMethod.getNextSibling());
this.signatureAlgorithm =
- new SignatureAlgorithm(signatureMethod, this.getBaseURI(), secureValidation);
+ new SignatureAlgorithm(signatureMethod, this.getBaseURI(), secureValidation, provider);
}
private static Element reparseSignedInfoElem(Element element, boolean secureValidation)
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignature.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignature.java?rev=1866270&r1=1866269&r2=1866270&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignature.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/signature/XMLSignature.java Mon Sep 2 09:55:19 2019
@@ -21,6 +21,7 @@ package org.apache.xml.security.signatur
import java.io.IOException;
import java.io.OutputStream;
import java.security.Key;
+import java.security.Provider;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
@@ -202,7 +203,7 @@ public final class XMLSignature extends
org.slf4j.LoggerFactory.getLogger(XMLSignature.class);
/** ds:Signature.ds:SignedInfo element */
- private SignedInfo signedInfo;
+ private final SignedInfo signedInfo;
/** ds:Signature.ds:KeyInfo */
private KeyInfo keyInfo;
@@ -234,7 +235,25 @@ public final class XMLSignature extends
*/
public XMLSignature(Document doc, String baseURI, String signatureMethodURI)
throws XMLSecurityException {
- this(doc, baseURI, signatureMethodURI, 0, Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
+ this(doc, baseURI, signatureMethodURI, 0, Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS, null);
+ }
+
+ /**
+ * This creates a new <CODE>ds:Signature</CODE> Element and adds an empty
+ * <CODE>ds:SignedInfo</CODE>.
+ * The <code>ds:SignedInfo</code> is initialized with the specified Signature
+ * algorithm and Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS which is REQUIRED
+ * by the spec. This method's main use is for creating a new signature.
+ *
+ * @param doc Document in which the signature will be appended after creation.
+ * @param baseURI URI to be used as context for all relative URIs.
+ * @param signatureMethodURI signature algorithm to use.
+ * @param provider security provider to use.
+ * @throws XMLSecurityException
+ */
+ public XMLSignature(Document doc, String baseURI, String signatureMethodURI, Provider provider)
+ throws XMLSecurityException {
+ this(doc, baseURI, signatureMethodURI, 0, Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS, provider);
}
/**
@@ -250,7 +269,25 @@ public final class XMLSignature extends
int hmacOutputLength) throws XMLSecurityException {
this(
doc, baseURI, signatureMethodURI, hmacOutputLength,
- Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS
+ Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS, null
+ );
+ }
+
+ /**
+ * Constructor XMLSignature
+ *
+ * @param doc
+ * @param baseURI
+ * @param signatureMethodURI the Signature method to be used.
+ * @param hmacOutputLength
+ * @param provider security provider to use.
+ * @throws XMLSecurityException
+ */
+ public XMLSignature(Document doc, String baseURI, String signatureMethodURI,
+ int hmacOutputLength, Provider provider) throws XMLSecurityException {
+ this(
+ doc, baseURI, signatureMethodURI, hmacOutputLength,
+ Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS, provider
);
}
@@ -270,7 +307,28 @@ public final class XMLSignature extends
String signatureMethodURI,
String canonicalizationMethodURI
) throws XMLSecurityException {
- this(doc, baseURI, signatureMethodURI, 0, canonicalizationMethodURI);
+ this(doc, baseURI, signatureMethodURI, 0, canonicalizationMethodURI, null);
+ }
+
+ /**
+ * Constructor XMLSignature
+ *
+ * @param doc
+ * @param baseURI
+ * @param signatureMethodURI the Signature method to be used.
+ * @param canonicalizationMethodURI the canonicalization algorithm to be
+ * used to c14nize the SignedInfo element.
+ * @param provider security provider to use.
+ * @throws XMLSecurityException
+ */
+ public XMLSignature(
+ Document doc,
+ String baseURI,
+ String signatureMethodURI,
+ String canonicalizationMethodURI,
+ Provider provider
+ ) throws XMLSecurityException {
+ this(doc, baseURI, signatureMethodURI, 0, canonicalizationMethodURI, provider);
}
/**
@@ -290,6 +348,17 @@ public final class XMLSignature extends
int hmacOutputLength,
String canonicalizationMethodURI
) throws XMLSecurityException {
+ this(doc, baseURI, signatureMethodURI, hmacOutputLength, canonicalizationMethodURI, null);
+ }
+
+ public XMLSignature(
+ Document doc,
+ String baseURI,
+ String signatureMethodURI,
+ int hmacOutputLength,
+ String canonicalizationMethodURI,
+ Provider provider
+ ) throws XMLSecurityException {
super(doc);
String xmlnsDsPrefix = getDefaultPrefix(Constants.SignatureSpecNS);
@@ -307,7 +376,7 @@ public final class XMLSignature extends
this.baseURI = baseURI;
this.signedInfo =
new SignedInfo(
- getDocument(), signatureMethodURI, hmacOutputLength, canonicalizationMethodURI
+ getDocument(), signatureMethodURI, hmacOutputLength, canonicalizationMethodURI, provider
);
appendSelf(this.signedInfo);
@@ -325,15 +394,25 @@ public final class XMLSignature extends
* Creates a XMLSignature in a Document
* @param doc
* @param baseURI
- * @param SignatureMethodElem
- * @param CanonicalizationMethodElem
+ * @param signatureMethodElem
+ * @param canonicalizationMethodElem
* @throws XMLSecurityException
*/
public XMLSignature(
Document doc,
String baseURI,
- Element SignatureMethodElem,
- Element CanonicalizationMethodElem
+ Element signatureMethodElem,
+ Element canonicalizationMethodElem
+ ) throws XMLSecurityException {
+ this(doc, baseURI, signatureMethodElem, canonicalizationMethodElem, null);
+ }
+
+ public XMLSignature(
+ Document doc,
+ String baseURI,
+ Element signatureMethodElem,
+ Element canonicalizationMethodElem,
+ Provider provider
) throws XMLSecurityException {
super(doc);
@@ -351,7 +430,7 @@ public final class XMLSignature extends
this.baseURI = baseURI;
this.signedInfo =
- new SignedInfo(getDocument(), SignatureMethodElem, CanonicalizationMethodElem);
+ new SignedInfo(getDocument(), signatureMethodElem, canonicalizationMethodElem, provider);
appendSelf(this.signedInfo);
addReturnToSelf();
@@ -375,7 +454,22 @@ public final class XMLSignature extends
*/
public XMLSignature(Element element, String baseURI)
throws XMLSignatureException, XMLSecurityException {
- this(element, baseURI, true);
+ this(element, baseURI, true, null);
+ }
+
+ /**
+ * This will parse the element and construct the Java Objects.
+ * That will allow a user to validate the signature.
+ *
+ * @param element ds:Signature element that contains the whole signature
+ * @param baseURI URI to be prepended to all relative URIs
+ * @param provider security provider to use
+ * @throws XMLSecurityException
+ * @throws XMLSignatureException if the signature is badly formatted
+ */
+ public XMLSignature(Element element, String baseURI, Provider provider)
+ throws XMLSignatureException, XMLSecurityException {
+ this(element, baseURI, true, provider);
}
/**
@@ -390,6 +484,22 @@ public final class XMLSignature extends
*/
public XMLSignature(Element element, String baseURI, boolean secureValidation)
throws XMLSignatureException, XMLSecurityException {
+ this(element, baseURI, secureValidation, null);
+ }
+
+ /**
+ * This will parse the element and construct the Java Objects.
+ * That will allow a user to validate the signature.
+ *
+ * @param element ds:Signature element that contains the whole signature
+ * @param baseURI URI to be prepended to all relative URIs
+ * @param secureValidation whether secure secureValidation is enabled or not
+ * @param provider security provider to use
+ * @throws XMLSecurityException
+ * @throws XMLSignatureException if the signature is badly formatted
+ */
+ public XMLSignature(Element element, String baseURI, boolean secureValidation, Provider provider)
+ throws XMLSignatureException, XMLSecurityException {
super(element, baseURI);
// check out SignedInfo child
@@ -402,7 +512,7 @@ public final class XMLSignature extends
}
// create a SignedInfo object from that element
- this.signedInfo = new SignedInfo(signedInfoElem, baseURI, secureValidation);
+ this.signedInfo = new SignedInfo(signedInfoElem, baseURI, secureValidation, provider);
// get signedInfoElem again in case it has changed
signedInfoElem = XMLUtils.getNextElement(element.getFirstChild());
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java?rev=1866270&r1=1866269&r2=1866270&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java Mon Sep 2 09:55:19 2019
@@ -18,8 +18,11 @@
*/
package org.apache.xml.security.test.dom.algorithms;
+import java.lang.reflect.Field;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
+import java.security.Provider;
+import java.util.Map;
import org.apache.xml.security.algorithms.SignatureAlgorithm;
import org.apache.xml.security.exceptions.XMLSecurityException;
@@ -27,6 +30,9 @@ import org.apache.xml.security.signature
import org.apache.xml.security.utils.XMLUtils;
import org.w3c.dom.Document;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
public class SignatureAlgorithmTest {
static org.slf4j.Logger LOG =
@@ -62,4 +68,20 @@ public class SignatureAlgorithmTest {
otherSignatureAlgorithm.sign();
}
+ @org.junit.jupiter.api.Test
+ public void testConstructionWithProvider() throws Exception {
+ Field algorithmHashField = SignatureAlgorithm.class.getDeclaredField("algorithmHash");
+ algorithmHashField.setAccessible(true);
+ @SuppressWarnings("unchecked")
+ Map<String, Class<?>> algorithmHash = (Map<String, Class<?>>)algorithmHashField.get(null);
+ assertFalse(algorithmHash.isEmpty());
+
+ Document doc = XMLUtils.newDocument();
+ Provider provider = new org.bouncycastle.jce.provider.BouncyCastleProvider();
+
+ for (String algorithmURI : algorithmHash.keySet()) {
+ SignatureAlgorithm signatureAlgorithm = new SignatureAlgorithm(doc, algorithmURI, provider);
+ assertEquals("BC", signatureAlgorithm.getJCEProviderName());
+ }
+ }
}