denoland/celldPublic

self-hosted, distributed Durable Objects

Normalize imported RSA CryptoKey metadata

DL

I had sent an email w/ this bug & a patch for it, but I'm creating this issue as well just in case the email got marked as spam. Sorry for the duplication.

Anyway, I was working on auth today and ran into an issue with the [propelauth worker sdk](https://docs.propelauth.com/reference/backend-apis/cloudflare-workers).

My understanding of the issue is as follows: After importing the key, celld constructs a `CryptoKey` using the algorithm object unchanged, resulting in the shape below. ``` { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" } ```

JOSE then tries to evaluate something like [`key.algorithm.hash.name`](http://key.algorithm.hash.name/), which ends up undefined. The first attempt was to just change the returned object slightly to ```

hash: { name: _hashName(algorithm.hash) } ```

However, JOSE also checks key.algorithm.modulusLength so I've added that field as well.

`publicExponent` was not needed for this fix, but according to my bot ([verified as well here](https://www.w3.org/TR/webcrypto/#dfn-RsaKeyAlgorithm)) Web Crypto defines an RSA `CryptoKey.algorithm` as a complete `RsaHashedKeyAlgorithm`:

``` { name, modulusLength, publicExponent, hash } ```

Here is a pretty minimal repro: https://gist.github.com/dleviminzi/d2d22292bd2bb5706a02b1b8e48b0476

I've attached a patch with a fix below.

[0001-Normalize-imported-RSA-CryptoKey-metadata.patch](https://github.com/user-attachments/files/31795237/0001-Normalize-imported-RSA-CryptoKey-metadata.patch)

  1. lourdsubscribed2 months ago on GitHub

  2. RY

    Thanks for the report and the patch. It landed today with you as co-author, extended to cover the same defect on the generate path and on EC keys: a CryptoKey now reports its *KeyAlgorithm dictionary built from the parsed key, with the Web Crypto name, `hash` as `{ name }`, `modulusLength`, `publicExponent` as bytes, and `namedCurve`. The fix ships in the next release, v0.4.1.

  3. ryclosed2 months ago on GitHub

  4. bartlomiejureferenced fd7b96b993f52 months ago on GitHub

  5. bartlomiejureferenced b61356b29deb2 months ago on GitHub

  6. bartlomiejureferenced 7ac68e0bd2a72 months ago on GitHub

  7. bartlomiejureferenced 10cb1303dac72 months ago on GitHub