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

Private key should not be required to verify JWT #291

Closed
anuragkapur opened this issue Oct 21, 2018 · 4 comments
Closed

Private key should not be required to verify JWT #291

anuragkapur opened this issue Oct 21, 2018 · 4 comments

Comments

@anuragkapur
Copy link

As per the following code sample in the documentation in the readme https://github.com/auth0/java-jwt/tree/b4c1eca4c68d68a343428c8bef4ce90774a4e29d#verify-a-token both private and public key is needed to verify a JWT's signature. This seems incorrect as when using RSA256 algorithm, there should be no need for the private key to verify the JWT.

String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
RSAPublicKey publicKey = //Get the key instance
RSAPrivateKey privateKey = //Get the key instance
try {
    Algorithm algorithm = Algorithm.RSA256(publicKey, privateKey);
    JWTVerifier verifier = JWT.require(algorithm)
        .withIssuer("auth0")
        .build(); //Reusable verifier instance
    DecodedJWT jwt = verifier.verify(token);
} catch (JWTVerificationException exception){
    //Invalid signature/claims
}

This alternate java library: https://github.com/jwtk/jjwt#reading-a-jws shows how the JWT is verified without secret key. Additionally, the Auth0 JWT node.js lib https://github.com/auth0/node-jsonwebtoken#jwtverifytoken-secretorpublickey-options-callback also doesn't need private key when using RSA256.

@lbalmaceda
Copy link
Contributor

We added a clarification for that right in the section above which explains the usage of the Algorithm class (used both for signing and verifying tokens). https://github.com/auth0/java-jwt/tree/b4c1eca4c68d68a343428c8bef4ce90774a4e29d#pick-the-algorithm

When using RSA or ECDSA algorithms and you just need to sign JWTs you can avoid specifying a Public Key by passing a null value. The same can be done with the Private Key when you just need to verify JWTs.

What is your suggestion?

@anuragkapur
Copy link
Author

My sincere apologies. I did not read the section of the documentation that already clarifies this.

@hoto
Copy link

hoto commented Oct 5, 2020

Sorry for resurrecting, should I create another issue?

We added a clarification for that right in the section above which explains the usage of the Algorithm class

That clarification is quite far away from the code sample 😬

Screenshot 2020-10-05 at 13 17 06

I can do a PR but I wonder if there is any scenario where the RSAPrivateKey would NOT be null when verifying the token?
I wonder if the readme could be updated to pass RSAPrivateKey as null or put another short explanation in the comment?

@petrdvorak
Copy link
Contributor

@hoto Best... visualization... ever... 😄 I opened #555 to address this, the docs also stroke me visually and no, there is no situation when private key is required during the JWT verification.

BaurzhanSakhariev added a commit to BaurzhanSakhariev/java-jwt that referenced this issue Feb 12, 2024
There was an auth0#554 referring to unclarity of private keys usage. 

Also there was a general hint referred in some comments 
auth0#291 (comment)

auth0#324 (comment)

auth0#253 (comment)

and community post
https://community.auth0.com/t/rsa256-jwks-jwt-validation-using-auth0s-java-jwt-and-jwks-rsa-java/13149

All this was removed in auth0@d0ebc3f

This PR gets back those as it's still might be unclear.
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

4 participants