garyf / json_web_token_ex

An Elixir implementation of the JSON Web Token (JWT) Standard, RFC 7519
MIT License
143 stars 50 forks source link

Sign payload with ECDSA P-256 SHA-256 #18

Closed slashmili closed 7 years ago

slashmili commented 7 years ago

Hey,

I was checking the code and noticed that in this library secp256k1 is used as opposed to secp256r1.

Is there any reason for that?

Looks like P-256 is secp256r1.

The JWA spec defines ES256 as ECDSA using P-256 and SHA-256 where P-256 is another name for secp256r1

-- Note that [FIPS186-3] refers to secp192r1 as P-192, secp224r1 as -- P-224, secp256r1 as P-256, secp384r1 as P-384, and secp521r1 as -- P-521.

The reason that I'm asking is I have problem verifying a JWT with key pair that generated with secp256r1.

{public_key, private_key} = :crypto.generate_key(:ecdh, :secp256r1)
jwt = JsonWebToken.sign(%{foo: "bar"}, %{alg: "ES256", key: private_key})
iex(98)> JsonWebToken.verify(jwt, %{alg: "ES256", key: public_key})
{:error, "invalid"}
slashmili commented 7 years ago

Just checked erlang-jose and it's also using :secp256r1

garyf commented 7 years ago

addressed by 3d0cd3c

slashmili commented 7 years ago

Thanks ❤️