Welcome to the WSO2 Identity Server source code! For info on working with the WSO2 Identity Server repository and contributing code, click the link below.
Describe the issue:
Following improvement[1], the JWKS endpoint now returns the x5c value. Since the x5c value is returned in the JWKS response, libraries processing the JWTs are capable of computing the x5t value for each of the keys returned in the JWKS response to identify the corresponding key by checking whether the value matches with the x5t in the JWT token.
The x5t value that is currently generated by the Identity server is not correct because of an additional hexify step[2] that is performed, this hexify step is not correct and was fixed for the x5t#s256 value in the JWKS response through issue[3]. However, it is not fixed for the x5t generation in the JWT token generation flows(JWT access token and id token).
Because the x5t value generated by the Identity server is incorrect and not as per the specification[4], when these libraries try to validate the JWT tokens they will not be able to find the corresponding key from the JWKS endpoint[5].
How to reproduce:
Set up an oauth2 service provider to issue JWT access tokens(id token can also be used).
Validate the JWT token using the jose4j library[6]
The following error would be observed:
org.jose4j.jwt.consumer.InvalidJwtException: JWT processing failed. Additional details: [[17] Unable to process JOSE object (cause: org.jose4j.lang.UnresolvableKeyException: Unable to find a suitable verification key for JWS w/ header {"x5t":"YjM4MjUxOTU5NjEyM2JjMWU0ZDkxZDBiMWM5ZGRhNjc0NTZiNGY5MQ","kid":"M2FmMWI2Y2ZmNDdjYTQ4MDY1ZTM2NmRmMjZkYmU1MGQxZWFkN2FiNmRlZWY5NDY0MDY4NjI5MjhkZjgxYmY2NQ_RS256","alg":"RS256"} from JWKs [org.jose4j.jwk.RsaJsonWebKey{kty=RSA, kid=M2FmMWI2Y2ZmNDdjYTQ4MDY1ZTM2NmRmMjZkYmU1MGQxZWFkN2FiNmRlZWY5NDY0MDY4NjI5MjhkZjgxYmY2NQ_RS256, use=sig, alg=RS256, n=jDA6imwZ5hJc-5PnzJG22WNf6Q8YFtS36CCzncne1G_JyuW4gwY8ZLjkXhwy7EpWbCxy8_GwooiRGaNxYdWisdPxMw8Zc49rdpel4f7QirTsag76JLjMUcX15I9r5I5DsLY8xADz7DS6N_xm8BClki4fQ4R4aqtAoYA35t02JHvoAfdYug1NwUiZ6F9pDmNybTDKt4cA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FJ2vYrtbA_nzjepsMheaTVvSnObfsGvxsv7_6CKgv1ciVHsowzqDttmOEkeCxwQNgTTg9EH4Z-gWBGvmxa1T-sa9-mriNN985jBjTVwFd68QsJHHXCCLMrv2PVo-e0u8IbDLLbIiEB8OobQYvvRYObFnA71Y8qn-M5SNJry_u7p-PQJoGJlimQihiby1rzD8eBuDCuJX97hbpElCg]
Expected behavior:
It should be possible to validate the JWT token issued by the server with its JWKS response.
Environment information (Please complete the following information; remove any unnecessary fields) :
Describe the issue: Following improvement[1], the JWKS endpoint now returns the x5c value. Since the x5c value is returned in the JWKS response, libraries processing the JWTs are capable of computing the x5t value for each of the keys returned in the JWKS response to identify the corresponding key by checking whether the value matches with the x5t in the JWT token.
The x5t value that is currently generated by the Identity server is not correct because of an additional hexify step[2] that is performed, this hexify step is not correct and was fixed for the x5t#s256 value in the JWKS response through issue[3]. However, it is not fixed for the x5t generation in the JWT token generation flows(JWT access token and id token).
Because the x5t value generated by the Identity server is incorrect and not as per the specification[4], when these libraries try to validate the JWT tokens they will not be able to find the corresponding key from the JWKS endpoint[5].
How to reproduce:
Expected behavior: It should be possible to validate the JWT token issued by the server with its JWKS response.
Environment information (Please complete the following information; remove any unnecessary fields) :
[1]https://github.com/wso2/product-is/issues/6686 [2]https://github.com/wso2-extensions/identity-inbound-auth-oauth/blob/3c36fc4bb338b8373099b80ab87fa0bdc07ea0f7/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/util/OAuth2Util.java#L3279 [3]https://github.com/wso2/product-is/issues/18817 [4]https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.7 [5]https://bitbucket.org/b_c/jose4j/src/a3a21a6c3169e2fea87153a4fad53896f953abf2/src/main/java/org/jose4j/jwk/SimpleJwkFilter.java#lines-108 [6]https://bitbucket.org/b_c/jose4j/wiki/Home