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

bestJWSAlg should take a list of supported algorithms #118

Closed
kaol opened this issue Oct 19, 2023 · 4 comments
Closed

bestJWSAlg should take a list of supported algorithms #118

kaol opened this issue Oct 19, 2023 · 4 comments

Comments

@kaol
Copy link

kaol commented Oct 19, 2023

I think bestJWSAlg should take a list of algorithms supported by the recipient as well. The key may potentially support it but there's no guarantee that the recipient will recognize it. In particular, OpenID Connect's discovery document defines fields

  • request_object_signing_alg_values_supported
  • id_token_signing_alg_values_supported
  • userinfo_signing_alg_values_supported
  • token_endpoint_auth_signing_alg_values_supported
  • introspection_endpoint_auth_signing_alg_values_supported

and in my case I was using openid-connect library which uses bestJWSAlg which returns PS512 but the provider I'm using only lists RS256 and HS256 in the discovery and using PS512 got me only errors.

@frasertweedale
Copy link
Owner

Yes, that's a good idea. I will introduce a new function for this purpose, call it negotiateBestJWSAlg or something like that, and ping you when it is ready for review. I hope to find time in the next few weeks to do some work on jose.

frasertweedale added a commit that referenced this issue Dec 14, 2023
Add `Crypto.JOSE.JWK.negotiateJWSAlg` which chooses the
cryptographically strongest JWS algorithm for a given key,
optionally restricted to a given set of algorithms.

#118
@frasertweedale
Copy link
Owner

@kaol please take a look at the feature/118-negotiate-alg branch, which adds a negotiation function:

negotiateJWSAlg
  :: (MonadError e m, AsError e)
  => JWK
  -> Maybe (NonEmpty JWA.JWS.Alg)
  -> m JWA.JWS.Alg

Please let me know if it meets your needs, and any other feedback.

frasertweedale added a commit that referenced this issue Dec 14, 2023
Add `Crypto.JOSE.JWK.negotiateJWSAlg` which chooses the
cryptographically strongest JWS algorithm for a given key,
optionally restricted to a given set of algorithms.

#118
@kaol
Copy link
Author

kaol commented Dec 14, 2023

Yes, that looks suitable for the purpose. Thanks. For reference, here's a version of openid-connect that uses it: https://github.com/KSF-Media/openid-connect/tree/feature/negotiate-JWS-alg

I could still suggest one change about it: Remove the Maybe from the publicly exposed negotiateJWSAlg and add a third internal function that's used by both bestJWSAlg and negotiateJWSAlg. IMHO that'd be a cleaner design, unless you're thinking of deprecating best and would offer only negotiate.

@frasertweedale
Copy link
Owner

@kaol, thanks for the feedback. I will implement the API change you suggested. I have some other changes in progress but I'll aim for a new release during the Christmas break.

frasertweedale added a commit that referenced this issue Dec 15, 2023
Add `Crypto.JOSE.JWK.negotiateJWSAlg` which chooses the
cryptographically strongest JWS algorithm for a given key,
restricted to a given set of algorithms.

#118
frasertweedale added a commit that referenced this issue Dec 15, 2023
Add `Crypto.JOSE.JWK.negotiateJWSAlg` which chooses the
cryptographically strongest JWS algorithm for a given key,
restricted to a given set of algorithms.

#118
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

2 participants