From bc373d561794e62ef20c16cd15c608c6b541870e Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Fri, 1 Apr 2022 11:58:36 +0200 Subject: [PATCH] crypto: cleanup webcrypto jwk code --- 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 63dd03bd00e0f0..ba6c2001aded44 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -368,11 +368,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':