Skip to content

Commit 323cafb

Browse files
committed
crypto: handle initEDRaw pkey failure
1 parent c7da13c commit 323cafb

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/internal/crypto/ec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,15 @@ function createECRawKey(namedCurve, keyData, isPublic) {
123123
}
124124

125125
if (isPublic) {
126-
handle.initEDRaw(namedCurve, keyData, kKeyTypePublic);
126+
if (!handle.initEDRaw(namedCurve, keyData, kKeyTypePublic)) {
127+
throw lazyDOMException('Failure to generate key object');
128+
}
127129
return new PublicKeyObject(handle);
128130
}
129131

130-
handle.initEDRaw(namedCurve, keyData, kKeyTypePrivate);
132+
if (!handle.initEDRaw(namedCurve, keyData, kKeyTypePrivate)) {
133+
throw lazyDOMException('Failure to generate key object');
134+
}
131135
return new PrivateKeyObject(handle);
132136
}
133137

lib/internal/crypto/keys.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,19 @@ function getKeyObjectHandleFromJwk(key, ctx) {
436436

437437
const handle = new KeyObjectHandle();
438438
if (isPublic) {
439-
handle.initEDRaw(
439+
if (!handle.initEDRaw(
440440
`NODE-${key.crv.toUpperCase()}`,
441441
keyData,
442-
kKeyTypePublic);
442+
kKeyTypePublic)) {
443+
throw new ERR_CRYPTO_INVALID_JWK();
444+
}
443445
} else {
444-
handle.initEDRaw(
446+
if (!handle.initEDRaw(
445447
`NODE-${key.crv.toUpperCase()}`,
446448
keyData,
447-
kKeyTypePrivate);
449+
kKeyTypePrivate)) {
450+
throw new ERR_CRYPTO_INVALID_JWK();
451+
}
448452
}
449453

450454
return handle;

0 commit comments

Comments
 (0)