Skip to content

fix: prefer JWS header kid over jwk.kid in attach decorator verify (fixes #4077)#4085

Merged
PatStLouis merged 4 commits into
openwallet-foundation:mainfrom
OpSecId:fix/4077-verify-kid-from-jws-header
Mar 17, 2026
Merged

fix: prefer JWS header kid over jwk.kid in attach decorator verify (fixes #4077)#4085
PatStLouis merged 4 commits into
openwallet-foundation:mainfrom
OpSecId:fix/4077-verify-kid-from-jws-header

Conversation

@PatStLouis
Copy link
Copy Markdown
Contributor

Summary

Fixes DIDComm connection failure with Credo (and other agents) when they put kid only in the JWS unprotected header and not in jwk.

Problem

During didexchange, ACA-Py's verify() in the attach decorator only read kid from protected["jwk"]["kid"]. Agents like Credo send kid in the JWS header (per spec). That led to ValueError in DIDKey.from_did() or failed verification (issue #4077).

Solution

  • Prefer sig.header.kid when present (canonical place per spec).
  • Fall back to protected["jwk"]["kid"] when the header has no kid.

Testing

  • New test: test_verify_uses_kid_from_header_when_jwk_has_no_kid (JWS with kid only in header).
  • All existing test_attach_decorator.py tests pass.

Made with Cursor

…ixes openwallet-foundation#4077)

When verifying JWS in attach decorator data, use kid from the JWS
unprotected header first (canonical per spec). Fall back to jwk.kid
only when header has no kid. Fixes DIDComm connection failure with
agents (e.g. Credo) that put kid only in header and not in jwk.

Add test for verify when kid is only in JWS header.

Signed-off-by: Patrick St-Louis <patrick.st-louis@opsecid.ca>
Made-with: Cursor
Signed-off-by: Patrick St-Louis <patrick.st-louis@opsecid.ca>
Made-with: Cursor
- test_verify_uses_kid_from_jwk_when_header_has_no_kid: cover jwk.kid fallback
- test_verify_returns_false_when_signer_verkey_does_not_match: cover signer_verkey rejection
- Apply ruff format

Signed-off-by: Patrick St-Louis <patrick.st-louis@opsecid.ca>
Made-with: Cursor
@sonarqubecloud
Copy link
Copy Markdown

@PatStLouis PatStLouis merged commit ad5ea22 into openwallet-foundation:main Mar 17, 2026
12 of 13 checks passed
@PatStLouis PatStLouis deleted the fix/4077-verify-kid-from-jws-header branch March 17, 2026 15:06
PatStLouis added a commit to OpSecId/acapy that referenced this pull request Mar 18, 2026
…ixes openwallet-foundation#4077)

When verifying JWS in attach decorator data, use kid from the JWS
unprotected header first (canonical per spec). Fall back to jwk.kid
only when header has no kid. Fixes DIDComm connection failure with
agents (e.g. Credo) that put kid only in header and not in jwk.

Backport of openwallet-foundation#4085 for 1.2.lts.

- Add test_verify_uses_kid_from_header_when_jwk_has_no_kid
- Add test_verify_uses_kid_from_jwk_when_header_has_no_kid
- Add test_verify_returns_false_when_signer_verkey_does_not_match

Signed-off-by: Patrick St-Louis <patrick.st-louis@opsecid.ca>
Made-with: Cursor
PatStLouis added a commit to OpSecId/acapy that referenced this pull request Mar 18, 2026
…ixes openwallet-foundation#4077)

When verifying JWS in attach decorator data, use kid from the JWS
unprotected header first (canonical per spec). Fall back to jwk.kid
only when header has no kid. Fixes DIDComm connection failure with
agents (e.g. Credo) that put kid only in header and not in jwk.

Backport of openwallet-foundation#4085 for 1.3.lts.

- Add test_verify_uses_kid_from_header_when_jwk_has_no_kid
- Add test_verify_uses_kid_from_jwk_when_header_has_no_kid
- Add test_verify_returns_false_when_signer_verkey_does_not_match

Signed-off-by: Patrick St-Louis <patrick.st-louis@opsecid.ca>
Made-with: Cursor
jamshale pushed a commit that referenced this pull request Mar 18, 2026
…ixes #4077) (#4094)

When verifying JWS in attach decorator data, use kid from the JWS
unprotected header first (canonical per spec). Fall back to jwk.kid
only when header has no kid. Fixes DIDComm connection failure with
agents (e.g. Credo) that put kid only in header and not in jwk.

Backport of #4085 for 1.2.lts.

- Add test_verify_uses_kid_from_header_when_jwk_has_no_kid
- Add test_verify_uses_kid_from_jwk_when_header_has_no_kid
- Add test_verify_returns_false_when_signer_verkey_does_not_match


Made-with: Cursor

Signed-off-by: Patrick St-Louis <patrick.st-louis@opsecid.ca>
jamshale pushed a commit that referenced this pull request Mar 18, 2026
…ixes #4077) (#4095)

When verifying JWS in attach decorator data, use kid from the JWS
unprotected header first (canonical per spec). Fall back to jwk.kid
only when header has no kid. Fixes DIDComm connection failure with
agents (e.g. Credo) that put kid only in header and not in jwk.

Backport of #4085 for 1.3.lts.

- Add test_verify_uses_kid_from_header_when_jwk_has_no_kid
- Add test_verify_uses_kid_from_jwk_when_header_has_no_kid
- Add test_verify_returns_false_when_signer_verkey_does_not_match


Made-with: Cursor

Signed-off-by: Patrick St-Louis <patrick.st-louis@opsecid.ca>
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.

2 participants