-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
[jwe] Decryption using an algorithm that uses the "p2c" header with the WithUseNumber option fails #1140
Comments
Thank you! Nice catch. |
@Hannes-Kunnen Thanks for the nice report and analysis! Much appreciated. BTW I didn't use your suggested fix for mainly one reason: Instead of reacting to what the JSON values are, I wanted to be pedantic about what we expect based on our internal settings. That is, I wanted to only convert to json.Number when we are expecting it, not when the input somehow turned out to be json.Number -- which could potentially be by mistake. |
That makes more sense and will fix the issue! |
Describe the bug
Decrypting an encrypted payload with any algorithm that requires the
p2c
(PBES2 count) header using thejwe.Decrypt
function will fail if thejwx.WithUseNumber(true)
decoder option is set.Go version:
go version go1.22.0 linux/amd64
To Reproduce / Expected behavior
See Go Playground
Expected behavior: I expected this code to print the
success
message.Actual behavior: I get the following error:
jwe.Decrypt: failed to decrypt any of the recipients (last error = jwe.Decrypt: tried 1 keys, but failed to match any of the keys with recipient (last error = unexpected type for 'p2c': json.Number))
Additional context
I think I found the issue and a possible solution.
The issue seems the be located in these lines:
jwx/jwe/jwe.go
Lines 748 to 751 in 611d914
Because the option
jwx.WithUseNumber(true)
is used the type here isjson.Number
instead offloat64
. This code could be updated to support thejson.Number
type like this:I am however not familiar with this code base, so it's possible that I'm missing a better solution.
The text was updated successfully, but these errors were encountered: