[java-idp-plugin-vci] 04/06: status list token, 404 for querying list that should no exist, sign with curve of the key, missing signing parameters are now error, empty list not encoded for each call

Codeberg noreply at shibboleth.net
Thu Nov 12 14:29:39 UTC 2026


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

codeberg pushed a commit to branch main
in repository java-idp-plugin-vci.

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

commit 6bf0868454e4ab9d86ea7e67b17af13d248db84f
Author: Janne Lauros <janne.lauros at csc.fi>
AuthorDate: Thu Nov 12 15:29:18 2026 +0200

    status list token, 404 for querying list that should no exist, sign with curve of the key, missing signing parameters are now error, empty list not encoded for each call
---
 .../messaging/error/StatusListError.java           |   7 +-
 .../profile/impl/FormStatusListToken.java          |  81 ++---
 .../profile/impl/SignStatusListToken.java          |  77 ++---
 .../profile/impl/FormStatusListTokenTest.java      | 334 +++++++++++++++++++++
 .../profile/impl/SignStatusListTokenTest.java      | 214 +++++++++++++
 5 files changed, 634 insertions(+), 79 deletions(-)

diff --git a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/error/StatusListError.java b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/error/StatusListError.java
index 0994148..7a6e395 100644
--- a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/error/StatusListError.java
+++ b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/messaging/error/StatusListError.java
@@ -30,12 +30,7 @@ public final class StatusListError {
     public static final ErrorObject UNKNOWN_STATUS_LIST = new ErrorObject("unknown_status_list",
             "No status list of that name.", 404);
 
-    /**
-     * The list is not published anymore.
-     *
-     * Separate from an unknown list, so that a verifier can tell a retired list
-     * from one that never existed.
-     */
+    /** The list is not published anymore. */
     @Nonnull
     public static final ErrorObject RETIRED_STATUS_LIST = new ErrorObject("retired_status_list",
             "Status list is no longer published, every credential in it having expired.", 410);
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/FormStatusListToken.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/FormStatusListToken.java
index d26d4a1..79adc19 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/FormStatusListToken.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/FormStatusListToken.java
@@ -67,9 +67,13 @@ import net.shibboleth.shared.primitive.LoggerFactory;
  */
 public class FormStatusListToken extends AbstractProfileAction {
 
+    /** Compressed and encoded status list with no slot revoked. */
+    @Nonnull
+    private static final String EMPTY_LIST = StatusListCodec.encode(StatusListCodec.empty());
+
     /** Class logger. */
     @Nonnull
-    private Logger log = LoggerFactory.getLogger(FormStatusListToken.class);
+    private final Logger log = LoggerFactory.getLogger(FormStatusListToken.class);
 
     /** Strategy used to obtain the issuer value. */
     @Nonnull
@@ -83,10 +87,6 @@ public class FormStatusListToken extends AbstractProfileAction {
     @Nonnull
     private Duration ttl = Duration.ofHours(1);
 
-    /** Compressed and encoded status list with no slot revoked. */
-    @NonnullAfterInit
-    private String emptyList;
-
     /** Issuer of the token. */
     @Nullable
     private String issuerId;
@@ -107,7 +107,7 @@ public class FormStatusListToken extends AbstractProfileAction {
     @Nonnull
     private Function<ProfileRequestContext, List<SignatureSigningConfiguration>> configurationLookupStrategy;
 
-    /** The value of the request parameter naming the list, tag and all. */
+    /** The value of the request parameter identifying the list, tag and all. */
     @Nullable
     private String reference;
 
@@ -144,9 +144,6 @@ public class FormStatusListToken extends AbstractProfileAction {
     /**
      * Set how long a published list may be cached.
      *
-     * Also the delay before a revocation is noticed. A verifier with a cached list
-     * does not see it before the cache expires.
-     *
      * @param cacheLifetime positive lifetime
      */
     public void setTtl(@Nonnull final Duration cacheLifetime) {
@@ -163,14 +160,10 @@ public class FormStatusListToken extends AbstractProfileAction {
         if (statusListStore == null) {
             throw new ComponentInitializationException("StatusListStore cannot be null");
         }
-        emptyList = StatusListCodec.encode(StatusListCodec.empty());
-        log.debug("{} Status list of {} slots with none revoked encodes to {} characters", getLogPrefix(),
-                StatusListParameters.CAPACITY, emptyList.length());
     }
 
     /**
-     * Set the url this deployment is reached at, a did:web issuer is derived from
-     * it.
+     * Set the url this deployment is reached at.
      *
      * @param issuer url of this deployment
      */
@@ -180,9 +173,7 @@ public class FormStatusListToken extends AbstractProfileAction {
     }
 
     /**
-     * Set the issuer identifier configured for this deployment, answering a list
-     * handed out under the plain issuer url. The keyword resolves to the issuer of
-     * the OP, a literal url to itself.
+     * Set the issuer identifier configured for this deployment.
      *
      * @param issuer the configured identifier
      */
@@ -193,7 +184,7 @@ public class FormStatusListToken extends AbstractProfileAction {
 
     /**
      * Set the strategy used to obtain the configurations Status List Tokens are
-     * signed by. A list handed out under a did:jwk issuer names a key of one of them.
+     * signed by.
      *
      * @param strategy lookup strategy
      */
@@ -208,8 +199,8 @@ public class FormStatusListToken extends AbstractProfileAction {
      *
      * @param profileRequestContext current profile request context
      * @param tag tag the request carries
-     * @return the issuer, or null when the tag names none this deployment answers
-     *         for
+     * @return the issuer, or null when the tag refers to none this deployment
+     *         answers for
      */
     @Nullable
     private String issuerOfTag(@Nonnull final ProfileRequestContext profileRequestContext,
@@ -225,7 +216,8 @@ public class FormStatusListToken extends AbstractProfileAction {
 
         final String thumbprint = StatusListIssuerTag.thumbprintOf(tag);
         if (thumbprint == null) {
-            log.error("Tag '{}' of the status list names no issuer this deployment answers for", tag);
+            log.warn("{} Tag '{}' of the status list names no issuer this deployment answers for", getLogPrefix(),
+                    tag);
             return null;
         }
 
@@ -244,23 +236,24 @@ public class FormStatusListToken extends AbstractProfileAction {
                     continue;
                 }
             } catch (final JOSEException e) {
-                log.warn("Unable to take a thumbprint of a signing key, leaving it out", e);
+                log.warn("{} Unable to take a thumbprint of a signing key, leaving it out", getLogPrefix(), e);
                 continue;
             }
             final String issuer = DidSupport.toDidJwk(candidate.getPublicKey());
             if (issuer == null) {
-                log.error("Key '{}' is of a type a did:jwk issuer cannot name", thumbprint);
+                log.warn("{} Key '{}' is of a type a did:jwk issuer cannot name", getLogPrefix(), thumbprint);
                 return null;
             }
             keyThumbprint = thumbprint;
             return issuer;
         }
 
-        log.error("No signing credential has thumbprint '{}', the key that signed those credentials is no longer "
-                + "among the ones Status List Tokens are signed with", thumbprint);
+        log.warn("{} No signing credential has thumbprint '{}', the key that signed those credentials is not "
+                + "among the ones Status List Tokens are signed with", getLogPrefix(), thumbprint);
         return null;
     }
 
+    // Checkstyle: ReturnCount|CyclomaticComplexity OFF
     /** {@inheritDoc} */
     @Override
     protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
@@ -269,7 +262,7 @@ public class FormStatusListToken extends AbstractProfileAction {
         }
         if (getHttpServletRequest() == null) {
             log.error("{} Profile action does not contain an HttpServletRequest", getLogPrefix());
-            ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
+            ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
             return false;
         }
         if (profileRequestContext.getOutboundMessageContext() == null) {
@@ -279,22 +272,18 @@ public class FormStatusListToken extends AbstractProfileAction {
         }
 
         reference = getHttpServletRequest().getParameter(StatusListParameters.BUCKET_PARAMETER);
+        if (reference == null) {
+            log.warn("{} Request has no parameter '{}'", getLogPrefix(), StatusListParameters.BUCKET_PARAMETER);
+            ActionSupport.buildEvent(profileRequestContext, StatusListEventIds.NO_STATUS_LIST);
+            return false;
+        }
         bucket = MonthlyBucketStrategy.parse(StatusListIssuerTag.bucketOf(reference));
         if (bucket == null) {
-            log.error("{} '{}' in parameter '{}' does not name a status list", getLogPrefix(), reference,
+            log.warn("{} '{}' in parameter '{}' does not name a status list", getLogPrefix(), reference,
                     StatusListParameters.BUCKET_PARAMETER);
             ActionSupport.buildEvent(profileRequestContext, StatusListEventIds.NO_STATUS_LIST);
             return false;
         }
-
-        final String tag = StatusListIssuerTag.tagOf(reference);
-        issuerId = tag == null ? issuerLookupStrategy.apply(profileRequestContext)
-                : issuerOfTag(profileRequestContext, tag);
-        if (issuerId == null) {
-            log.error("{} Unable to determine issuer of the status list token", getLogPrefix());
-            ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
-            return false;
-        }
         if (!bucket.end().isAfter(Instant.now())) {
             log.info("{} Status list {} ended at {} and is no longer published", getLogPrefix(), bucket.id(),
                     bucket.end());
@@ -302,8 +291,25 @@ public class FormStatusListToken extends AbstractProfileAction {
             return false;
         }
 
+        final String tag = StatusListIssuerTag.tagOf(reference);
+        if (tag == null) {
+            issuerId = issuerLookupStrategy.apply(profileRequestContext);
+            if (issuerId == null) {
+                log.error("{} Unable to determine issuer of the status list token", getLogPrefix());
+                ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+                return false;
+            }
+            return true;
+        }
+        issuerId = issuerOfTag(profileRequestContext, tag);
+        if (issuerId == null) {
+            ActionSupport.buildEvent(profileRequestContext, StatusListEventIds.NO_STATUS_LIST);
+            return false;
+        }
+
         return true;
     }
+    // Checkstyle: ReturnCount|CyclomaticComplexity ON
 
     /** {@inheritDoc} */
     @Override
@@ -314,13 +320,12 @@ public class FormStatusListToken extends AbstractProfileAction {
         final String list;
         try {
             final String stored = statusListStore.read(bucket);
-            list = stored == null ? emptyList : stored;
+            list = stored == null ? EMPTY_LIST : stored;
         } catch (final IOException e) {
             log.error("{} Unable to read status list {}: {}", getLogPrefix(), bucket.id(), e.getMessage());
             ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR);
             return;
         }
-        // The subject has to be the url the credential points at, tag and all.
         final String subject = getHttpServletRequest().getRequestURL().append('?')
                 .append(StatusListParameters.BUCKET_PARAMETER).append('=').append(reference).toString();
         final JWTClaimsSet claims = new JWTClaimsSet.Builder().issuer(issuerId).subject(subject)
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/SignStatusListToken.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/SignStatusListToken.java
index 8c0067c..2b622ba 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/SignStatusListToken.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/SignStatusListToken.java
@@ -41,6 +41,8 @@ import org.opensaml.security.x509.X509Credential;
 import org.slf4j.Logger;
 
 import com.nimbusds.jose.JOSEException;
+import com.nimbusds.jose.crypto.impl.ECDSA;
+import com.nimbusds.jose.jwk.ECKey;
 import com.nimbusds.jose.jwk.JWK;
 
 import net.shibboleth.idp.profile.AbstractProfileAction;
@@ -49,8 +51,6 @@ import net.shibboleth.oidc.security.jose.SignatureException;
 import net.shibboleth.oidc.security.jose.SignatureSigningConfiguration;
 import net.shibboleth.oidc.security.jose.SignatureSigningParameters;
 import net.shibboleth.oidc.security.jose.context.SecurityParametersContext;
-import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
-import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
 import net.shibboleth.shared.codec.EncodingException;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.logic.PredicateSupport;
@@ -58,11 +58,8 @@ import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
  * Action that signs claims in {@link StatusListTokenContext#getClaims} and
- * stores the result to {@link StatusListTokenContext#setSignedToken}.
- *
- * Signing is done with the parameters of the status list signing configuration,
- * which offers EC algorithms only. Sets the statuslist+jwt type header required
- * of the token.
+ * stores the result to {@link StatusListTokenContext#setSignedToken}, or to
+ * {@link StatusListTokenContext#setSignedCwt} for the CWT format.
  */
 public class SignStatusListToken extends AbstractProfileAction {
 
@@ -76,10 +73,10 @@ public class SignStatusListToken extends AbstractProfileAction {
 
     /** Class logger. */
     @Nonnull
-    private Logger log = LoggerFactory.getLogger(SignStatusListToken.class);
+    private final Logger log = LoggerFactory.getLogger(SignStatusListToken.class);
 
     /** Status list token context. */
-    @NonnullBeforeExec
+    @Nullable
     private StatusListTokenContext ctx;
 
     /**
@@ -94,7 +91,7 @@ public class SignStatusListToken extends AbstractProfileAction {
     private Function<ProfileRequestContext, StatusListTokenContext> statusListTokenContextLookupStrategy;
 
     /** The signature signing parameters. */
-    @NonnullAfterInit
+    @Nullable
     private SignatureSigningParameters signatureSigningParameters;
 
     /** Condition for signing the token in CWT format. */
@@ -150,16 +147,6 @@ public class SignStatusListToken extends AbstractProfileAction {
         cwtCondition = Constraint.isNotNull(condition, "CWT condition cannot be null");
     }
 
-    /**
-     * Get the signing parameters to apply.
-     *
-     * @return the signing parameters
-     */
-    @Nullable
-    public SignatureSigningParameters getSignatureSigningParameters() {
-        return signatureSigningParameters;
-    }
-
     /** {@inheritDoc} */
     @Override
     protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
@@ -176,18 +163,10 @@ public class SignStatusListToken extends AbstractProfileAction {
         }
 
         final SecurityParametersContext secParamCtx = securityParametersLookupStrategy.apply(profileRequestContext);
-        if (secParamCtx == null) {
-            log.debug("{} no security parameters context is available", getLogPrefix());
-            return false;
-        }
-
-        signatureSigningParameters = secParamCtx.getSignatureSigningParameters();
-        if (signatureSigningParameters == null) {
-            log.debug("{} no signature signing parameters available", getLogPrefix());
-            return false;
-        }
-        if (signatureSigningParameters.getSigningCredential() == null) {
-            log.debug("{} no signature signing credential available", getLogPrefix());
+        signatureSigningParameters = secParamCtx == null ? null : secParamCtx.getSignatureSigningParameters();
+        if (signatureSigningParameters == null || signatureSigningParameters.getSigningCredential() == null) {
+            log.error("{} No signature signing parameters to sign the status list token with", getLogPrefix());
+            ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_SEC_CFG);
             return false;
         }
         return true;
@@ -195,7 +174,7 @@ public class SignStatusListToken extends AbstractProfileAction {
 
     /**
      * Set the strategy used to obtain the configurations Status List Tokens are
-     * signed by, searched when the issuer names one key.
+     * signed by, searched when the issuer is bound to one key.
      *
      * @param strategy lookup strategy
      */
@@ -206,7 +185,7 @@ public class SignStatusListToken extends AbstractProfileAction {
     }
 
     /**
-     * Take the parameters signing with the key a thumbprint names.
+     * Take the parameters signing with the key of a thumbprint.
      *
      * @param profileRequestContext current profile request context
      * @param parameters parameters resolved by the signing configuration
@@ -228,8 +207,12 @@ public class SignStatusListToken extends AbstractProfileAction {
         for (final SignatureSigningConfiguration config : configurationLookupStrategy.apply(profileRequestContext)) {
             for (final Credential candidate : config.getSigningCredentials()) {
                 if (thumbprint.equals(thumbprintOf(candidate))) {
+                    final String algorithm = algorithmOf(candidate);
+                    if (algorithm == null) {
+                        return null;
+                    }
                     final SignatureSigningParameters required = new SignatureSigningParameters();
-                    required.setSignatureAlgorithm(parameters.getSignatureAlgorithm());
+                    required.setSignatureAlgorithm(algorithm);
                     required.setSigningCredential(candidate);
                     return required;
                 }
@@ -238,6 +221,28 @@ public class SignStatusListToken extends AbstractProfileAction {
         return null;
     }
 
+    /**
+     * Get the signature algorithm of the curve of the key of a credential.
+     *
+     * @param credential credential to read
+     * @return the algorithm, or null when the key is not an EC key of a supported
+     *         curve
+     */
+    @Nullable
+    private String algorithmOf(@Nonnull final Credential credential) {
+
+        if (!(CredentialConversionUtil.credentialToKey(credential) instanceof final ECKey key)) {
+            log.warn("{} Signing key is not an EC key", getLogPrefix());
+            return null;
+        }
+        try {
+            return ECDSA.resolveAlgorithm(key.getCurve()).getName();
+        } catch (final JOSEException e) {
+            log.warn("{} No signature algorithm for the curve of the signing key", getLogPrefix(), e);
+            return null;
+        }
+    }
+
     /**
      * Get the thumbprint of the key of a credential.
      *
@@ -266,6 +271,8 @@ public class SignStatusListToken extends AbstractProfileAction {
     @Override
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
 
+        assert ctx != null && signatureSigningParameters != null;
+
         final SignatureSigningParameters parameters = withRequiredKey(profileRequestContext,
                 signatureSigningParameters, ctx.getKeyThumbprint());
         if (parameters == null) {
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/FormStatusListTokenTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/FormStatusListTokenTest.java
new file mode 100644
index 0000000..d1e9236
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/FormStatusListTokenTest.java
@@ -0,0 +1,334 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * 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 org.geant.shibboleth.plugin.openidvci.statuslist.profile.impl;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.time.YearMonth;
+import java.time.ZoneOffset;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.geant.shibboleth.plugin.openidvci.security.impl.DidSupport;
+import org.geant.shibboleth.plugin.openidvci.statuslist.MonthlyBucketStrategy;
+import org.geant.shibboleth.plugin.openidvci.statuslist.StatusListBucket;
+import org.geant.shibboleth.plugin.openidvci.statuslist.StatusListCodec;
+import org.geant.shibboleth.plugin.openidvci.statuslist.StatusListIssuerTag;
+import org.geant.shibboleth.plugin.openidvci.statuslist.StatusListParameters;
+import org.geant.shibboleth.plugin.openidvci.statuslist.context.StatusListTokenContext;
+import org.geant.shibboleth.plugin.openidvci.statuslist.profile.StatusListEventIds;
+import org.geant.shibboleth.plugin.openidvci.statuslist.storage.StatusListStore;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.security.credential.BasicCredential;
+import org.opensaml.storage.impl.MemoryStorageService;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.webflow.execution.RequestContext;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.nimbusds.jose.jwk.Curve;
+import com.nimbusds.jose.jwk.ECKey;
+import com.nimbusds.jose.jwk.gen.ECKeyGenerator;
+import com.nimbusds.jwt.JWTClaimsSet;
+
+import jakarta.servlet.http.HttpServletRequest;
+import net.shibboleth.idp.profile.IdPEventIds;
+import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
+import net.shibboleth.idp.profile.testing.ActionTestingSupport;
+import net.shibboleth.idp.profile.testing.RequestContextBuilder;
+import net.shibboleth.oidc.security.jose.impl.BasicSignatureSigningConfiguration;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.primitive.NonnullSupplier;
+
+/** Tests for {@link FormStatusListToken}. */
+public class FormStatusListTokenTest {
+
+    private static final String ENDPOINT = "https://issuer.example.org/idp/profile/oauth/status-list/list";
+
+    private static final String DEPLOYMENT = "https://issuer.example.org";
+
+    private static final String LOOKED_UP_ISSUER = "did:example:lookup";
+
+    private RequestContext requestCtx;
+
+    private ProfileRequestContext profileRequestCtx;
+
+    private MemoryStorageService storageService;
+
+    private StatusListStore store;
+
+    private MockHttpServletRequest httpRequest;
+
+    private String list;
+
+    private StatusListBucket bucket;
+
+    @BeforeMethod
+    public void setUp() throws Exception {
+        storageService = new MemoryStorageService();
+        storageService.setId("test");
+        storageService.initialize();
+
+        store = new StatusListStore();
+        store.setId("test");
+        store.setStorage(storageService);
+        store.initialize();
+
+        list = YearMonth.now(ZoneOffset.UTC).plusMonths(2).toString();
+        bucket = MonthlyBucketStrategy.parse(list);
+
+        requestCtx = new RequestContextBuilder().buildRequestContext();
+        profileRequestCtx = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
+        profileRequestCtx.setOutboundMessageContext(new MessageContext());
+
+        httpRequest = new MockHttpServletRequest("GET", "/idp/profile/oauth/status-list/list");
+        httpRequest.setScheme("https");
+        httpRequest.setServerName("issuer.example.org");
+        httpRequest.setServerPort(443);
+    }
+
+    @AfterMethod
+    public void tearDown() {
+        store.destroy();
+        storageService.destroy();
+    }
+
+    private FormStatusListToken newAction(final String reference) throws ComponentInitializationException {
+        if (reference != null) {
+            httpRequest.setParameter(StatusListParameters.BUCKET_PARAMETER, reference);
+        }
+        final FormStatusListToken action = new FormStatusListToken();
+        action.setStatusListStore(store);
+        action.setIssuerLookupStrategy(prc -> LOOKED_UP_ISSUER);
+        action.setDeploymentIssuer(DEPLOYMENT);
+        action.setHttpServletRequestSupplier(new NonnullSupplier<>() {
+            public HttpServletRequest get() {
+                return httpRequest;
+            }
+        });
+        return action;
+    }
+
+    private JWTClaimsSet claims() {
+        final StatusListTokenContext ctx =
+                profileRequestCtx.ensureOutboundMessageContext().getSubcontext(StatusListTokenContext.class);
+        Assert.assertNotNull(ctx);
+        return ctx.getClaims();
+    }
+
+    @Test
+    public void testClaims() throws Exception {
+        final FormStatusListToken action = newAction(list);
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        final JWTClaimsSet claims = claims();
+        Assert.assertEquals(claims.getIssuer(), LOOKED_UP_ISSUER);
+        Assert.assertEquals(claims.getSubject(), ENDPOINT + "?id=" + list);
+        Assert.assertNotNull(claims.getIssueTime());
+        Assert.assertEquals(claims.getExpirationTime(), Date.from(bucket.end()));
+        Assert.assertEquals(claims.getLongClaim("ttl"), Long.valueOf(3600));
+        final Map<String, Object> statusList = claims.getJSONObjectClaim("status_list");
+        Assert.assertEquals(((Number) statusList.get("bits")).intValue(), StatusListParameters.STATUS_BITS);
+        Assert.assertEquals(statusList.get("lst"), StatusListCodec.encode(StatusListCodec.empty()));
+        Assert.assertNull(profileRequestCtx.ensureOutboundMessageContext()
+                .getSubcontext(StatusListTokenContext.class).getKeyThumbprint());
+    }
+
+    @Test
+    public void testTtl() throws Exception {
+        final FormStatusListToken action = newAction(list);
+        action.setTtl(Duration.ofMinutes(10));
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        Assert.assertEquals(claims().getLongClaim("ttl"), Long.valueOf(600));
+    }
+
+    @Test
+    public void testStoredList() throws Exception {
+        store.revoke(bucket, 5);
+        final FormStatusListToken action = newAction(list);
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        final Object lst = claims().getJSONObjectClaim("status_list").get("lst");
+        Assert.assertEquals(lst, store.read(bucket));
+        Assert.assertNotEquals(lst, StatusListCodec.encode(StatusListCodec.empty()));
+    }
+
+    @Test
+    public void testDidWebTag() throws Exception {
+        final String reference = StatusListIssuerTag.reference(list, StatusListIssuerTag.DID_WEB);
+        final FormStatusListToken action = newAction(reference);
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        Assert.assertEquals(claims().getIssuer(), DidSupport.toDidWeb(DEPLOYMENT));
+        Assert.assertEquals(claims().getSubject(), ENDPOINT + "?id=" + reference);
+    }
+
+    @Test
+    public void testUrlTagConfiguredUrl() throws Exception {
+        final FormStatusListToken action = newAction(StatusListIssuerTag.reference(list, StatusListIssuerTag.URL));
+        action.setConfiguredIssuer("https://credentials.example.org");
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        Assert.assertEquals(claims().getIssuer(), "https://credentials.example.org");
+    }
+
+    @Test
+    public void testUrlTagKeyword() throws Exception {
+        final FormStatusListToken action = newAction(StatusListIssuerTag.reference(list, StatusListIssuerTag.URL));
+        action.setConfiguredIssuer(DidSupport.URL_KEYWORD);
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        Assert.assertEquals(claims().getIssuer(), DEPLOYMENT);
+    }
+
+    @Test
+    public void testDidJwkTag() throws Exception {
+        final ECKey other = new ECKeyGenerator(Curve.P_256).generate();
+        final ECKey named = new ECKeyGenerator(Curve.P_256).generate();
+        final BasicSignatureSigningConfiguration config = new BasicSignatureSigningConfiguration();
+        config.setSigningCredentials(
+                List.of(new BasicCredential(other.toPublicKey()), new BasicCredential(named.toPublicKey())));
+        final String thumbprint = named.computeThumbprint().toString();
+
+        final FormStatusListToken action =
+                newAction(StatusListIssuerTag.reference(list, StatusListIssuerTag.didJwk(thumbprint)));
+        action.setConfigurationLookupStrategy(prc -> List.of(config));
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        Assert.assertEquals(claims().getIssuer(), DidSupport.toDidJwk(named.toPublicKey()));
+        Assert.assertEquals(profileRequestCtx.ensureOutboundMessageContext()
+                .getSubcontext(StatusListTokenContext.class).getKeyThumbprint(), thumbprint);
+    }
+
+    @Test
+    public void testDidJwkTagUnknownKey() throws Exception {
+        final BasicSignatureSigningConfiguration config = new BasicSignatureSigningConfiguration();
+        config.setSigningCredentials(
+                List.of(new BasicCredential(new ECKeyGenerator(Curve.P_256).generate().toPublicKey())));
+        final String thumbprint = new ECKeyGenerator(Curve.P_256).generate().computeThumbprint().toString();
+
+        final FormStatusListToken action =
+                newAction(StatusListIssuerTag.reference(list, StatusListIssuerTag.didJwk(thumbprint)));
+        action.setConfigurationLookupStrategy(prc -> List.of(config));
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), StatusListEventIds.NO_STATUS_LIST);
+    }
+
+    @Test
+    public void testUnknownTag() throws Exception {
+        final FormStatusListToken action = newAction(StatusListIssuerTag.reference(list, "other"));
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), StatusListEventIds.NO_STATUS_LIST);
+    }
+
+    @Test
+    public void testNoParameter() throws Exception {
+        final FormStatusListToken action = newAction(null);
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), StatusListEventIds.NO_STATUS_LIST);
+    }
+
+    @Test
+    public void testNotAMonth() throws Exception {
+        final FormStatusListToken action = newAction("not-a-month");
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), StatusListEventIds.NO_STATUS_LIST);
+    }
+
+    @Test
+    public void testEndedMonth() throws Exception {
+        final FormStatusListToken action = newAction("2020-01");
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), StatusListEventIds.STATUS_LIST_RETIRED);
+    }
+
+    @Test
+    public void testEndedMonthUnknownTag() throws Exception {
+        final FormStatusListToken action = newAction(StatusListIssuerTag.reference("2020-01", "other"));
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), StatusListEventIds.STATUS_LIST_RETIRED);
+    }
+
+    @Test
+    public void testNoIssuer() throws Exception {
+        final FormStatusListToken action = newAction(list);
+        action.setIssuerLookupStrategy(prc -> null);
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
+    }
+
+    @Test
+    public void testStoreFails() throws Exception {
+        final StatusListStore failing = new StatusListStore() {
+            @Override
+            public String read(final StatusListBucket toRead) throws IOException {
+                throw new IOException("Testing");
+            }
+        };
+        failing.setId("failing");
+        failing.setStorage(storageService);
+        failing.initialize();
+        final FormStatusListToken action = newAction(list);
+        action.setStatusListStore(failing);
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.IO_ERROR);
+        failing.destroy();
+    }
+
+    @Test
+    public void testNoOutboundMessageContext() throws Exception {
+        profileRequestCtx.setOutboundMessageContext(null);
+        final FormStatusListToken action = newAction(list);
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_PROFILE_CTX);
+    }
+
+    @Test(expectedExceptions = ComponentInitializationException.class)
+    public void testNoStore() throws Exception {
+        new FormStatusListToken().initialize();
+    }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/SignStatusListTokenTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/SignStatusListTokenTest.java
new file mode 100644
index 0000000..8ccd466
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/SignStatusListTokenTest.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * 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 org.geant.shibboleth.plugin.openidvci.statuslist.profile.impl;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.geant.shibboleth.plugin.openidvci.security.impl.DidSupport;
+import org.geant.shibboleth.plugin.openidvci.statuslist.context.StatusListTokenContext;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.springframework.webflow.execution.RequestContext;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.nimbusds.jose.JWSAlgorithm;
+import com.nimbusds.jose.crypto.ECDSAVerifier;
+import com.nimbusds.jose.jwk.Curve;
+import com.nimbusds.jose.jwk.ECKey;
+import com.nimbusds.jose.jwk.gen.ECKeyGenerator;
+import com.nimbusds.jwt.JWTClaimsSet;
+import com.nimbusds.jwt.SignedJWT;
+
+import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
+import net.shibboleth.idp.profile.testing.ActionTestingSupport;
+import net.shibboleth.idp.profile.testing.RequestContextBuilder;
+import net.shibboleth.oidc.jwa.support.SignatureConstants;
+import net.shibboleth.oidc.security.credential.BasicJWKCredential;
+import net.shibboleth.oidc.security.jose.SignatureSigningParameters;
+import net.shibboleth.oidc.security.jose.context.SecurityParametersContext;
+import net.shibboleth.oidc.security.jose.impl.BasicSignatureSigningConfiguration;
+import net.shibboleth.shared.component.ComponentInitializationException;
+
+/** Tests for {@link SignStatusListToken}. */
+public class SignStatusListTokenTest {
+
+    private static final String SUBJECT = "https://issuer.example.org/idp/profile/oauth/status-list/list?id=2027-02";
+
+    private RequestContext requestCtx;
+
+    private ProfileRequestContext profileRequestCtx;
+
+    private StatusListTokenContext tokenCtx;
+
+    private ECKey resolvedKey;
+
+    private ECKey otherKey;
+
+    private BasicSignatureSigningConfiguration config;
+
+    @BeforeMethod
+    public void setUp() throws Exception {
+        requestCtx = new RequestContextBuilder().buildRequestContext();
+        profileRequestCtx = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
+        profileRequestCtx.setOutboundMessageContext(new MessageContext());
+
+        resolvedKey = new ECKeyGenerator(Curve.P_256).keyID("resolved").generate();
+        otherKey = new ECKeyGenerator(Curve.P_384).keyID("other").generate();
+        config = new BasicSignatureSigningConfiguration();
+        config.setSigningCredentials(List.of(credentialOf(resolvedKey), credentialOf(otherKey)));
+
+        final SignatureSigningParameters parameters = new SignatureSigningParameters();
+        parameters.setSigningCredential(credentialOf(resolvedKey));
+        parameters.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_ES_256);
+        profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(SecurityParametersContext.class)
+                .setSignatureSigningParameters(parameters);
+
+        tokenCtx = profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(StatusListTokenContext.class);
+        tokenCtx.setClaims(claimsOf(DidSupport.toDidJwk(resolvedKey.toECPublicKey())));
+    }
+
+    private static BasicJWKCredential credentialOf(final ECKey key) throws Exception {
+        final BasicJWKCredential credential = new BasicJWKCredential();
+        credential.setPublicKey(key.toECPublicKey());
+        credential.setPrivateKey(key.toECPrivateKey());
+        credential.setKid(key.getKeyID());
+        return credential;
+    }
+
+    private static JWTClaimsSet claimsOf(final String issuer) {
+        return new JWTClaimsSet.Builder().issuer(issuer).subject(SUBJECT).issueTime(new Date())
+                .expirationTime(new Date(System.currentTimeMillis() + 3600000L)).claim("ttl", 3600L)
+                .claim("status_list", Map.of("bits", 1, "lst", "eNrbuRgAAhcBXQ")).build();
+    }
+
+    private SignStatusListToken newAction() throws ComponentInitializationException {
+        final SignStatusListToken action = new SignStatusListToken();
+        action.setConfigurationLookupStrategy(prc -> List.of(config));
+        return action;
+    }
+
+    @Test
+    public void testJwt() throws Exception {
+        final SignStatusListToken action = newAction();
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        final SignedJWT jwt = SignedJWT.parse(tokenCtx.getSignedToken());
+        Assert.assertEquals(jwt.getHeader().getType().toString(), "statuslist+jwt");
+        Assert.assertEquals(jwt.getHeader().getAlgorithm(), JWSAlgorithm.ES256);
+        Assert.assertEquals(jwt.getHeader().getKeyID(), tokenCtx.getClaims().getIssuer() + "#0");
+        Assert.assertTrue(jwt.verify(new ECDSAVerifier(resolvedKey.toECPublicKey())));
+        Assert.assertEquals(jwt.getJWTClaimsSet().getSubject(), SUBJECT);
+        Assert.assertNull(tokenCtx.getSignedCwt());
+    }
+
+    @Test
+    public void testNamedKeyIsTheResolvedOne() throws Exception {
+        tokenCtx.setKeyThumbprint(resolvedKey.computeThumbprint().toString());
+        final SignStatusListToken action = newAction();
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        Assert.assertTrue(SignedJWT.parse(tokenCtx.getSignedToken())
+                .verify(new ECDSAVerifier(resolvedKey.toECPublicKey())));
+    }
+
+    @Test
+    public void testNamedKeyOfAnotherCurve() throws Exception {
+        tokenCtx.setClaims(claimsOf(DidSupport.toDidJwk(otherKey.toECPublicKey())));
+        tokenCtx.setKeyThumbprint(otherKey.computeThumbprint().toString());
+        final SignStatusListToken action = newAction();
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        final SignedJWT jwt = SignedJWT.parse(tokenCtx.getSignedToken());
+        Assert.assertEquals(jwt.getHeader().getAlgorithm(), JWSAlgorithm.ES384);
+        Assert.assertTrue(jwt.verify(new ECDSAVerifier(otherKey.toECPublicKey())));
+    }
+
+    @Test
+    public void testNamedKeyNotConfigured() throws Exception {
+        tokenCtx.setKeyThumbprint(new ECKeyGenerator(Curve.P_256).generate().computeThumbprint().toString());
+        final SignStatusListToken action = newAction();
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_SEC_CFG);
+        Assert.assertNull(tokenCtx.getSignedToken());
+    }
+
+    @Test
+    public void testCwt() throws Exception {
+        final SignStatusListToken action = newAction();
+        action.setCwtCondition(prc -> true);
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        Assert.assertNotNull(tokenCtx.getSignedCwt());
+        Assert.assertTrue(tokenCtx.getSignedCwt().length > 0);
+        Assert.assertNull(tokenCtx.getSignedToken());
+    }
+
+    @Test
+    public void testCwtWithNamedKeyOfAnotherCurve() throws Exception {
+        tokenCtx.setKeyThumbprint(otherKey.computeThumbprint().toString());
+        final SignStatusListToken action = newAction();
+        action.setCwtCondition(prc -> true);
+        action.initialize();
+
+        ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+        Assert.assertNotNull(tokenCtx.getSignedCwt());
+    }
+
+    @Test
+    public void testNoClaims() throws Exception {
+        tokenCtx.setClaims(null);
+        final SignStatusListToken action = newAction();
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_PROFILE_CTX);
+    }
+
+    @Test
+    public void testNoSecurityParametersContext() throws Exception {
+        profileRequestCtx.ensureOutboundMessageContext().removeSubcontext(SecurityParametersContext.class);
+        final SignStatusListToken action = newAction();
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_SEC_CFG);
+    }
+
+    @Test
+    public void testNoSigningCredential() throws Exception {
+        profileRequestCtx.ensureOutboundMessageContext().ensureSubcontext(SecurityParametersContext.class)
+                .getSignatureSigningParameters().setSigningCredential(null);
+        final SignStatusListToken action = newAction();
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_SEC_CFG);
+    }
+
+}

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


More information about the commits mailing list