1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix(ext/crypto): check extractable in exportKey (#14222)

This commit is contained in:
EduM22 2022-04-07 14:58:56 +02:00 committed by GitHub
parent b8d66a683a
commit 181e378032
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 4 deletions

View file

@ -1750,3 +1750,23 @@ Deno.test(async function importJwkWithUse() {
assert(key instanceof CryptoKey);
});
// https://github.com/denoland/deno/issues/14215
Deno.test(async function exportKeyNotExtractable() {
const key = await crypto.subtle.generateKey(
{
name: "HMAC",
hash: "SHA-512",
},
false,
["sign", "verify"],
);
assert(key);
assertEquals(key.extractable, false);
await assertRejects(async () => {
// Should fail
await crypto.subtle.exportKey("raw", key);
}, DOMException);
});

View file

@ -984,28 +984,43 @@
const algorithmName = key[_algorithm].name;
let result;
switch (algorithmName) {
case "HMAC": {
return exportKeyHMAC(format, key, innerKey);
result = exportKeyHMAC(format, key, innerKey);
break;
}
case "RSASSA-PKCS1-v1_5":
case "RSA-PSS":
case "RSA-OAEP": {
return exportKeyRSA(format, key, innerKey);
result = exportKeyRSA(format, key, innerKey);
break;
}
case "ECDH":
case "ECDSA": {
return exportKeyEC(format, key, innerKey);
result = exportKeyEC(format, key, innerKey);
break;
}
case "AES-CTR":
case "AES-CBC":
case "AES-GCM":
case "AES-KW": {
return exportKeyAES(format, key, innerKey);
result = exportKeyAES(format, key, innerKey);
break;
}
default:
throw new DOMException("Not implemented", "NotSupportedError");
}
if (key.extractable === false) {
throw new DOMException(
"Key is not extractable",
"InvalidAccessError",
);
}
return result;
}
/**