JWK: support the registered secp256k1 curve name for EC keys

未关闭
#786 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
ruby
领域
backend, security

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Ruby
星标
3.7k
派生
381
平均合并
14 小时 13 分钟
30 天内合并 PR
13

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

jwt/ruby-jwt 的其他 Issue

查看 jwt/ruby-jwt 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。