mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(ext/crypto): handle JWK import with "use" (#13912)
This commit is contained in:
parent
189e2f617e
commit
f9b4d262b3
2 changed files with 30 additions and 7 deletions
|
@ -1727,3 +1727,26 @@ Deno.test(async function ecPrivateKeyMaterialExportSpki() {
|
||||||
const spki = await crypto.subtle.exportKey("spki", keys.publicKey);
|
const spki = await crypto.subtle.exportKey("spki", keys.publicKey);
|
||||||
assert(spki instanceof ArrayBuffer);
|
assert(spki instanceof ArrayBuffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://github.com/denoland/deno/issues/13911
|
||||||
|
Deno.test(async function importJwkWithUse() {
|
||||||
|
const jwk = {
|
||||||
|
"kty": "EC",
|
||||||
|
"use": "sig",
|
||||||
|
"crv": "P-256",
|
||||||
|
"x": "FWZ9rSkLt6Dx9E3pxLybhdM6xgR5obGsj5_pqmnz5J4",
|
||||||
|
"y": "_n8G69C-A2Xl4xUW2lF0i8ZGZnk_KPYrhv4GbTGu5G4",
|
||||||
|
};
|
||||||
|
|
||||||
|
const algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
||||||
|
|
||||||
|
const key = await crypto.subtle.importKey(
|
||||||
|
"jwk",
|
||||||
|
jwk,
|
||||||
|
algorithm,
|
||||||
|
true,
|
||||||
|
["verify"],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(key instanceof CryptoKey);
|
||||||
|
});
|
||||||
|
|
|
@ -2696,27 +2696,27 @@
|
||||||
"RSASSA-PKCS1-v1_5": {
|
"RSASSA-PKCS1-v1_5": {
|
||||||
public: ["verify"],
|
public: ["verify"],
|
||||||
private: ["sign"],
|
private: ["sign"],
|
||||||
jwtUse: "sig",
|
jwkUse: "sig",
|
||||||
},
|
},
|
||||||
"RSA-PSS": {
|
"RSA-PSS": {
|
||||||
public: ["verify"],
|
public: ["verify"],
|
||||||
private: ["sign"],
|
private: ["sign"],
|
||||||
jwtUse: "sig",
|
jwkUse: "sig",
|
||||||
},
|
},
|
||||||
"RSA-OAEP": {
|
"RSA-OAEP": {
|
||||||
public: ["encrypt", "wrapKey"],
|
public: ["encrypt", "wrapKey"],
|
||||||
private: ["decrypt", "unwrapKey"],
|
private: ["decrypt", "unwrapKey"],
|
||||||
jwtUse: "enc",
|
jwkUse: "enc",
|
||||||
},
|
},
|
||||||
"ECDSA": {
|
"ECDSA": {
|
||||||
public: ["verify"],
|
public: ["verify"],
|
||||||
private: ["sign"],
|
private: ["sign"],
|
||||||
jwtUse: "sig",
|
jwkUse: "sig",
|
||||||
},
|
},
|
||||||
"ECDH": {
|
"ECDH": {
|
||||||
public: [],
|
public: [],
|
||||||
private: ["deriveKey", "deriveBits"],
|
private: ["deriveKey", "deriveBits"],
|
||||||
jwtUse: "enc",
|
jwkUse: "enc",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2863,11 +2863,11 @@
|
||||||
if (
|
if (
|
||||||
keyUsages.length > 0 && jwk.use !== undefined &&
|
keyUsages.length > 0 && jwk.use !== undefined &&
|
||||||
StringPrototypeToLowerCase(jwk.use) !==
|
StringPrototypeToLowerCase(jwk.use) !==
|
||||||
SUPPORTED_KEY_USAGES[normalizedAlgorithm.name].jwtUse
|
SUPPORTED_KEY_USAGES[normalizedAlgorithm.name].jwkUse
|
||||||
) {
|
) {
|
||||||
throw new DOMException(
|
throw new DOMException(
|
||||||
`'use' property of JsonWebKey must be '${
|
`'use' property of JsonWebKey must be '${
|
||||||
SUPPORTED_KEY_USAGES[normalizedAlgorithm.name].jwtUse
|
SUPPORTED_KEY_USAGES[normalizedAlgorithm.name].jwkUse
|
||||||
}'`,
|
}'`,
|
||||||
"DataError",
|
"DataError",
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue