Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EC token signature verification, add verify against JWKS URL, and more #60

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ulidtko
Copy link

@ulidtko ulidtko commented Mar 18, 2022

Greetings @ticarpi !

I'm unshelving a bunch of fixes to the tool, please consider merging.

Most important first:

  • EC JWT verification fixed.
    I'm sure you know, there are Elliptic Curve based JWT algos, EC256 EC384 EC521. They were not getting sig-verified correctly. The bug may be hard to see in the diff, but it's pretty simple, I'll just echo the commit message:
    image
    With this fix, I got complete parity with https://jwt.io & other implementations.

I also added a straightforward "verify token against JWKS URL" mode, for UX speed reasons.

Some more bits and pieces too, I hope the rest will be obvious.

I tested the changes with real keys and tokens, mostly EC ones.

Feel free to question anything unclear in review; I'm hoping to get the PR landed, completely in the spirit of FOSS to make the tool ever a bit sharper 🚀

Best regards

@ulidtko
Copy link
Author

ulidtko commented Apr 12, 2023

Yearly ping @ticarpi. EC token sigs are still broken, care to review?

@ulidtko
Copy link
Author

ulidtko commented Apr 12, 2023

Retested with RSA tokens, too.

@ulidtko
Copy link
Author

ulidtko commented Dec 6, 2023

Bump @ticarpi, any review comment?

@halfluke
Copy link

halfluke commented Jul 8, 2024

I find so annoying that an effort for the community has been ignored for so long. Just wanted to say that and express my sympathy

The correct variable name is `sig`, but under try: it's referred to as
`signature`. Normally that'd crash with NameError exception -- but here
we have a catch-all except block misinterpreting that as wrong signature.
Keys can be/are of wildly different types, including different elliptic curves.

IETF RFC7518 (JWA) section 3.4 table mandates this 3-row map:

 | JWT.alg | Hash, curve
 | ES256   | SHA256, P-256
 | ES384   | SHA384, P-384
 | ES512   | SHA512, P-521

The assert (unless disabled with -O) will clearly fail when JWT mismatches the pubkey,
(as far as by curve choice).
For those JWK's which lack the kid attribute, the logic assigns one.

When parsing pubkey bundle (JWKS, a set of JWK), the previous logic
enables a clash, consider this JWK sequence:

 * {"kid": "2", "kty":"EC", "use":"sig", ... }
 * {"kty":"RS", "use":"sig", ... } -- this saves with kid=1
 * {"kty":"RS", "use":"enc", ... } -- this *overwrites* kid=2
@ulidtko
Copy link
Author

ulidtko commented Jul 8, 2024

Thanks @halfluke for the kind words 🙏

What's most annoying to me, is that other PRs #101 #108 do get reviewed & merged, and releases come out every so often. But radio silence here, no feedback whatsoever. Ping @ticarpi @rbrown256 @JJK96 anything I should change to land this fix?..

FWIW, rebased once again to resolve the merge confict.

@rbrown256
Copy link
Contributor

This looks like a worthwhile merge to me.

Thanks for your contribution. @ticarpi any chance of merging this in?

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.

3 participants