From f94a5d5833e055c9a0c5e92719d1cd4db4f844b2 Mon Sep 17 00:00:00 2001 From: beth Date: Mon, 6 Jan 2025 11:39:49 +0100 Subject: [PATCH 1/2] Fix: Removed "duplicated" ICryptoSessionKeyProvider instances for AES keys --- .../crypto/ICryptoSessionKeyProvider.java | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/phase4-lib/src/main/java/com/helger/phase4/crypto/ICryptoSessionKeyProvider.java b/phase4-lib/src/main/java/com/helger/phase4/crypto/ICryptoSessionKeyProvider.java index 2a83f0221..99d4b003f 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/crypto/ICryptoSessionKeyProvider.java +++ b/phase4-lib/src/main/java/com/helger/phase4/crypto/ICryptoSessionKeyProvider.java @@ -27,7 +27,7 @@ public interface ICryptoSessionKeyProvider { /** - * Get or create a new symmetric session key. This method may only throws + * Get or create a new symmetric session key. This method may only throw * unchecked exceptions. * * @return A new session key. Must not be null. @@ -35,6 +35,9 @@ public interface ICryptoSessionKeyProvider @Nonnull SecretKey getSessionKey (); + /** + * Session key provider for AES-128 keys that can be used e.g. for AES-128-CBC or AES-128-GCM + */ ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_128 = () -> { try { @@ -47,18 +50,9 @@ public interface ICryptoSessionKeyProvider } }; - ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_128_GCM = () -> { - try - { - final KeyGenerator aKeyGen = KeyUtils.getKeyGenerator (WSS4JConstants.AES_128_GCM); - return aKeyGen.generateKey (); - } - catch (final WSSecurityException ex) - { - throw new IllegalStateException ("Failed to create session key (AES-128-GCM)", ex); - } - }; - + /** + * Session key provider for AES-256 keys that can be used e.g. for AES-256-CBC or AES-256-GCM + */ ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_256 = () -> { try { @@ -71,15 +65,4 @@ public interface ICryptoSessionKeyProvider } }; - ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_256_GCM = () -> { - try - { - final KeyGenerator aKeyGen = KeyUtils.getKeyGenerator (WSS4JConstants.AES_256_GCM); - return aKeyGen.generateKey (); - } - catch (final WSSecurityException ex) - { - throw new IllegalStateException ("Failed to create session key (AES-256-GCM)", ex); - } - }; } From cd7426f46ef7450ed5ab399b00e59c4d0bedcbbd Mon Sep 17 00:00:00 2001 From: beth Date: Mon, 6 Jan 2025 11:58:29 +0100 Subject: [PATCH 2/2] Added back old instances for compability reasons (with @Deprecated) --- .../com/helger/phase4/crypto/ICryptoSessionKeyProvider.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phase4-lib/src/main/java/com/helger/phase4/crypto/ICryptoSessionKeyProvider.java b/phase4-lib/src/main/java/com/helger/phase4/crypto/ICryptoSessionKeyProvider.java index 99d4b003f..b55d81b9f 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/crypto/ICryptoSessionKeyProvider.java +++ b/phase4-lib/src/main/java/com/helger/phase4/crypto/ICryptoSessionKeyProvider.java @@ -50,6 +50,9 @@ public interface ICryptoSessionKeyProvider } }; + @Deprecated (forRemoval = true, since = "3.0.2") + ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_128_GCM = INSTANCE_RANDOM_AES_128; + /** * Session key provider for AES-256 keys that can be used e.g. for AES-256-CBC or AES-256-GCM */ @@ -65,4 +68,7 @@ public interface ICryptoSessionKeyProvider } }; + @Deprecated (forRemoval = true, since = "3.0.2") + ICryptoSessionKeyProvider INSTANCE_RANDOM_AES_256_GCM = INSTANCE_RANDOM_AES_256; + }