Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: cleanup webcrypto jwk code #42562

Merged
merged 1 commit into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions lib/internal/crypto/dsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ const {

const {
DSAKeyExportJob,
KeyObjectHandle,
SignJob,
kCryptoJobAsync,
kSigEncDER,
kKeyTypePrivate,
kSignJobModeSign,
kSignJobModeVerify,
} = internalBinding('crypto');
Expand All @@ -29,8 +27,6 @@ const {

const {
InternalCryptoKey,
PrivateKeyObject,
PublicKeyObject,
createPrivateKey,
createPublicKey,
isKeyObject,
Expand All @@ -45,7 +41,6 @@ const {
hasAnyNotIn,
jobPromise,
normalizeHashName,
validateKeyOps,
kKeyObject,
kHandle,
} = require('internal/crypto/util');
Expand Down Expand Up @@ -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}`,
Expand Down
5 changes: 0 additions & 5 deletions lib/internal/crypto/webcrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down