traits icon indicating copy to clipboard operation
traits copied to clipboard

elliptic-curve: `JwkEcKey` is too strict in what it accepts

Open Erik1000 opened this issue 2 years ago • 0 comments

As per RFC7517 section 4 (fourth paragraph)

Additional members can be present in the JWK; if not understood by implementations encountering them, they MUST be ignored.

But currently, if you try to parse this key for example (using the p256 crate; key created by step-cli):

{
  "use": "enc",
  "kty": "EC",
  "kid": "UYa89vgc4u_lpcbbmDQfYJQRAUD4AED8H8FUNjk5KyQ",
  "crv": "P-256",
  "alg": "ECDH-ES",
  "x": "hFc6OfbgRsYFOWyhGbWH0sS5DZBjJLGABJvPttVZfA4",
  "y": "tnXB8ks0-AZJKOgbMWJrE5Jm3nTFy0UiqQugmx9jku4"
}

It will fail, because it does not recognize the use parameter (it doesn't recognize some other parameters either, but that is the first parameter it sees). In fact, you have to reduce it to the following parameters (so only the ones from Field are present)

{
  "kty": "EC",
  "crv": "P-256",
  "x": "hFc6OfbgRsYFOWyhGbWH0sS5DZBjJLGABJvPttVZfA4",
  "y": "tnXB8ks0-AZJKOgbMWJrE5Jm3nTFy0UiqQugmx9jku4"
}

There's a registry for all key parameters at IANA but note that this list 1) may grow with new entries and 2) implementations are allowed to define custom parameters not in the registry.

My proposed solution would be to ignore unknown parameters just like the spec dictates it.

Erik1000 avatar May 26 '22 13:05 Erik1000