Skip to content

Commit 6c57465

Browse files
RafaelGSSpanvatniessen
committed
src: fix error handling on async crypto operations
Fixes: https://hackerone.com/reports/2817648 Co-Authored-By: Filip Skokan <panva.ip@gmail.com> Co-Authored-By: Tobias Nießen <tniessen@tnie.de> Backport-PR-URL: nodejs-private/node-private#688 CVE-ID: CVE-2025-23166 PR-URL: nodejs-private/node-private#710
1 parent fc68c44 commit 6c57465

20 files changed

+122
-89
lines changed

src/crypto/crypto_dh.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,10 @@ Maybe<bool> DHBitsTraits::EncodeOutput(
705705
return Just(!result->IsEmpty());
706706
}
707707

708-
bool DHBitsTraits::DeriveBits(
709-
Environment* env,
710-
const DHBitsConfig& params,
711-
ByteSource* out) {
708+
bool DHBitsTraits::DeriveBits(Environment* env,
709+
const DHBitsConfig& params,
710+
ByteSource* out,
711+
CryptoJobMode mode) {
712712
*out = StatelessDiffieHellmanThreadsafe(
713713
params.private_key->GetAsymmetricKey(),
714714
params.public_key->GetAsymmetricKey());

src/crypto/crypto_dh.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ struct DHBitsTraits final {
131131
unsigned int offset,
132132
DHBitsConfig* params);
133133

134-
static bool DeriveBits(
135-
Environment* env,
136-
const DHBitsConfig& params,
137-
ByteSource* out_);
134+
static bool DeriveBits(Environment* env,
135+
const DHBitsConfig& params,
136+
ByteSource* out_,
137+
CryptoJobMode mode);
138138

139139
static v8::Maybe<bool> EncodeOutput(
140140
Environment* env,

src/crypto/crypto_ec.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ Maybe<bool> ECDHBitsTraits::AdditionalConfig(
480480

481481
bool ECDHBitsTraits::DeriveBits(Environment* env,
482482
const ECDHBitsConfig& params,
483-
ByteSource* out) {
483+
ByteSource* out,
484+
CryptoJobMode mode) {
484485
size_t len = 0;
485486
ManagedEVPPKey m_privkey = params.private_->GetAsymmetricKey();
486487
ManagedEVPPKey m_pubkey = params.public_->GetAsymmetricKey();

src/crypto/crypto_ec.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ struct ECDHBitsTraits final {
7777
unsigned int offset,
7878
ECDHBitsConfig* params);
7979

80-
static bool DeriveBits(
81-
Environment* env,
82-
const ECDHBitsConfig& params,
83-
ByteSource* out_);
80+
static bool DeriveBits(Environment* env,
81+
const ECDHBitsConfig& params,
82+
ByteSource* out_,
83+
CryptoJobMode mode);
8484

8585
static v8::Maybe<bool> EncodeOutput(
8686
Environment* env,

src/crypto/crypto_hash.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,10 @@ Maybe<bool> HashTraits::AdditionalConfig(
501501
return Just(true);
502502
}
503503

504-
bool HashTraits::DeriveBits(
505-
Environment* env,
506-
const HashConfig& params,
507-
ByteSource* out) {
504+
bool HashTraits::DeriveBits(Environment* env,
505+
const HashConfig& params,
506+
ByteSource* out,
507+
CryptoJobMode mode) {
508508
EVPMDCtxPointer ctx(EVP_MD_CTX_new());
509509

510510
if (UNLIKELY(!ctx ||

src/crypto/crypto_hash.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ struct HashTraits final {
7070
unsigned int offset,
7171
HashConfig* params);
7272

73-
static bool DeriveBits(
74-
Environment* env,
75-
const HashConfig& params,
76-
ByteSource* out);
73+
static bool DeriveBits(Environment* env,
74+
const HashConfig& params,
75+
ByteSource* out,
76+
CryptoJobMode mode);
7777

7878
static v8::Maybe<bool> EncodeOutput(
7979
Environment* env,

src/crypto/crypto_hkdf.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ Maybe<bool> HKDFTraits::AdditionalConfig(
100100
return Just(true);
101101
}
102102

103-
bool HKDFTraits::DeriveBits(
104-
Environment* env,
105-
const HKDFConfig& params,
106-
ByteSource* out) {
103+
bool HKDFTraits::DeriveBits(Environment* env,
104+
const HKDFConfig& params,
105+
ByteSource* out,
106+
CryptoJobMode mode) {
107107
EVPKeyCtxPointer ctx =
108108
EVPKeyCtxPointer(EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, nullptr));
109109
if (!ctx || !EVP_PKEY_derive_init(ctx.get()) ||

src/crypto/crypto_hkdf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ struct HKDFTraits final {
4242
unsigned int offset,
4343
HKDFConfig* params);
4444

45-
static bool DeriveBits(
46-
Environment* env,
47-
const HKDFConfig& params,
48-
ByteSource* out);
45+
static bool DeriveBits(Environment* env,
46+
const HKDFConfig& params,
47+
ByteSource* out,
48+
CryptoJobMode mode);
4949

5050
static v8::Maybe<bool> EncodeOutput(
5151
Environment* env,

src/crypto/crypto_hmac.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ Maybe<bool> HmacTraits::AdditionalConfig(
220220
return Just(true);
221221
}
222222

223-
bool HmacTraits::DeriveBits(
224-
Environment* env,
225-
const HmacConfig& params,
226-
ByteSource* out) {
223+
bool HmacTraits::DeriveBits(Environment* env,
224+
const HmacConfig& params,
225+
ByteSource* out,
226+
CryptoJobMode mode) {
227227
HMACCtxPointer ctx(HMAC_CTX_new());
228228

229229
if (!ctx ||

src/crypto/crypto_hmac.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ struct HmacTraits final {
7373
unsigned int offset,
7474
HmacConfig* params);
7575

76-
static bool DeriveBits(
77-
Environment* env,
78-
const HmacConfig& params,
79-
ByteSource* out);
76+
static bool DeriveBits(Environment* env,
77+
const HmacConfig& params,
78+
ByteSource* out,
79+
CryptoJobMode mode);
8080

8181
static v8::Maybe<bool> EncodeOutput(
8282
Environment* env,

0 commit comments

Comments
 (0)