Closed Bug 1563236 Opened 5 years ago Closed 2 years ago

WebCrypto unwrapKey does not work with AES-KW wrapped keys

Categories

(Core :: DOM: Web Crypto, defect, P1)

67 Branch
defect

Tracking

()

RESOLVED FIXED
108 Branch
Tracking Status
firefox108 --- fixed

People

(Reporter: paul, Assigned: me)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0

Steps to reproduce:

The unwrapKey method does not support AES-KW wrapped key:

window.crypto.subtle.unwrapKey(
'raw',
wrappedKey, // AES-KW wrapped key
wrappingKey, // AES-KW wrapping key
'AES-KW',
{ name: 'AES-KW', length: 256 },
true,
['wrapKey', 'unwrapKey']
)

Actual results:

An error is returned: DOMException: "Operation is not supported".

Expected results:

The AES-KW key should be unwrapped, as it is a valid key algorithm according to the documentation:
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/unwrapKey

I assume this is because "WEBCRYPTO_ALG_AES_KW" is missing here: https://dxr.mozilla.org/mozilla-central/source/dom/crypto/WebCryptoTask.cpp#3410-3414

Hi @Paul, can you please provide a TC, steps of how can we reproduce the issue.
Additionally, I will set a component, if this isn't the right one please fell free to change it.
Thanks.

Flags: needinfo?(paul)
Component: Untriaged → DOM: Web Crypto
Product: Firefox → Core
Priority: -- → P3

Hi all,
It seems all kind of unwraps are broken. Here is a example working great in Chrome but failing on Firefox (73.0 (64-bit) from Ubuntu Ubuntu 19.10)

'use strict';
(async function() {

const scr=window.crypto.subtle;
const ec_params={
	name:"ECDSA",namedCurve:"P-521",
}
let aes_params={
	name:"AES-CTR",length:256
};

let kp= await scr.generateKey (ec_params,true,["sign","verify"]);
let wk=await scr.generateKey(aes_params, true,["wrapKey","unwrapKey"]);
let salt=new Uint8Array(16);
window.crypto.getRandomValues(salt);

console.log("wk:",await scr.exportKey("jwk",wk));
console.log("salt:",salt);

const wrap_params={
	name:"AES-CTR",length:64 , counter:salt,
};

let data=await scr.wrapKey("jwk",kp.privateKey,wk,wrap_params);
console.log("data:",data);

let pk=await scr.unwrapKey("jwk",data,wk,wrap_params,ec_params,true,["sign"]);
console.log("pk:",pk);

})();

That code snippet works fine for me in Firefox 92 - are you still seeing issues?

Flags: needinfo?(st.iv.sdr)

Seems to be fixed in my current Firefox 92 on 64bit Ubuntu 21.04. Great works! Thanks

Flags: needinfo?(st.iv.sdr)

Hi,

Sorry guys but unwrapKey on Windows x64, Firefox 92.0.1 64-bit, still fails while at least Chrome and Opera on Windows succeed.

Parameters passed:
format: pkcs8

wrapping key:
algorithm:
length: 256
name: "AES-CBC"
extractable: false
type: "secret"
usages: "unwrapKey"

Key options:
{name: "ECDH",
namedCurve: "P-384"}

isExtractable: false

usages: ['deriveBits']

Exception:

code: 9
columnNumber: 0
data: null
filename: ""
lineNumber: 0
message: "Operation is not supported"
name: "NotSupportedError"
result: 2152923145
stack: ""

(In reply to H. S. from comment #5)

Sorry guys but unwrapKey on Windows x64, Firefox 92.0.1 64-bit, still fails while at least Chrome and Opera on Windows succeed.

Not a guy 😉
Can you give me a minimized code snippet that fails on Firefox? (or some other way to reproduce the issue you're seeing?)

Flags: needinfo?(hrs5880)
Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → INCOMPLETE

(In reply to Dana Keeler (she/her) (use needinfo) (:keeler for reviews) from comment #6)

(In reply to H. S. from comment #5)

Sorry guys but unwrapKey on Windows x64, Firefox 92.0.1 64-bit, still fails while at least Chrome and Opera on Windows succeed.

Not a guy 😉
Can you give me a minimized code snippet that fails on Firefox? (or some other way to reproduce the issue you're seeing?)

This seems to still be failing for me on Firefox, while working on Chrome and Edge.

async function test() {
  const subtle = window.crypto.subtle;

  const key1 = await subtle.generateKey(
    {
      name: "AES-KW",
      length: 256,
    },
    true,
    ["wrapKey", "unwrapKey"]
  );

  const key2 = await subtle.generateKey(
    {
      name: "AES-KW",
      length: 256,
    },
    true,
    ["wrapKey", "unwrapKey"]
  );

  const wrapped = await subtle.wrapKey("raw", key1, key2, "AES-KW");
  const unwrapped = await subtle.unwrapKey(
    "raw",
    wrapped,
    key2,
    "AES-KW",
    "AES-KW",
    true,
    ["wrapKey", "unwrapKey"]
  );
}

(In reply to Dana Keeler (she/her) (use needinfo) (:keeler for reviews) from comment #6)

(In reply to H. S. from comment #5)

Sorry guys but unwrapKey on Windows x64, Firefox 92.0.1 64-bit, still fails while at least Chrome and Opera on Windows succeed.

Not a guy 😉
Can you give me a minimized code snippet that fails on Firefox? (or some other way to reproduce the issue you're seeing?)

It looks like WEBCRYPTO_ALG_AES_KW is not currently allowed in the creation of the unwrap task in WebCryptoTask.cpp:

if (keyAlgName.EqualsASCII(WEBCRYPTO_ALG_AES_CBC) ||
      keyAlgName.EqualsASCII(WEBCRYPTO_ALG_AES_CTR) ||
      keyAlgName.EqualsASCII(WEBCRYPTO_ALG_AES_GCM) ||
      keyAlgName.EqualsASCII(WEBCRYPTO_ALG_HKDF) ||
      keyAlgName.EqualsASCII(WEBCRYPTO_ALG_HMAC)) 

Adding it seems to fix the issue, but I'm not sure whether there was a reason for excluding it in the first place. I wouldn't believe so.

The web-platform tests seem to show that AES-KW should be allowed but are currently failing:
https://wpt.fyi/results/WebCryptoAPI/wrapKey_unwrapKey/wrapKey_unwrapKey.https.any.html?label=experimental&label=master&aligned

I just added WEBCRYPTO_ALG_AES_KW to the list above and all the tests pass.

Unless I'm missing something, can we reopen this bug? I can submit a patch I guess.

Yeah, I think that was just an oversight. A patch would be greatly appreciated!

Assignee: nobody → me
Severity: normal → S3
Status: RESOLVED → REOPENED
Ever confirmed: true
Flags: needinfo?(paul)
Flags: needinfo?(hrs5880)
Priority: P3 → P1
Resolution: INCOMPLETE → ---
Pushed by dkeeler@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/a6e30cde05ed
Add AES-KW purposed keys to list of allowable keys to unwrap. r=keeler
Status: REOPENED → RESOLVED
Closed: 2 years ago2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 108 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: