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: handle initEDRaw pkey failure #40188

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/internal/crypto/ec.js
Expand Up @@ -122,13 +122,12 @@ function createECRawKey(namedCurve, keyData, isPublic) {
break;
}

if (isPublic) {
handle.initEDRaw(namedCurve, keyData, kKeyTypePublic);
return new PublicKeyObject(handle);
const keyType = isPublic ? kKeyTypePublic : kKeyTypePrivate;
if (!handle.initEDRaw(namedCurve, keyData, keyType)) {
throw lazyDOMException('Failure to generate key object');
}

handle.initEDRaw(namedCurve, keyData, kKeyTypePrivate);
panva marked this conversation as resolved.
Show resolved Hide resolved
return new PrivateKeyObject(handle);
return isPublic ? new PublicKeyObject(handle) : new PrivateKeyObject(handle);
}

async function ecGenerateKey(algorithm, extractable, keyUsages) {
Expand Down
14 changes: 4 additions & 10 deletions lib/internal/crypto/keys.js
Expand Up @@ -435,16 +435,10 @@ function getKeyObjectHandleFromJwk(key, ctx) {
}

const handle = new KeyObjectHandle();
if (isPublic) {
handle.initEDRaw(
`NODE-${key.crv.toUpperCase()}`,
keyData,
kKeyTypePublic);
} else {
handle.initEDRaw(
`NODE-${key.crv.toUpperCase()}`,
keyData,
kKeyTypePrivate);

const keyType = isPublic ? kKeyTypePublic : kKeyTypePrivate;
if (!handle.initEDRaw(`NODE-${key.crv.toUpperCase()}`, keyData, keyType)) {
throw new ERR_CRYPTO_INVALID_JWK();
}

return handle;
Expand Down