[java-idp-plugin-vci] 02/02: credential offer configuration, pre-authorized code minimum now 32 characters, code length non-negative

Codeberg noreply at shibboleth.net
Mon Nov 16 12:19:35 UTC 2026


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

codeberg pushed a commit to branch dev/REVIEWOFFERCALLERFLOW
in repository java-idp-plugin-vci.

View the commit online:
https://codeberg.org/Shibboleth/java-idp-plugin-vci/commit/1a2b33b886bc3e8ff5c03eddbdbd60563cf10f38

commit 1a2b33b886bc3e8ff5c03eddbdbd60563cf10f38
Author: Janne Lauros <janne.lauros at csc.fi>
AuthorDate: Mon Nov 16 14:19:01 2026 +0200

    credential offer configuration, pre-authorized code minimum now 32 characters, code length non-negative
---
 README.md                                          |  9 ++---
 .../profile/config/OpenIDVCIConfiguration.java     |  6 ++--
 .../impl/AbstractOpenIDVCIConfiguration.java       | 36 +++++++++++++++-----
 .../plugin/openidvci/conf/openid-vci.properties    |  5 +--
 ...tOpenIDVCICredentialOfferConfigurationTest.java | 39 ++++++++++++++++++++--
 .../impl/BuildCredentialOfferTokenTest.java        |  6 ++--
 6 files changed, 79 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md
index 73c65c7..8a8ea48 100644
--- a/README.md
+++ b/README.md
@@ -4715,8 +4715,9 @@ Endpoint `/idp/profile/openid/vci/credential-offer`, profile ID `http://geant.or
 | Name | Type | Default | Description |
 |---|---|---|---|
 | `preAuthorizedCodeLifetime` | Duration | `PT10M` | Lifetime of the pre-authorized code. Property `openidvci.preAuthorizedCode.defaultLifetime`. |
-| `preAuthorizedCodeLength` | Integer | `0` | `0` seals the whole offer in the code, no storage needed. `10` to `128` is a code of that length for an offer in storage. Property `openidvci.preAuthorizedCode.defaultLength`. |
-| `tokenEndpointAuthMethods` | Collection<String> | | Client authentication of the caller. |
+| `preAuthorizedCodeLength` | Integer | `0` | `0` seals the whole offer by data sealer, no storage needed. Use `32` to `128` if you want storage based
+shorter code. Property `openidvci.preAuthorizedCode.defaultLength`. |
+| `tokenEndpointAuthMethods` | Collection<String> | | Client authentication of the caller. Use `client_secret_basic`. |
 | `inboundInterceptorFlows` | List<String> | | Interceptor flows run after the request is decoded, before authentication. |
 | `outboundInterceptorFlows` | List<String> | | Interceptor flows run before the response is sent, also for an error response. |
 | `messageHandler` | Function<MessageContext,Exception> | | Of the OP plugin. Runs on the inbound message before authentication and on the outbound one before encoding. |
@@ -5042,9 +5043,9 @@ The file comes with the plugin and is loaded automatically.
 | `openidvci.authn.flows` | Regex | `OpenIDVCIClient` | Login flows of the VCI endpoints. `OpenIDVCIClient` is the `OAuth2Client` flow with `attest_jwt_client_auth`. |
 | `openidvci.credentialTimestampPrecision` | Duration | `PT1H` | Instant of issuance is rounded down to this. Keep it shorter than the shortest lifetime. |
 | `openidvci.batchSize` | Integer | `2` | Default of `batchSize`. |
-| `openidvci.StorageService` | Bean ID | **shibboleth.StorageService** | Storage of Credential Offers. Server side storage. |
+| `openidvci.StorageService` | Bean ID | **shibboleth.StorageService** | Storage of Credential Offers, used only when `openidvci.preAuthorizedCode.defaultLength` is not `0`. Server side storage. |
 | `openidvci.preAuthorizedCode.defaultLifetime` | Duration | `PT10M` | Lifetime of pre-authorized codes. |
-| `openidvci.preAuthorizedCode.defaultLength` | Integer | `0` | `0` self-contained, `10` to `128` stored. |
+| `openidvci.preAuthorizedCode.defaultLength` | Integer | `0` | `0` self-contained, `32` to `128` stored. |
 | `openidvci.nonce.lifetime` | Duration | `PT5M` | Lifetime of the `c_nonce` of the Nonce endpoint. |
 | `openidvci.requestParser.TokenRequest` | Bean ID | | Custom parser of the Token endpoint request, a `CustomNimbusRequestParser` of the OP plugin returning an `OpenIDVCITokenRequest`. |
 
diff --git a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/OpenIDVCIConfiguration.java b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/OpenIDVCIConfiguration.java
index bc8b482..55a3546 100644
--- a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/OpenIDVCIConfiguration.java
+++ b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/OpenIDVCIConfiguration.java
@@ -29,6 +29,7 @@ import net.shibboleth.oidc.security.jose.SignatureSigningConfiguration;
 import net.shibboleth.oidc.security.jose.SignatureValidationConfiguration;
 import net.shibboleth.profile.config.ConditionalProfileConfiguration;
 import net.shibboleth.shared.annotation.ConfigurationSetting;
+import net.shibboleth.shared.annotation.constraint.NonNegative;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.annotation.constraint.Positive;
 
@@ -69,8 +70,7 @@ public interface OpenIDVCIConfiguration extends ConditionalProfileConfiguration
     public static final String PROFILE_ID_NONCE = "http://geant.org/ns/profiles/openid/vci/nonce";
 
     /**
-     * Get pre-authorized code length. Length of zero means there is no requirement
-     * and code does not require storage configuration.
+     * Get pre-authorized code length, 0 for a sealed code.
      *
      * <p>
      * Defaults to 0.
@@ -81,7 +81,7 @@ public interface OpenIDVCIConfiguration extends ConditionalProfileConfiguration
      * @return pre-authorized code length
      */
     @ConfigurationSetting(name = "preAuthorizedCodeLength")
-    @Positive
+    @NonNegative
     @Nonnull
     Integer getPreAuthorizedCodeLength(@Nullable final ProfileRequestContext profileRequestContext);
 
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/AbstractOpenIDVCIConfiguration.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/AbstractOpenIDVCIConfiguration.java
index f23ccc3..8a1c539 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/AbstractOpenIDVCIConfiguration.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/AbstractOpenIDVCIConfiguration.java
@@ -30,6 +30,7 @@ import net.shibboleth.oidc.jwt.claims.ClaimsValidator;
 import net.shibboleth.oidc.profile.config.impl.AbstractOIDCSSOConfiguration;
 import net.shibboleth.oidc.security.jose.SignatureSigningConfiguration;
 import net.shibboleth.oidc.security.jose.SignatureValidationConfiguration;
+import net.shibboleth.shared.annotation.constraint.NonNegative;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.annotation.constraint.Positive;
 import net.shibboleth.shared.logic.Constraint;
@@ -41,7 +42,7 @@ public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConf
         implements OpenIDVCIConfiguration {
 
     /** Minimum length of a stored pre-authorized code. */
-    public static final int MIN_PRE_AUTHORIZED_CODE_LENGTH = 10;
+    public static final int MIN_PRE_AUTHORIZED_CODE_LENGTH = 32;
 
     /** Maximum length of a stored pre-authorized code. */
     public static final int MAX_PRE_AUTHORIZED_CODE_LENGTH = 128;
@@ -131,33 +132,52 @@ public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConf
         preAuthorizedCodeLifetimeLookupStrategy = FunctionSupport.constant(lifetime);
     }
 
+    /**
+     * Set the lookup strategy for the lifetime of a pre-authorized code.
+     *
+     * @param strategy lookup strategy
+     */
+    public void setPreAuthorizedCodeLifetimeLookupStrategy(
+            @Nonnull final Function<ProfileRequestContext, Duration> strategy) {
+        preAuthorizedCodeLifetimeLookupStrategy = Constraint.isNotNull(strategy, "Lookup strategy cannot be null");
+    }
+
     /** {@inheritDoc} */
     @Override
-    @Positive
+    @NonNegative
     @Nonnull
     public Integer getPreAuthorizedCodeLength(@Nullable final ProfileRequestContext profileRequestContext) {
         final Integer codeLength = preAuthorizedCodeLengthLookupStrategy.apply(profileRequestContext);
 
         Constraint.isTrue(codeLength != null && (codeLength == 0
                 || codeLength >= MIN_PRE_AUTHORIZED_CODE_LENGTH && codeLength <= MAX_PRE_AUTHORIZED_CODE_LENGTH),
-                "Pre-authorized code length must be 0 or from 10 to 128");
+                "Pre-authorized code length must be 0 or from 32 to 128");
         return codeLength;
     }
 
     /**
-     * Set the pre-authorized code length. Length of zero means there is no
-     * requirement and code does not require storage configuration.
+     * Set the pre-authorized code length, 0 for a sealed code.
      * 
-     * @param codeLength length of the pre-authorized code.
+     * @param codeLength length of the pre-authorized code
      */
-    public void setPreAuthorizedCodeLength(@Positive @Nonnull final Integer codeLength) {
+    public void setPreAuthorizedCodeLength(@NonNegative @Nonnull final Integer codeLength) {
         Constraint.isTrue(codeLength != null && (codeLength == 0
                 || codeLength >= MIN_PRE_AUTHORIZED_CODE_LENGTH && codeLength <= MAX_PRE_AUTHORIZED_CODE_LENGTH),
-                "Pre-authorized code length must be 0 or from 10 to 128");
+                "Pre-authorized code length must be 0 or from 32 to 128");
 
         preAuthorizedCodeLengthLookupStrategy = FunctionSupport.constant(codeLength);
     }
 
+    /**
+     * Set the lookup strategy for the pre-authorized code length.
+     *
+     * @param strategy lookup strategy
+     */
+    public void setPreAuthorizedCodeLengthLookupStrategy(
+            @Nonnull final Function<ProfileRequestContext, Integer> strategy) {
+        preAuthorizedCodeLengthLookupStrategy = Constraint.isNotNull(strategy, "Lookup strategy cannot be null");
+    }
+
     /** {@inheritDoc} */
     @Override
     @Positive
diff --git a/openid-vci-impl/src/main/resources/org/geant/shibboleth/plugin/openidvci/conf/openid-vci.properties b/openid-vci-impl/src/main/resources/org/geant/shibboleth/plugin/openidvci/conf/openid-vci.properties
index 1d8a9e7..e2bcc2b 100644
--- a/openid-vci-impl/src/main/resources/org/geant/shibboleth/plugin/openidvci/conf/openid-vci.properties
+++ b/openid-vci-impl/src/main/resources/org/geant/shibboleth/plugin/openidvci/conf/openid-vci.properties
@@ -14,12 +14,13 @@ openidvci.issuer =
 # For most deployments, the default is sufficient to accomodate a variety of methods
 #openidvci.authn.flows = OAuth2Client
 
-# Storage for Credential Offers. Requires server-side storage
+# Storage for Credential Offers when pre-authorized codes are stored. Requires server-side storage
 #openidvci.StorageService = shibboleth.StorageService
 
 # Default lifetime of the pre-authorized code
 #openidvci.preAuthorizedCode.defaultLifetime = PT10M
-# Length of pre-authorized codes (0 = sealed offer, 10 to 128 = offer in storage)
+# Length of pre-authorized codes (0 = sealed offer, 32 to 128 = offer in storage; 32 hex characters
+# give the 2^-128 guessing probability of RFC 6749 section 10.10, 40 the recommended 2^-160)
 #openidvci.preAuthorizedCode.defaultLength = 0
 
 # Lifetime of the c_nonce of the Nonce endpoint
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfigurationTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfigurationTest.java
index db903e4..c59c862 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfigurationTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfigurationTest.java
@@ -16,6 +16,7 @@
 
 package org.geant.shibboleth.plugin.openidvci.profile.config.impl;
 
+import java.time.Duration;
 import java.util.List;
 
 import org.testng.Assert;
@@ -50,7 +51,7 @@ public class DefaultOpenIDVCICredentialOfferConfigurationTest {
 
     @DataProvider(name = "validCodeLengths")
     public Object[][] validCodeLengths() {
-        return new Object[][] { { 0 }, { 10 }, { 128 } };
+        return new Object[][] { { 0 }, { 32 }, { 128 } };
     }
 
     @Test(dataProvider = "validCodeLengths")
@@ -64,7 +65,7 @@ public class DefaultOpenIDVCICredentialOfferConfigurationTest {
 
     @DataProvider(name = "invalidCodeLengths")
     public Object[][] invalidCodeLengths() {
-        return new Object[][] { { -1 }, { 9 }, { 129 } };
+        return new Object[][] { { -1 }, { 31 }, { 129 } };
     }
 
     @Test(dataProvider = "invalidCodeLengths", expectedExceptions = ConstraintViolationException.class)
@@ -72,4 +73,38 @@ public class DefaultOpenIDVCICredentialOfferConfigurationTest {
         new DefaultOpenIDVCICredentialOfferConfiguration().setPreAuthorizedCodeLength(length);
     }
 
+    @Test
+    public void testPreAuthorizedCodeLengthLookupStrategy() {
+        final DefaultOpenIDVCICredentialOfferConfiguration configuration =
+                new DefaultOpenIDVCICredentialOfferConfiguration();
+        configuration.setPreAuthorizedCodeLengthLookupStrategy(prc -> 40);
+
+        Assert.assertEquals(configuration.getPreAuthorizedCodeLength(null), 40);
+    }
+
+    @Test(expectedExceptions = ConstraintViolationException.class)
+    public void testInvalidPreAuthorizedCodeLengthLookupStrategy() {
+        final DefaultOpenIDVCICredentialOfferConfiguration configuration =
+                new DefaultOpenIDVCICredentialOfferConfiguration();
+        configuration.setPreAuthorizedCodeLengthLookupStrategy(prc -> 10);
+        configuration.getPreAuthorizedCodeLength(null);
+    }
+
+    @Test
+    public void testPreAuthorizedCodeLifetimeLookupStrategy() {
+        final DefaultOpenIDVCICredentialOfferConfiguration configuration =
+                new DefaultOpenIDVCICredentialOfferConfiguration();
+        configuration.setPreAuthorizedCodeLifetimeLookupStrategy(prc -> Duration.ofMinutes(5));
+
+        Assert.assertEquals(configuration.getPreAuthorizedCodeLifetime(null), Duration.ofMinutes(5));
+    }
+
+    @Test(expectedExceptions = ConstraintViolationException.class)
+    public void testInvalidPreAuthorizedCodeLifetimeLookupStrategy() {
+        final DefaultOpenIDVCICredentialOfferConfiguration configuration =
+                new DefaultOpenIDVCICredentialOfferConfiguration();
+        configuration.setPreAuthorizedCodeLifetimeLookupStrategy(prc -> Duration.ZERO);
+        configuration.getPreAuthorizedCodeLifetime(null);
+    }
+
 }
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java
index f547aa3..401ef65 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java
@@ -122,12 +122,12 @@ public class BuildCredentialOfferTokenTest {
 
     @Test
     public void testStoredCode() throws Exception {
-        configuration.setPreAuthorizedCodeLength(10);
+        configuration.setPreAuthorizedCodeLength(32);
         action.initialize();
         ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
 
         final String code = getCode();
-        Assert.assertEquals(code.length(), 10);
+        Assert.assertEquals(code.length(), 32);
         final CredentialOfferObject offer = cache.getCredentialOffer(code);
         Assert.assertNotNull(offer);
         Assert.assertEquals(offer.getClientID().getValue(), "offer-caller");
@@ -172,7 +172,7 @@ public class BuildCredentialOfferTokenTest {
 
     @Test
     public void testStorageFailure() throws Exception {
-        configuration.setPreAuthorizedCodeLength(10);
+        configuration.setPreAuthorizedCodeLength(32);
         action.setCredentialOfferCache(new FailingCache());
         action.initialize();
 

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


More information about the commits mailing list