-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
jwt RS256 signature verification failing #170
Comments
|
the difference is in that your public RSA key 4096 bits whereas lua-resty-openidc by default expects 2048 bits; @bodewig we should fix/enhance that indeed I seem to remember that the original PR had some commented out text to generate that part dynamically but the author couldn't get that to work |
Fully agree we should get that fixed, but I'd first need to read up on the format to be of any help.You probably recall https://github.com/zmartzone/lua-resty-openidc/pull/82/files#diff-1c5839bc51fa1aa064c7206dce60fb3eR582 |
OK, I've dug into it a bit and have tried to understand what the string The first few bytes say "this is a sequence of length 290 bytes". For the longer key the "correct" value says "546 bytes" and this is exactly the length of the decoded data following this prefix. This bitstring then contains a new ASN.1 message that starts with "This is a sequence of length 13 bytes" followed by the "an OID of length 9" and the 9 byte OID assigned to ":rsaEncryption" and an ASN.1 "NULL" with length 0. Next comes a the header that says "a bitstring of length 271 bytes" and in the "correct version" it is "527 bytes". I'm not sure what the ASN.1 NULL actually does but think we can reconstruct the rest well enough to create the "header" dynamically. I'll give it a try. |
Great! I intend to add a test case which means creating a 4k key and fiddling with openssl to turn it into a JWK which may take some time. Also I think I've got one real test environment where the server returns n/e keys instead of an x5c key claim - I want to test against that before merging to master. |
BTW the NULL is the Parameters part of the "AlgorithmIdentifier" defined for PKCS 1 and there was a 0 byte in front of the encoded key that signals "the bitstring uses all bits of the following bytes" in BER's "primitive" encoding. |
Things worked just fine with my test environment so I merged the fix. |
Hi guys, I am having the same issue again. I am using kong plugin oidc with ory/hydr as my Oauth sever. |
I am getting error in JWT RS256 signature verification because the PEM generated from n,e keys is invalid.
trying to validate the token with the generated PEM (obtained from the logs) at https://jwt.io/ fails too.
Correct
n,e
are obtained from the jwk endpoint, but the function that converts it to the PEM public key has some bug. I have done the same conversion (RSA(n,e) ->PEM) using this tool and the obtained public key passes jwt.io validation.There is only one char that is different between the key created by this library and the valid one,
while your keys always start with:
in my case mine should start with
I have seen that this part of the key is hardcoded here:
--PEM KEY FROM PUBLIC KEYS, PASSING 64 BIT ENCODED RSA HEADER STRING WHICH IS SAME FOR ALL KEYS local pem = der2pem(encoded_key,"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A","PUBLIC KEY")
For some reason that string that "is same for all keys" doesn't apply to me?
I'm using Ory hydra as the oauth2 server, that is generating the keys.
Thanks!
The text was updated successfully, but these errors were encountered: