Skip to content

X5CVerifier: support more signature algorithms#238

Merged
ptoffy merged 11 commits into
vapor:mainfrom
m-barthelemy:feature/jws-multi-alg
May 5, 2026
Merged

X5CVerifier: support more signature algorithms#238
ptoffy merged 11 commits into
vapor:mainfrom
m-barthelemy:feature/jws-multi-alg

Conversation

@m-barthelemy

@m-barthelemy m-barthelemy commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

These changes are now available in 5.5.0

Noticed jwt-kit's X5CVerifier only supports ES256 while trying to use Ed25519 certs and signatures.
This PR tries to add support for ES384, ES512 and EdDSA (did not bother with RSA yet). Would that be an okay way of doing so?

@m-barthelemy m-barthelemy requested a review from ptoffy as a code owner December 7, 2025 06:51

@0xTim 0xTim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this is the right approach, just some nits to add

Comment thread Sources/JWTKit/X5C/X5CVerifier.swift Outdated
let eddsaKey = try EdDSA.PublicKey(pem: certificate.publicKey.serializeAsPEM().pemString)
return JWTSigner(algorithm: EdDSASigner(key: eddsaKey), parser: parser)
default:
throw JWTError.invalidX5CChain(reason: "Unsupported algorithm: \(String(describing: alg))")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the correct error - the chain could be valid but we don't support that algorithm so I think we should migrate it to something else

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if the new error I added makes sense!

}
}

@Test("Test signing with EdDSA x5c chain")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add tests for the other new algorithms

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, however I'm not sure how you guys feel about me replacing the previously hardcoded key and certs with runtime-generated ones.

@0xTim 0xTim added the semver-minor Contains new APIs label Dec 19, 2025
@m-barthelemy m-barthelemy requested a review from 0xTim December 19, 2025 21:36

@ptoffy ptoffy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this and sorry for the wait!
This feature is long overdue. It looks like tests are failing because the other hardcoded certs are expired. I'll fix those up in a separate PR. In the meantime could you please switch the tests you added to be parameterised using swift-testing so we don't duplicate the same code over various tests? And could you also please run this through a swift-format round when done? Thanks!

@m-barthelemy

Copy link
Copy Markdown
Contributor Author

Thanks for this and sorry for the wait! This feature is long overdue. It looks like tests are failing because the other hardcoded certs are expired. I'll fix those up in a separate PR. In the meantime could you please switch the tests you added to be parameterised using swift-testing so we don't duplicate the same code over various tests? And could you also please run this through a swift-format round when done? Thanks!

@ptoffy sorry for the very long delay. I have modified the tests that are related to this new feature so that they are parameterized and ran swift-format on the file afterwards.
Anything else looking weird or wrong?

@ptoffy ptoffy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, thanks!

@codecov

codecov Bot commented May 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.20%. Comparing base (94a8b96) to head (320c2ab).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
Sources/JWTKit/JWTError.swift 33.33% 2 Missing ⚠️
Sources/JWTKit/X5C/X5CVerifier.swift 89.47% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #238   +/-   ##
=======================================
  Coverage   82.19%   82.20%           
=======================================
  Files          61       61           
  Lines        1455     1472   +17     
=======================================
+ Hits         1196     1210   +14     
- Misses        259      262    +3     
Files with missing lines Coverage Δ
Sources/JWTKit/JWTError.swift 91.17% <33.33%> (-2.67%) ⬇️
Sources/JWTKit/X5C/X5CVerifier.swift 85.22% <89.47%> (+1.44%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptoffy ptoffy merged commit a93a262 into vapor:main May 5, 2026
31 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-minor Contains new APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants