crypto: handle incomplete RSA private keys · nodejs/node@a5d4ac8 · GitHub
Skip to content

Commit a5d4ac8

Browse files
panvaaduh95
authored andcommitted
crypto: handle incomplete RSA private keys
Treat missing private RSA parameters as an export failure instead of passing null BIGNUM pointers to the JWK encoder. Also stop constructing a usable RSA view when reading an optional parameter itself fails. Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64547 Backport-PR-URL: #65087 Refs: #64211 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent b72c0b9 commit a5d4ac8

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

deps/ncrypto/ncrypto.cc

Lines changed: 8 additions & 6 deletions

src/crypto/crypto_rsa.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ bool ExportJWKRsaKey(Environment* env,
357357

358358
if (key.GetKeyType() == kKeyTypePrivate) {
359359
auto pvt_key = rsa.getPrivateKey();
360+
if (pub_key.d == nullptr || pvt_key.p == nullptr || pvt_key.q == nullptr ||
361+
pvt_key.dp == nullptr || pvt_key.dq == nullptr ||
362+
pvt_key.qi == nullptr) {
363+
THROW_ERR_CRYPTO_OPERATION_FAILED(env,
364+
"Failed to export RSA private key");
365+
return false;
366+
}
360367
if (SetEncodedValue(env, target, env->jwk_d_string(), pub_key.d)
361368
.IsNothing() ||
362369
SetEncodedValue(env, target, env->jwk_p_string(), pvt_key.p)

test/cctest/test_node_crypto_env.cc

Lines changed: 27 additions & 0 deletions

0 commit comments

Comments
 (0)