Repository navigation
Accept the RFC 8812 secp256k1 curve name for EC JWKs - #787
Merged
Merged
Conversation
RFC 8812 registers the JWK curve name for secp256k1 as "secp256k1". JWT::JWK::EC only recognised the earlier draft name "P-256K", so standard secp256k1 JWKs failed with 'Invalid curve provided' when the key was used or exported. Accept both names on import. Exporting keys generated by ruby-jwt still uses "P-256K". Refs jwt#786
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the EC JWK curve-name compatibility change.
No open issues 🎉
What changed in this PR
Adds support for the RFC 8812 secp256k1 curve name when importing EC JWKs, enabling ES256K verification with standards-compliant keys while preserving compatibility with P-256K.
Changes:
- Accepts both curve names without changing export behavior.
- Adds tests for curve mapping, private-key import and export preservation, and token verification through a public JWKS.
- Documents the compatibility fix in the changelog.
| File | Description |
|---|---|
spec/jwt/jwk/ec_spec.rb |
Tests the registered curve name and ES256K verification. |
lib/jwt/jwk/ec.rb |
Maps both accepted JWK curve names to OpenSSL’s secp256k1. |
CHANGELOG.md |
Records support for importing the registered curve name. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Refs #786.
RFC 8812, section 3.1 registers the JWK
crvvalue for secp256k1 as"secp256k1".JWT::JWK::EC.to_openssl_curveonly recognised"P-256K", an earlier draft name, so standard secp256k1 JWKs raisedJWT::JWKError: Invalid curve providedfromverify_key,private?andexport. One example is the EC key in the Connect2id demo JWKS. ES256K tokens couldn't be verified against such keys.This accepts both names when importing. An imported JWK keeps the curve name it was given, so
"secp256k1"stays"secp256k1"when exported.This PR doesn't change export. Keys generated from an
OpenSSL::PKey::ECare still exported withcrv: "P-256K", because switching to"secp256k1"would change exported JWKs and their thumbprints. That's left in #786 for a minor release.Specs cover the curve mapping, importing a private
"secp256k1"JWK and exporting it unchanged, and verifying an ES256K token against a public JWKS that uses the registered name. Without the fix, all three fail. I also tried the real Connect2id JWKS: its secp256k1 key now resolves, and the whole set exports.Checklist
Before the PR can be merged be sure the following are checked:
Posted by Claude on behalf of @anakinj.