From c036258809476380fc134d69cfc3446aec674900 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sun, 3 Apr 2022 12:11:02 +0200 Subject: [PATCH] crypto: cleanup webcrypto jwk code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/42562 Reviewed-By: Tobias Nießen Reviewed-By: Benjamin Gruenbaum Reviewed-By: Zeyu Yang Reviewed-By: Akhil Marsonya Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott --- lib/internal/crypto/dsa.js | 51 -------------------------------- lib/internal/crypto/webcrypto.js | 5 ---- 2 files changed, 56 deletions(-) diff --git a/lib/internal/crypto/dsa.js b/lib/internal/crypto/dsa.js index 12e327c6ed1765..faaf7d6b889c07 100644 --- a/lib/internal/crypto/dsa.js +++ b/lib/internal/crypto/dsa.js @@ -7,11 +7,9 @@ const { const { DSAKeyExportJob, - KeyObjectHandle, SignJob, kCryptoJobAsync, kSigEncDER, - kKeyTypePrivate, kSignJobModeSign, kSignJobModeVerify, } = internalBinding('crypto'); @@ -29,8 +27,6 @@ const { const { InternalCryptoKey, - PrivateKeyObject, - PublicKeyObject, createPrivateKey, createPublicKey, isKeyObject, @@ -45,7 +41,6 @@ const { hasAnyNotIn, jobPromise, normalizeHashName, - validateKeyOps, kKeyObject, kHandle, } = require('internal/crypto/util'); @@ -178,52 +173,6 @@ async function dsaImportKey( }); break; } - case 'jwk': { - if (keyData == null || typeof keyData !== 'object') - throw lazyDOMException('Invalid JWK keyData', 'DataError'); - - verifyAcceptableDsaKeyUse( - algorithm.name, - keyData.x !== undefined ? 'private' : 'public', - usagesSet); - - if (keyData.kty !== 'DSA') - throw lazyDOMException('Invalid key type', 'DataError'); - - if (usagesSet.size > 0 && - keyData.use !== undefined && - keyData.use !== 'sig') { - throw lazyDOMException('Invalid use type', 'DataError'); - } - - validateKeyOps(keyData.key_ops, usagesSet); - - if (keyData.ext !== undefined && - keyData.ext === false && - extractable === true) { - throw lazyDOMException('JWK is not extractable', 'DataError'); - } - - if (keyData.alg !== undefined) { - if (typeof keyData.alg !== 'string') - throw lazyDOMException('Invalid alg', 'DataError'); - const hash = - normalizeHashName(keyData.alg, normalizeHashName.kContextWebCrypto); - if (hash !== algorithm.hash.name) - throw lazyDOMException('Hash mismatch', 'DataError'); - } - - const handle = new KeyObjectHandle(); - const type = handle.initJwk(keyData); - if (type === undefined) - throw lazyDOMException('Invalid JWK keyData', 'DataError'); - - keyObject = type === kKeyTypePrivate ? - new PrivateKeyObject(handle) : - new PublicKeyObject(handle); - - break; - } default: throw lazyDOMException( `Unable to import DSA key with format ${format}`, diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index a7916e6ac341f8..e9380ed53bf4d2 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -403,11 +403,6 @@ async function exportKeyJWK(key) { key.algorithm.hash.name, normalizeHashName.kContextJwkHmac); return jwk; - case 'NODE-DSA': - jwk.alg = normalizeHashName( - key.algorithm.hash.name, - normalizeHashName.kContextJwkDsa); - return jwk; case 'NODE-ED25519': // Fall through case 'NODE-ED448':