You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to import an ECDSA public key from a JWKS using jwt (2.6.0) and it's consistently failing. I have tried with different JWKS values and I'm getting the same results each time. Below is a summary of what I'm doing, in a Pry console.
First I retrieve the relevant JWK value from the JWKS:
Following the work-round suggested in this issue, I replace line 139 of the JWT::JWK::EC.create_ec_key method with OpenSSL::BN.new([0x04, x_octets, y_octets].pack(''), 2).
I try to import the public key again and at first it looks like it might work, but the key is deemed invalid:
public_key=JWT::JWK::EC.import(jwk).public_key# => #<OpenSSL::PKey::EC::Point:0x00000001013fba18 @group=#<OpenSSL::PKey::EC::Group:0x00000001013fb9f0>>public_key.check_key# NoMethodError: undefined method `check_key' for #<OpenSSL::PKey::EC::Point:0x00000001013fba18 @group=#<OpenSSL::PKey::EC::Group:0x00000001013fb9f0>># Use `.keypair` which implements `.check_key`keypair=JWT::JWK::EC.import(jwk).keypairkeypair.check_key# OpenSSL::PKey::ECError: EVP_PKEY_public_check: point at infinity
I used .keypair instead of .public_key here, following the suggestion in this issue.
Am I doing something wrong here? Any help would be very much appreciated, please. 🙏
The text was updated successfully, but these errors were encountered:
It looks like the X value in the key is missing something, the encoded value is one char shorter than the y value. Is this JWK published publicly somewhere?
Also switching the x value to a valid encoded number makes the error different:
JWT::JWK::EC.import(
kty: 'EC',
crv: 'P-521',
x: 'AafgvMTsTt3-Z7g663VUz0CwW7GN8x83YV-dFwylobgjUKaGRuCgCvpOj5OP1mDPm7CHwGhI-yKUtMDYNfu7O_Uz',
y: 'AX1cjkGMiltikPrkX49qwuJDdcETaTsj-kyFP8jsF9W5XAB3Z4tBiQtc72DQnJYeKyAV_T6qZTtFKFr-Tp4iu-j7'
) => EC_POINT_bn2point: point is not on curve
Hi @anakinj, thanks for your reply and sorry I'm only replying now. This was indeed a padding issue with the JWK. After trying a few things, we figured out that all we needed was to apply zero-padding to the non-encoded value, which we achieved this way:
I'm trying to import an ECDSA public key from a JWKS using
jwt (2.6.0)
and it's consistently failing. I have tried with different JWKS values and I'm getting the same results each time. Below is a summary of what I'm doing, in a Pry console.First I retrieve the relevant JWK value from the JWKS:
Then I try to import the public key from the JWK and I get this error:
Following the work-round suggested in this issue, I replace line 139 of the
JWT::JWK::EC.create_ec_key
method withOpenSSL::BN.new([0x04, x_octets, y_octets].pack(''), 2)
.I try to import the public key again and at first it looks like it might work, but the key is deemed invalid:
I used
.keypair
instead of.public_key
here, following the suggestion in this issue.Am I doing something wrong here? Any help would be very much appreciated, please. 🙏
The text was updated successfully, but these errors were encountered: