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

Automatic JWK enrichment #544

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

bellebaum
Copy link
Contributor

This PR will allow to derive most standardized common parameters from already specified parameters.
This is a follow-up to a few points which could not be addressed in #520, but were brought up by me in #518.

Overview

Using all of its features, given an X.509 certificate, you can acquire a JWK like this:

::JWT::JWK.new(certificate)

This will extract the public key, construct the JWK, and try to set the following parameters:

  • kid as previously implemented
  • x5c is a representation of the certificate
  • x5t and x5t#S256 are wide-spread certificate thumbprints
  • key_ops and use state allowed key usages and are derived from the X.509 keyUsage extension, if present
  • alg will be set to a sensible default depending on use and kty

Of course, any parameters specified in the above invocation will still take precedence.

There is even support for the x5u parameter, to fetch a remote certificate chain:

x5u_fetcher = ->(uri) {
    # Fetch uri, return as Array of OpenSSL::X509::Certificate
}
::JWT::JWK.new(jwks_hash, nil, enrich_key: true, x5u_handler: x5u_fetcher)

TODO

  • Proper certificate validation
  • Check if code from x5c_key_finder can be reused
  • new README examples
  • Update changelog

@anakinj
Copy link
Member

anakinj commented Jan 29, 2023

I realize this is a WIP but I got very curious so will drop a few comments.

@@ -50,6 +52,83 @@ def <=>(other)
private

attr_reader :parameters

KEY_USAGES_SIG = ['Digital Signature', 'Non Repudiation', 'Content Commitment', 'Key Cert Sign', 'CRL Sign'].freeze
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im wondering about where this certificate specific stuff should live. Now the logic baked into each and every JWK object created.

Most of these methods are just setting some values under certain keys? Could it just be a separate mechanism (method/extension) that would build the params passed into the key or add the params to an existing key?

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

Successfully merging this pull request may close these issues.

2 participants