JWK: support the registered secp256k1 curve name for EC keys

Offen
#786 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
65/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
ruby
Bereich
backend, security

Rechercherichtung

Start with lib/jwt/jwk/ec.rb, especially to_openssl_curve and keypair_components, then read the existing EC JWK tests and the changelog conventions. Reproduce the reported import and export behavior for secp256k1; done means registered-name JWKS keys work through verification, verify_key, private?, and set export, with the intended export name and compatibility note covered.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Problem

RFC 8812, section 3.1 registers the JWK crv value for the secp256k1 curve as "secp256k1". JWT::JWK::EC only recognises "P-256K", a name from earlier drafts, in lib/jwt/jwk/ec.rb:

  • to_openssl_curve maps 'P-256K' to 'secp256k1' and raises JWT::JWKError, 'Invalid curve provided' for anything else.
  • keypair_components exports secp256k1 keys with crv: 'P-256K'.

As a result, ES256K tokens can't be verified against a JWKS that uses the registered name, and keys exported by ruby-jwt aren't readable by implementations that only accept "secp256k1".

Reproduction (jwt 3.3.0)
key = OpenSSL::PKey::EC.generate("secp256k1")
jwk = JWT::JWK.new(key)
jwk.export[:crv] # => "P-256K"

token = JWT.encode({ sub: "1" }, key, "ES256K", kid: jwk.kid)
standard = jwk.export.merge(crv: "secp256k1")

JWT.decode(token, nil, true, algorithms: ["ES256K"], jwks: { keys: [standard] })
# => JWT::JWKError: Invalid curve provided

JWT.decode(token, nil, true, algorithms: ["ES256K"], jwks: { keys: [jwk.export] })
# => works with "P-256K"

This also shows up with real JWKS. The Connect2id demo JWKS publishes an EC key with crv: "secp256k1". Importing it works because the key is built lazily, but verify_key, private? and export raise, so JWT::JWK::Set#export fails for the whole set. Looking up other keys by kid isn't affected.

Suggested fix
  1. Accept both "secp256k1" and "P-256K" in to_openssl_curve. This is backwards compatible and could go into a patch release.
  2. Export secp256k1 keys with crv: "secp256k1". This changes exported JWKs and their thumbprints for existing secp256k1 keys, so it might fit better in a minor or major release, with a CHANGELOG note.

Posted by Claude on behalf of @anakinj.

Vorherrschende Sprache
Ruby
Sterne
3.7k
Forks
381
Ø Merge
14 Std. 13 Min.
Gemergte PRs (30 T.)
13

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus jwt/ruby-jwt

Alle Issues in jwt/ruby-jwt

Ähnliche Issues

Weitere Issues zu Ruby

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.