w3c/webcrypto

Calling key wrap operation on a JWK encoding

Closed this issue · 4 comments

The current document is either missing a required line or has some other similar problem.

Wrap Key is defined in terms of assuming that the Export Key operation is going to return an ArrayBuffer so that it can pass it on.

Export Key is defined as returning an ECMAScript Object, when exporting using the JWK format.

This means that one cannot run the Wrap Key operation and directly encrypt a JWK object. Do we care about this?

wiml commented

Step 13 of the description in 14.3.11, and the note, seem to specify JSON-encoding in the way you describe. Is this issue still an issue?

(I think the specification is unnecessarily rigid: the sub-steps should be chosen based on "if the export operation produces an ArrayBuffer / Object", not on the text of the format argument, but it does handle the JSON case)

Step 13 of the description in 14.3.11, and the note, seem to specify JSON-encoding in the way you describe. Is this issue still an issue?

@jimsch I guess that question is for you

The fact that AES-KW requires keys to be a multiple of 8 suggests that export JWK -> JSON.stringify might not work great as input for AES-KW.

See discussion in https://stackoverflow.com/a/71372136

twiss commented

I agree that the interaction between JWK and AES-KW is not ideal. The current text allows, but does not require, user agents to include whitespace in the generated JSON to pad the result to a multiple of 8 bytes, but that seems like a bit of a hack to me, so I'm not surprised if that's not implemented. I think it's better to recommend not to use JWK and AES-KW together.

I'll close this issue as the spec does at least seem to specify what to do in this case, even if the result is a bit surprising. If someone wants to propose a change, we can discuss that in a separate issue :)