2222import java .security .PrivilegedAction ;
2323import java .security .spec .AlgorithmParameterSpec ;
2424
25+ import javax .crypto .spec .GCMParameterSpec ;
2526import javax .crypto .spec .IvParameterSpec ;
2627
27- import org .apache .xml .security .utils .ClassLoaderUtils ;
2828import org .apache .xml .security .utils .EncryptionConstants ;
2929
3030public final class XMLCipherUtil {
@@ -45,27 +45,27 @@ public final class XMLCipherUtil {
4545 * @return the newly constructed AlgorithmParameterSpec instance, appropriate for the
4646 * specified algorithm
4747 */
48- public static AlgorithmParameterSpec constructBlockCipherParameters (String algorithm , byte [] iv , Class <?> callingClass ) {
48+ public static AlgorithmParameterSpec constructBlockCipherParameters (String algorithm , byte [] iv ) {
4949 if (EncryptionConstants .ALGO_ID_BLOCKCIPHER_AES128_GCM .equals (algorithm )
5050 || EncryptionConstants .ALGO_ID_BLOCKCIPHER_AES192_GCM .equals (algorithm )
5151 || EncryptionConstants .ALGO_ID_BLOCKCIPHER_AES256_GCM .equals (algorithm )) {
52- return constructBlockCipherParametersForGCMAlgorithm (algorithm , iv , callingClass );
52+ return constructBlockCipherParametersForGCMAlgorithm (algorithm , iv );
5353 } else {
5454 LOG .debug ("Saw non-AES-GCM mode block cipher, returning IvParameterSpec: {}" , algorithm );
5555 return new IvParameterSpec (iv );
5656 }
5757 }
5858
59- public static AlgorithmParameterSpec constructBlockCipherParameters (boolean gcmAlgorithm , byte [] iv , Class <?> callingClass ) {
59+ public static AlgorithmParameterSpec constructBlockCipherParameters (boolean gcmAlgorithm , byte [] iv ) {
6060 if (gcmAlgorithm ) {
61- return constructBlockCipherParametersForGCMAlgorithm ("AES/GCM/NoPadding" , iv , callingClass );
61+ return constructBlockCipherParametersForGCMAlgorithm ("AES/GCM/NoPadding" , iv );
6262 } else {
6363 LOG .debug ("Saw non-AES-GCM mode block cipher, returning IvParameterSpec" );
6464 return new IvParameterSpec (iv );
6565 }
6666 }
6767
68- private static AlgorithmParameterSpec constructBlockCipherParametersForGCMAlgorithm (String algorithm , byte [] iv , Class <?> callingClass ) {
68+ private static AlgorithmParameterSpec constructBlockCipherParametersForGCMAlgorithm (String algorithm , byte [] iv ) {
6969 if (gcmUseIvParameterSpec ) {
7070 // This override allows to support Java 1.7+ with (usually older versions of) third-party security
7171 // providers which support or even require GCM via IvParameterSpec rather than GCMParameterSpec,
@@ -76,20 +76,8 @@ private static AlgorithmParameterSpec constructBlockCipherParametersForGCMAlgori
7676
7777 LOG .debug ("Saw AES-GCM block cipher, attempting to create GCMParameterSpec: {}" , algorithm );
7878
79- try {
80- // This class only added in Java 1.7. So load reflectively until Santuario starts targeting a minimum of Java 1.7.
81- Class <?> gcmSpecClass = ClassLoaderUtils .loadClass ("javax.crypto.spec.GCMParameterSpec" , callingClass );
82-
83- // XML Encryption 1.1 mandates a 128-bit Authentication Tag for AES GCM modes.
84- AlgorithmParameterSpec gcmSpec = (AlgorithmParameterSpec ) gcmSpecClass .getConstructor (int .class , byte [].class )
85- .newInstance (128 , iv );
86- LOG .debug ("Successfully created GCMParameterSpec" );
87- return gcmSpec ;
88- } catch (Exception e ) {
89- // This handles the case of Java < 1.7 with a third-party security provider that
90- // supports GCM mode using only an IvParameterSpec, such as BouncyCastle.
91- LOG .debug ("Failed to create GCMParameterSpec, falling back to returning IvParameterSpec" , e );
92- return new IvParameterSpec (iv );
93- }
79+ GCMParameterSpec gcmSpec = new GCMParameterSpec (128 , iv );
80+ LOG .debug ("Successfully created GCMParameterSpec" );
81+ return gcmSpec ;
9482 }
9583}
0 commit comments