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

The JWK oct import is not decoding the k value #632

Open
anakinj opened this issue Oct 6, 2024 · 0 comments
Open

The JWK oct import is not decoding the k value #632

anakinj opened this issue Oct 6, 2024 · 0 comments

Comments

@anakinj
Copy link
Member

anakinj commented Oct 6, 2024

Noticed while working on the unencoded payloads and trying to re-create the scenarios in the RFC that the OCT JWK import is not working correctly.

It seems that the key import and export is missing the Base64 encoding parts.

This should work:

key = ::JWT::JWK.import({kty:"oct", k:"AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow"})
token = ::JWT::EncodedToken.new("eyJhbGciOiJIUzI1NiJ9.JC4wMg.5mvfOroL-g7HyqJoozehmsaqmvTYGEq5jTI1gVvoEoQ")
token.verify_signature!(algorithm: "HS256", key: key.verify_key) # => raises JWT::VerificationError

When explicitly decoded it works:

key = ::JWT::JWK.import({kty:"oct", k:Base64.urlsafe_decode64("AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow")})
token = ::JWT::EncodedToken.new("eyJhbGciOiJIUzI1NiJ9.JC4wMg.5mvfOroL-g7HyqJoozehmsaqmvTYGEq5jTI1gVvoEoQ")
token.verify_signature!(algorithm: "HS256", key: key.verify_key)

We need to fix this, but as it's breaking change in imports and exports it would be suitable for the 3.0 version.

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

No branches or pull requests

1 participant