diff options
author | Filip Skokan <panva.ip@gmail.com> | 2022-03-11 15:56:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-11 20:26:16 +0530 |
commit | f9b4d262b307649966b6433c72a9ee2b57bde8f7 (patch) | |
tree | 31766d95c4f093b67992d1d798cb8aa315f9a340 | |
parent | 189e2f617ea0f4304bb44bb6243e0378ca55b8b5 (diff) |
fix(ext/crypto): handle JWK import with "use" (#13912)
-rw-r--r-- | cli/tests/unit/webcrypto_test.ts | 23 | ||||
-rw-r--r-- | ext/crypto/00_crypto.js | 14 |
2 files changed, 30 insertions, 7 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index bdb99e8b7..94f011bae 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -1727,3 +1727,26 @@ Deno.test(async function ecPrivateKeyMaterialExportSpki() { const spki = await crypto.subtle.exportKey("spki", keys.publicKey); 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); +}); diff --git a/ext/crypto/00_crypto.js b/ext/crypto/00_crypto.js index b4b317b3c..5387544e8 100644 --- a/ext/crypto/00_crypto.js +++ b/ext/crypto/00_crypto.js @@ -2696,27 +2696,27 @@ "RSASSA-PKCS1-v1_5": { public: ["verify"], private: ["sign"], - jwtUse: "sig", + jwkUse: "sig", }, "RSA-PSS": { public: ["verify"], private: ["sign"], - jwtUse: "sig", + jwkUse: "sig", }, "RSA-OAEP": { public: ["encrypt", "wrapKey"], private: ["decrypt", "unwrapKey"], - jwtUse: "enc", + jwkUse: "enc", }, "ECDSA": { public: ["verify"], private: ["sign"], - jwtUse: "sig", + jwkUse: "sig", }, "ECDH": { public: [], private: ["deriveKey", "deriveBits"], - jwtUse: "enc", + jwkUse: "enc", }, }; @@ -2863,11 +2863,11 @@ if ( keyUsages.length > 0 && jwk.use !== undefined && StringPrototypeToLowerCase(jwk.use) !== - SUPPORTED_KEY_USAGES[normalizedAlgorithm.name].jwtUse + SUPPORTED_KEY_USAGES[normalizedAlgorithm.name].jwkUse ) { throw new DOMException( `'use' property of JsonWebKey must be '${ - SUPPORTED_KEY_USAGES[normalizedAlgorithm.name].jwtUse + SUPPORTED_KEY_USAGES[normalizedAlgorithm.name].jwkUse }'`, "DataError", ); |