-
Notifications
You must be signed in to change notification settings - Fork 238
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
JWKError when using a JWKS with multiple algorithms #138
Comments
This is currently a design limitation. The library currently does not feature key algorithm detection and as such, algorithm must currently be passed in as a separate argument. Thus, the code assumes all the keys passed in have the same algorithm. This limitation could be removed, but I'm note entirely sure mixing different key types - what you're doing - is a good idea. If you can (if you have both ends under control), I'd recommend using Until this limitation is removed, the workaround is to separate the keys based on supported algorithm and try different algorithms in turn. |
That seems like a good solution to me. Is there any reason for the library to iterate over the JWKS and ignore the |
The library only has a naive implementation that iterates over all the keys provided in order. It currently does nothing to distinguish different keys. The Appendix D of JWS spec has an overview how the logic to choose the key and even the order of the keys to verify with may look in a bit more complex application where there are multiple keys. Since this can be very application specific I'm not sure if there can be a good way for the library to provide this logic. I do think there should at least be a clear error if the keys provided use different algorithms. |
Thanks for the information, I see the problem now, it would be too cumbersome to implement a general solution that takes into account all the possible ways. To remove the JWKS limitation, the |
This implements point 2 of Appendix D, filtering out keys that don't match
|
Hi, again, I'm not sure if this is expected behavior or a bug, but currently I'm in a situation where a JWT needs to be decoded and it can be encoded using RS256 or HS256, so my JWKS has 3 JWK, 2 for RS256 and 1 for HS256.
In this case, if I use a JWT encoded with HS256 and the first JWK in my JWKS has
kty: 'RSA'
aJWKError("Incorrect key type. Expected: 'oct', Recieved: RSA",)
is raised, if the conditions are reversed, JWT encoded with RS256 and the first JWK havingkty: 'oct'
,JWKError("Incorrect key type. Expected: 'RSA', Recieved: oct",)
is raised. I think the troubling line is https://github.com/mpdavis/python-jose/blob/master/jose/jws.py#L216 as it attempts to construct a JWK using the wrong algorithm.Thanks for developing this library and if I can be of any use to solve this (if it's a bug) let me know.
The text was updated successfully, but these errors were encountered: