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

JWT and JWK x5u and x5c verification #408

Open
behrangsa opened this issue Nov 7, 2018 · 5 comments
Open

JWT and JWK x5u and x5c verification #408

behrangsa opened this issue Nov 7, 2018 · 5 comments
Labels
enhancement help-wanted If you're looking to help the project, start with these!

Comments

@behrangsa
Copy link

When receiving a signed JWT token with a header such as:

{
    "x5t" : "thumbprint",
    "x5u ": "https://certificates.example.com/123456789.cer"
}

Where is the appropriate place for verifying the identity of https://certificates.example.com/123456789.cer, before resolving it and letting JJWT use it to verify the signature of the token? Should this also be done in the SigningKeyResolver? And if the verification fails, does it matter what exception is thrown or is it required to throw an io.jsonwebtoken.security.SecurityException?

@lhazlewood lhazlewood added enhancement help-wanted If you're looking to help the project, start with these! labels Mar 10, 2019
@ChristopherSchultz
Copy link

Honestly, I think it makes more sense to support something like signWith(Certificate) for token-generation and setSigningKey(Certificate) for token-validation for starters. Then a future improvement could be useSigningKeyFromToken(true) or something to allow the library to go fetch the certificate and verify using it.

@ChristopherSchultz
Copy link

signWith(Certificate) for token-generation

🤦‍♂️

Of course, you can't sign with a Certificate, since the Certificate class doesn't expose the private key.

But maybe something like signWith(Certificate, PrivateKey) where the signWith method checks to see that (a) the private key belongs with the Certificate and (b) the certificate is valid, hasn't expired, etc.

@netmackan
Copy link

The way I have been considering is to use the SigningKeyResolver as you suggest.
Something like this:

JwtParser jwtParser = Jwts.parserBuilder().setSigningKeyResolver(new SigningKeyResolverAdapter() {

    @Override
    public Key resolveSigningKey(JwsHeader header, Claims claims) {
            String certUrl = header.get("x5u");
            // Fetch and parse certificate
            ...
            // Verify certificate chain, and if not valid and trusted and not revoked etc throw exception (which?)
            ...
            // If all ok:
            return cert.getPublicKey();
    }

}).build();

Jws<Claims> jws = jwtParser.parseClaimsJws(signedRequest);

But question remains what exception to use and if there is any downside of doing it like this or any alternative. I probably just go with JwtException for now.

@lhazlewood
Copy link
Contributor

@netmackan your last example is exactly how you should handle x5u-to-publicKey lookup - nicely done. FWIW, SigningKeyResolver has been deprecated in favor of new Locator<Header> and JwtParserBuilder.keyLocator concepts that will be shortly released in 0.12.0. I'm closing this issue due to those options.

Thank you for your example!

@lhazlewood lhazlewood changed the title Extension point for verifying x5u certificates JWT x5u verification Aug 11, 2023
@lhazlewood lhazlewood reopened this Aug 11, 2023
@lhazlewood
Copy link
Contributor

This and #741 are likely duplicates, but maybe not (this issue is for JWT verification key resolution, #741 is for JWK certificate verification)

@lhazlewood lhazlewood changed the title JWT x5u verification JWT and JWK x5u verification Sep 16, 2023
@lhazlewood lhazlewood changed the title JWT and JWK x5u verification JWT and JWK x5u and x5c verification Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help-wanted If you're looking to help the project, start with these!
Projects
None yet
Development

No branches or pull requests

4 participants