FFFF JWT and JWK `x5u` and `x5c` verification · Issue #408 · jwtk/jjwt · GitHub
[go: up one dir, main page]

Skip to content

JWT and JWK x5u and x5c verification #408

Open

Description

@behrangsa

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?

Activity

  1. ChristopherSchultz commented on May 4, 2021

    @ChristopherSchultz

    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.

  2. ChristopherSchultz commented on May 4, 2021

    @ChristopherSchultz

    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.

  3. netmackan commented on Nov 15, 2021

    @netmackan

    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.

  4. lhazlewood commented on Aug 11, 2023

    @lhazlewood
    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!

  5. changed the title [-]Extension point for verifying `x5u` certificates[/-] [+]JWT `x5u` verification[/+] on Aug 11, 2023
  6. lhazlewood commented on Aug 11, 2023

    @lhazlewood
    Contributor

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

  7. changed the title [-]JWT `x5u` verification[/-] [+]JWT and JWK `x5u` verification[/+] on Sep 16, 2023
  8. changed the title [-]JWT and JWK `x5u` verification[/-] [+]JWT and JWK `x5u` and `x5c` verification[/+] on Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp-wantedIf you're looking to help the project, start with these!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0