Skip to content

feat: Supporting verification of a signature selected by label - #174

Closed
rosylilly wants to merge 1 commit into
dadrus:mainfrom
rosylilly:feat/signature-selection
Closed

rosylilly wants to merge 1 commit into
dadrus:mainfrom
rosylilly:feat/signature-selection

Conversation

@rosylilly

Copy link
Copy Markdown
Contributor

WithSignatureSelection makes Verify check only the signature named by WithLabel, so other signatures on the message don't affect the result.

Closes #169

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.97%. Comparing base (a572b10) to head (36ff8e1).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #174      +/-   ##
==========================================
+ Coverage   97.94%   97.97%   +0.03%     
==========================================
  Files          23       23              
  Lines        1603     1633      +30     
==========================================
+ Hits         1570     1600      +30     
  Misses         33       33              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@dadrus

dadrus commented Nov 5, 2026

Copy link
Copy Markdown
Owner

@rosylilly: sorry for the silence on this one. Even though it looks promising, I would like to sleep over it for a couple of nights. ... and I would like to resolve the simpler challenges your are looking for first :)

@dadrus

dadrus commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Since the Accept-Signature related PR is now merged, we can focus on this one. Could you please rebase your branch on the current main, respectively merge it into yours and resolve the conflicts. From there on, we can see what can be done. Thank you in advance.

WithSignatureSelection makes Verify check only the signature named by
WithLabel, so other signatures on the message don't affect the result.
@rosylilly
rosylilly force-pushed the feat/signature-selection branch from 15f6cbd to 36ff8e1 Compare November 7, 2026 01:27
@rosylilly

Copy link
Copy Markdown
Contributor Author

@dadrus I've rebased this branch onto the latest main. Could you please review it?

@dadrus

dadrus commented Nov 8, 2026

Copy link
Copy Markdown
Owner

@rosylilly: I finally found some time to merge the current main into your branch locally and review the implementation. Apart from the expected small adjustments related to the changes introduced in #204, the implementation looks good to me.

There is, however, one behavioral change I'd like to understand: On main, getSignatureReferences() parses the complete Signature-Input dictionary and checks that all members are Inner Lists before selecting the signatures to verify. Unselected signatures are then ignored for the actual signature-specific validation. Your implementation filters the dictionary by label before performing the Inner List type check. Consequently, an unrelated member such as broken=1 is now accepted, whereas main returns ErrMalformedData. This is even explicitly covered by the new test ignores an unrelated malformed signature input member. I'm curious whether this change was intentional. Is there a specific interoperability requirement behind it?

Additionally, I'd like to discuss some broader API design considerations. Since our initial discussion in #169, and thanks in part to your PR, I've been thinking about a more general signature selection model, which would replace WithRequiredTag() and WithValidateAllSignatures() entirely. The idea is to introduce a SignatureSelector, allowing signatures to be selected by label, tag, custom signature parameters, or any combination of them. For example:

verifier, err := httpsig.NewVerifier(
    resolver,
    httpsig.WithExpectedSignature(
        httpsig.SignatureSelector{Label: "sig1"},
        httpsig.WithComponents(`"@method"`, `"@target-uri"`),
    ),
)

Additionally, multiple WithExpectedSignature() profiles could be configured, each with its own verification policy and signature negotiation options. For example:

verifier, err := httpsig.NewVerifier(
    resolver,
    httpsig.WithExpectedSignature(
        httpsig.SignatureSelector{
            Label: "sig1",
        },
        httpsig.WithComponents(`"@method"`, `"@target-uri"`),
        httpsig.WithValidityTolerance(5 * time.Second),
        httpsig.WithMaxAge(2 * time.Minute),
        httpsig.WithParameter("audience", "service-a"),
        httpsig.WithRequiredParameters("transaction-id"),
        httpsig.WithForbiddenParameters("legacy-mode"),
        httpsig.WithSignatureNegotiation(
            httpsig.WithKeyID("client-key"),
            httpsig.WithSignatureAlgorithm(httpsig.EcdsaP256Sha256),
            httpsig.WithNonceGetter(nonceGetter),
        ),
    ),
    httpsig.WithExpectedSignature(
        httpsig.SignatureSelector{
            Tag: "proxy-attestation",
            Parameters: httpsig.SignatureParameters{
                "purpose": "request-forwarding",
            },
        },
        httpsig.WithComponents(`"@authority"`, `"content-digest"`),
        httpsig.WithParameter("issuer", "trusted-proxy"),
        httpsig.WithSignatureNegotiation(),
    ),
)

The semantics would be quite simple: Each expected signature profile requires at least one matching signature, and all matching signatures must pass its verification policy. If a signature matches multiple selectors, all applicable policies must be satisfied. Signatures not matching any selector are not verified. The existing functionality to select all signatures would still be possible with an empty selector.

The verification options would work as they do today, including the existing security defaults (required created and expires, 30s maximum age and zero validity tolerance). The main difference is that they would be configured per expected signature instead of globally, with no more overriding of global policies by tag-specific ones. I'd also make WithComponents() mandatory for each profile, even if called without arguments, to make the decision not to require any covered components explicit. Multiple calls would be cumulative.

Signature negotiation would also be configured per expected signature. The selector criteria would automatically become part of the corresponding Accept-Signature requirements. If verification fails, negotiation would be prepared for all profiles having it enabled, leaving it to the application to decide whether to use it. The existing per-call VerifyOption mechanism would remain unchanged, with its requirements applying to all selected signatures.

IMO, this would result in a much cleaner and more flexible API, without introducing yet another mutually exclusive selection mode. It would also allow to get rid of the current distinction between global and tag-specific verification policies.

That brings me to my concern with merging this PR. I'd really like to implement this more general approach, but doing so would mean removing most of the API and selection logic introduced by your PR again.

There is, however, one thing I'd like to clarify before going down that road. One consequence of your implementation is that the label can be selected independently for each Verify() call. I'm wondering whether there are practical use cases where the label actually needs to change between requests, and whether this is the case for your ActivityPub server. Does the label of the first signature vary between requests, or could it be specified when constructing the verifier? And what do you think about the alternative API?

Thanks again, and sorry for the novel ;)

@rosylilly

Copy link
Copy Markdown
Contributor Author

@dadrus Thanks for the detailed write-up.

  1. Yes, it was intentional, but only as a consequence of prioritizing that unselected signatures don't affect the result. Since the verifier is being redesigned now, I don't think we need to keep it.
  2. In my ActivityPub server, the label does vary between requests, since it's taken from the first member of Signature-Input. However, the server creates a verifier per request after resolving the key, so the label can be specified when constructing the verifier. The proposed API covers what I need.

I like the SignatureSelector approach and agree that it results in a cleaner and more flexible API. I think it would be best for you to implement it along those lines.

@dadrus

dadrus commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thank you for sharing your view and sorry for the belated answer. Then, let's do so. I'll add yet another comment to #169 describing the agreed API and will address it asap in a new PR which will replace this one. Therefore, I'm closing this PR for now.

FYI: it might take a week or two until the new PR is there.

@dadrus dadrus closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify one selected signature without using tags

2 participants