[java-oidc-common] branch main updated: JCOMOIDC-198 - Client information encryption method resolver should return default value if not set in metadata

Codeberg noreply at shibboleth.net
Thu Nov 26 12:47:40 UTC 2026


This is an automated email from the git hooks/post-receive script.

codeberg pushed a commit to branch main
in repository java-oidc-common.

View the commit online:
https://codeberg.org/Shibboleth/java-oidc-common/commit/ba72ae677129a3d982f47cc9501455979a99fe5b

The following commit(s) were added to refs/heads/main by this push:
     new ba72ae67 JCOMOIDC-198 - Client information encryption method resolver should return default value if not set in metadata
ba72ae67 is described below

commit ba72ae677129a3d982f47cc9501455979a99fe5b
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Thu Nov 26 14:47:06 2026 +0200

    JCOMOIDC-198 - Client information encryption method resolver should return default value if not set in metadata
    
    https://shibboleth.atlassian.net/browse/JCOMOIDC-198
---
 ...tionDataEncryptionAlgorithmsLookupStrategy.java |  10 +-
 ...DataEncryptionAlgorithmsLookupStrategyTest.java | 107 +++++++++++++++++++++
 2 files changed, 113 insertions(+), 4 deletions(-)

diff --git a/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/jose/impl/ClientInformationDataEncryptionAlgorithmsLookupStrategy.java b/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/jose/impl/ClientInformationDataEncryptionAlgorithmsLookupStrategy.java
index 30b78572..fa6d805b 100644
--- a/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/jose/impl/ClientInformationDataEncryptionAlgorithmsLookupStrategy.java
+++ b/oidc-common-crypto-impl/src/main/java/net/shibboleth/oidc/security/jose/impl/ClientInformationDataEncryptionAlgorithmsLookupStrategy.java
@@ -25,6 +25,7 @@ import javax.annotation.Nullable;
 import org.opensaml.xmlsec.algorithm.AlgorithmRegistry;
 import org.slf4j.Logger;
 
+import com.nimbusds.jose.EncryptionMethod;
 import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
 
 import net.shibboleth.oidc.security.jose.criterion.ClientInformationCriterion;
@@ -49,7 +50,7 @@ public class ClientInformationDataEncryptionAlgorithmsLookupStrategy
     
     /** 
      * A strategy to locate the encryption method ('enc') appropriate for the JWT to be encrypted.
-     * Can return {@code null} if the metadata does not contain a value (which is means no encryption should be done).
+     * Can return {@code null} if the metadata does not contain a value: default value A128CBC-HS256 will be used.
      */
     @Nonnull private final Function<OIDCClientInformation, String> clientEncryptionMethodLookupStrategy;
     
@@ -94,11 +95,12 @@ public class ClientInformationDataEncryptionAlgorithmsLookupStrategy
             return super.apply(criteria, includeExcludePredicate);
         }
         
-        final String dataEncryptionMethod = clientEncryptionMethodLookupStrategy.apply(metadata);        
+        String dataEncryptionMethod = clientEncryptionMethodLookupStrategy.apply(metadata);
         log.trace("Resolved effective data encryption algorithms from client metadata: {}", dataEncryptionMethod);
         if (dataEncryptionMethod == null) {
-            log.debug("Client metadata does not contain 'enc' algorithm value, returning empty list");
-            return Collections.emptyList();
+            log.debug("Client metadata does not contain 'enc' algorithm value, using default {}",
+                    EncryptionMethod.A128CBC_HS256);
+            dataEncryptionMethod = EncryptionMethod.A128CBC_HS256.getName();
         }
         
         final List<String> dataEncryptionAlgorithmsSupported =
diff --git a/oidc-common-crypto-impl/src/test/java/net/shibboleth/oidc/security/jose/impl/ClientInformationDataEncryptionAlgorithmsLookupStrategyTest.java b/oidc-common-crypto-impl/src/test/java/net/shibboleth/oidc/security/jose/impl/ClientInformationDataEncryptionAlgorithmsLookupStrategyTest.java
new file mode 100644
index 00000000..a49d9d05
--- /dev/null
+++ b/oidc-common-crypto-impl/src/test/java/net/shibboleth/oidc/security/jose/impl/ClientInformationDataEncryptionAlgorithmsLookupStrategyTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.oidc.security.jose.impl;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.List;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+
+import org.mockito.Mockito;
+import org.opensaml.xmlsec.algorithm.AlgorithmRegistry;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicates;
+import com.nimbusds.jose.EncryptionMethod;
+import com.nimbusds.oauth2.sdk.id.ClientID;
+import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
+import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
+
+import net.shibboleth.oidc.jwa.algorithm.descriptors.EncryptionA128CBCHS256;
+import net.shibboleth.oidc.jwa.algorithm.descriptors.EncryptionA128GCM;
+import net.shibboleth.oidc.jwa.algorithm.descriptors.EncryptionA192CBCHS384;
+import net.shibboleth.oidc.jwa.algorithm.descriptors.EncryptionA256CBCHS512;
+import net.shibboleth.oidc.jwa.support.EncryptionConstants;
+import net.shibboleth.oidc.security.jose.criterion.ClientInformationCriterion;
+import net.shibboleth.oidc.security.jose.criterion.EncryptionConfigurationCriterion;
+import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.resolver.CriteriaSet;
+
+/**
+ * Unit tests for {@link ClientInformationDataEncryptionAlgorithmsLookupStrategy}.
+ */
+public class ClientInformationDataEncryptionAlgorithmsLookupStrategyTest {
+    
+    private ClientInformationDataEncryptionAlgorithmsLookupStrategy strategy;
+    
+    private BasicEncryptionConfiguration config;
+    
+    private CriteriaSet criteria;
+
+    @SuppressWarnings({ "unchecked", "null" })
+    @Nonnull private Function<OIDCClientInformation, String> methodLookup = Mockito.mock(Function.class);
+
+    @SuppressWarnings("null")
+    @BeforeMethod
+    public void setup() {
+        final AlgorithmRegistry algorithmRegistry = new AlgorithmRegistry();
+        algorithmRegistry.register(new EncryptionA128GCM());
+        algorithmRegistry.register(new EncryptionA128CBCHS256());
+        algorithmRegistry.register(new EncryptionA256CBCHS512());
+        algorithmRegistry.register(new EncryptionA192CBCHS384());
+
+        config = new BasicEncryptionConfiguration();
+        config.setDataEncryptionAlgorithms(
+                CollectionSupport.listOf(EncryptionConstants.ALGO_ID_ENC_ALG_A128CBC_HS256,
+                        EncryptionConstants.ALGO_ID_ENC_ALG_A128GCM, EncryptionConstants.ALGO_ID_ENC_ALG_A256CBC_HS512,
+                        EncryptionConstants.ALGO_ID_ENC_ALG_A192CBC_HS384));
+
+        final OIDCClientInformation clientInformation =
+                new OIDCClientInformation(new ClientID("mockClient"), new OIDCClientMetadata());
+        criteria = new CriteriaSet(new EncryptionConfigurationCriterion(CollectionSupport.singletonList(config)),
+                new ClientInformationCriterion(clientInformation));
+
+        strategy = new ClientInformationDataEncryptionAlgorithmsLookupStrategy(methodLookup, algorithmRegistry);
+    }
+
+    @Test
+    public void testNullEnc_alwaysYes_default() {
+        Mockito.when(methodLookup.apply(Mockito.any())).thenReturn(null);
+        final List<String> keyAlgs = strategy.apply(criteria, Predicates.alwaysTrue());
+        assert keyAlgs != null;
+        assertEquals(keyAlgs.size(), 1);
+        assertEquals(keyAlgs.get(0), EncryptionMethod.A128CBC_HS256.getName());
+    }
+
+    @Test
+    public void testNullEnc_defaultExcluded_emptyList() {
+        Mockito.when(methodLookup.apply(Mockito.any())).thenReturn(null);
+        final List<String> keyAlgs = strategy.apply(criteria, Predicates.alwaysFalse());
+        assert keyAlgs != null;
+        assertEquals(keyAlgs.size(), 0);
+    }
+
+    @Test
+    public void testExcludedEnc_defaultExcluded_emptyList() {
+        Mockito.when(methodLookup.apply(Mockito.any())).thenReturn(EncryptionMethod.A256GCM.getName());
+        final List<String> keyAlgs = strategy.apply(criteria, Predicates.alwaysFalse());
+        assert keyAlgs != null;
+        assertEquals(keyAlgs.size(), 0);
+    }
+
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list