-
Notifications
You must be signed in to change notification settings - Fork 9
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
OpenSSL error in ASN1_get_object: too long #5
Comments
I am trying to do the following Python, in R:
This is so that I can verify the JWT sent back from the AWS ALB and in turn safely use the information stored within it. |
Do you have an example of the code that is giving this error? |
The public key I got from passing the I would give you the JWT I was using exactly, but it contains sensitive information, apologies. I will try and recreate my setup in a throwaway AWS account in the meantime. Here is the basic structure of the header and payload of the JWT if it helps:
|
Are you sure your jwt string contains a signature? Does this example work for you? library(jose)
pubkeystring <- "-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd
UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs
HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D
o2kQ+X5xK9cipRgEKwIDAQAB
-----END PUBLIC KEY-----"
sig <- "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.EkN-DOsnsuRjRO6BxXemmJDm3HbxrbRzXglbN2S4sOkopdU4IsDxTI8jO19W_A4K8ZPJijNLis4EZsHeY559a4DFOd50_OqgHGuERTqYZyuhtF39yxJPAjUESwxk2J5k_4zM3O-vtd1Ghyo4IbqKKSy6J9mTniYJPenn5-HIirE"
pk <- openssl::read_pubkey(pubkeystring)
# Should return: 1234567890
jwt_decode_sig(sig, pk)
|
That does work yes. I copied the whole JWT string from the I used this gist to write a shiny app behind the ALB which in turn gets me the So you think it is a problem with the third part of the JWT (the signature)? If it helps, I put the public key, and the JWT into the https://jwt.io/ debugger and it said "valid signature". |
It's hard to say from here. You can |
Also what is your version of OpenSSL? |
I did as you suggested and tried to The error occurs here: https://github.com/jeroen/jose/blob/c1385e453a47042144aa6cff4f213a74a0269851/R/jwt.R#L117 and then here: OpenSSL version:
|
What is the length of |
|
Hmm I am confused 🤔The spec says that the signature has to be 64 bytes but openssl seems to expect signatures of 70 or 71 bytes: library(openssl)
test <- charToRaw('hello')
signature_create(test, key = ec_keygen('P-256')) Perhaps there is an issue with the DER encoding of the signature in openssl. But it seems to work just fine for other applications. Possibly related: auth0/java-jwt#187, mpdavis/python-jose#47 |
Very interesting. So are you saying that there could be an issue in the library that is used to create the JWT signature that I am getting back from the AWS ALB because this library (which follows the spec) is unable to verify it? |
No, there is a bug here. Apparently the jwt spec uses an unconventional way to encode the signature to make sure it is always 64 bytes. We need to convert it from what openssl gives us, exactly the same problem as the java and python people have run into above. |
I have pushed a fix based on what the python/java implementations linked above are doing. Could you test this please? remotes::install_github("jeroen/jose") I should add better test cases because roundtripping apparently isn't enough. |
Thanks for the really quick turnaround on this! I tried it, by doing the following:
Where
So yeah, it segfaults. Would you like me to get you an actual JWT to work with? Or have you recreated it with Auth0 and AWS ALB on your side? |
I think something went wrong in updating the openssl package. Can you try again please? Make sure neither jose or openssl is loaded in your R session when you install the update: remotes::install_github("jeroen/openssl")
remotes::install_github("jeroen/jose") |
I am still getting the error with a clean environment. Starting from scratch, into a fresh libs directory, I install remotes, then run the two lines you just posted, then run the code, and it gives:
|
Hmm that's very odd. Which OS are you on? |
Linux Ubuntu 16.04
|
Do you only get this crash for your particular signature, or also when running |
I am guessing a lot of these problems are to do with the fact that AWS ALB returns a base64 encoded token, not a base64 URL encoded token. I have been experiencing issues with javascript libraries as well, this issue pretty much sums it up: auth0/node-jsonwebtoken#514. Possible that the same is happening here? Maybe the Anyway, I will try your code this afternoon with |
Hmm invalid input should never cause a crash. I do have an amazon account, can you explain me where I would create a test jwt token? |
You would need to create the following:
This post does a good job of explaining how it all fits together. Basically people can use the ALB built-in OIDC auth to authenticate apps so the apps behind the load balancer don't have to (or can't authenticate themselves). |
OK that is more complicated than I thought. Is there no simpler application of jwt's in amazon? If you can generate a dummy jwt that would be super helpful. You can revoke it immediately and email it to me because we only need to test the parser. |
I finally found the problem. Should be fixed in the openssl package 1.2.1. |
Great! Thanks so much for continuing the effort. What was the issue in the end? Do you have a patreon or similar that I can contribute to? |
The issue was some uninitiated null pointer in openssl, that could make it crash. I uploaded I don't have patreon, your feedback is a contribution in itself :) You can always donate to WWF if you want to make me happy. |
@jeroen sorry for the late response! From initial testing, it looks like it is now fixed. When I find some time to do some more thorough testing, I will raise a new issue if anything pops up. Thanks again for all of the effort. I made a donation to WWF on your behalf. |
I am getting the error when the
jwt_decode_sig
function calls thesignature_verify
function. Any ideas on where to look at first?If I copy the
jwt_split
code and pass the sig through it, it works fine and I can get all of the information out of the JWT signature. However, when I use thejwt_decode_sig
function directly, it fails with the error, even though the public key is valid, and I assume the sig is valid.The text was updated successfully, but these errors were encountered: