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

JWT::JWK::EC#public_key returns unexpected type #529

Open
bellebaum opened this issue Oct 21, 2022 · 2 comments
Open

JWT::JWK::EC#public_key returns unexpected type #529

bellebaum opened this issue Oct 21, 2022 · 2 comments
Milestone

Comments

@bellebaum
Copy link
Contributor

Hey,

I was trying to use a JWK inside a block in JWT.decode, since I cannot use the jwks option because (for backwards compatibility reasons) I need a special handling of the situation where no kid is present in the token header (I.e. if the issuer only has one key, use that one).

When trying to get the public key from a JWT::JWK using .public_key, its usability depends on the kty.

For RSA and in particular OpenSSL::PKey::RSA, you get another OpenSSL::PKey::RSA object, for which .private? returns false.
For EC and in particular OpenSSL::PKey::EC, you get a OpenSSL::PKey::EC::Point.

This seems unexpected and causes the validation to fail for EC, since a Point has no method dsa_verify_asn1 used in the EC Algo.

For me, using .keypair instead solved the issue but always exporting the private key as well seems like a bad habit.
Should JWT::JWK::EC#public_key return OpenSSL::PKey::EC even though OpenSSL::PKey::EC#public_key does not?

@bellebaum bellebaum changed the title JWT::JWK::EC.public_key returns unexpected type JWT::JWK::EC#public_key returns unexpected type Oct 21, 2022
@anakinj
Copy link
Member

anakinj commented Feb 2, 2023

We should dig deeper into this one and fix the EC public key representation. Could also be a limitation of ruby/openssl?

@anakinj anakinj added this to the Version 3.0.0 milestone Feb 2, 2023
@julik
Copy link
Contributor

julik commented Jan 27, 2024

Probably the issue is that OpenSSL::PKey::EC and similar are actually keypairs - the Ruby OpenSSL docs do not really provide a nice noun for this.

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

3 participants