Skip to content

Commit e72192e

Browse files
committed
src: move more crypto_dh.cc code to ncrypto
nodejs/node#54459
1 parent 330374d commit e72192e

4 files changed

+75
-76
lines changed

patches/node/.patches

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,3 @@ add_v8_taskpirority_to_foreground_task_runner_signature.patch
4141
cli_remove_deprecated_v8_flag.patch
4242
build_restore_clang_as_default_compiler_on_macos.patch
4343
fix_-wextra-semi_errors_in_nghttp2_helper_h.patch
44-
crypto_fix_integer_comparison_in_crypto_for_boringssl.patch

patches/node/crypto_fix_integer_comparison_in_crypto_for_boringssl.patch

Lines changed: 0 additions & 64 deletions
This file was deleted.

patches/node/fix_handle_boringssl_and_openssl_incompatibilities.patch

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ index fe35a8e0f6bbb7ab515a0343a7ed046c44e86474..43a7abbf237d8d809953e302b83755a3
5353

5454
const EVP_MD* digest = nullptr;
5555
diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc
56-
index 6a967702b22df0eb8aa10e853fd232794955860d..b5631ed9d55339705a9b52dad66ac4a884df5f31 100644
56+
index 6a967702b22df0eb8aa10e853fd232794955860d..31058cccc6ffeed6b09aaecda320ee2f15849ec8 100644
5757
--- a/src/crypto/crypto_common.cc
5858
+++ b/src/crypto/crypto_common.cc
5959
@@ -134,7 +134,7 @@ const char* GetClientHelloALPN(const SSLPointer& ssl) {
@@ -91,6 +91,24 @@ index 6a967702b22df0eb8aa10e853fd232794955860d..b5631ed9d55339705a9b52dad66ac4a8
9191
}
9292

9393
const char* GetServerName(SSL* ssl) {
94+
@@ -282,7 +286,7 @@ StackOfX509 CloneSSLCerts(X509Pointer&& cert,
95+
if (!peer_certs) return StackOfX509();
96+
if (cert && !sk_X509_push(peer_certs.get(), cert.release()))
97+
return StackOfX509();
98+
- for (int i = 0; i < sk_X509_num(ssl_certs); i++) {
99+
+ for (size_t i = 0; i < sk_X509_num(ssl_certs); i++) {
100+
X509Pointer cert(X509_dup(sk_X509_value(ssl_certs, i)));
101+
if (!cert || !sk_X509_push(peer_certs.get(), cert.get()))
102+
return StackOfX509();
103+
@@ -298,7 +302,7 @@ MaybeLocal<Object> AddIssuerChainToObject(X509Pointer* cert,
104+
Environment* const env) {
105+
cert->reset(sk_X509_delete(peer_certs.get(), 0));
106+
for (;;) {
107+
- int i;
108+
+ size_t i;
109+
for (i = 0; i < sk_X509_num(peer_certs.get()); i++) {
110+
ncrypto::X509View ca(sk_X509_value(peer_certs.get(), i));
111+
if (!cert->view().isIssuedBy(ca)) continue;
94112
@@ -384,14 +388,14 @@ MaybeLocal<Array> GetClientHelloCiphers(
95113
Environment* env,
96114
const SSLPointer& ssl) {
@@ -124,7 +142,7 @@ index 6a967702b22df0eb8aa10e853fd232794955860d..b5631ed9d55339705a9b52dad66ac4a8
124142
crypto::EVPKeyPointer key(raw_key);
125143

126144
diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc
127-
index c924a54639e8c22d765dc240dffacfffb200ca0c..661e8a13c9245f76441414982dc4a996f4896a81 100644
145+
index c924a54639e8c22d765dc240dffacfffb200ca0c..94fd301b9dc81aa86f41151417f67e7dbe2f3e4f 100644
128146
--- a/src/crypto/crypto_context.cc
129147
+++ b/src/crypto/crypto_context.cc
130148
@@ -64,7 +64,7 @@ X509_STORE* GetOrCreateRootCertStore() {
@@ -136,6 +154,15 @@ index c924a54639e8c22d765dc240dffacfffb200ca0c..661e8a13c9245f76441414982dc4a996
136154
if (!bio) return {};
137155
ByteSource bsrc = ByteSource::FromStringOrBuffer(env, v);
138156
if (bsrc.size() > INT_MAX) return {};
157+
@@ -94,7 +94,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
158+
// the CA certificates.
159+
SSL_CTX_clear_extra_chain_certs(ctx);
160+
161+
- for (int i = 0; i < sk_X509_num(extra_certs); i++) {
162+
+ for (size_t i = 0; i < sk_X509_num(extra_certs); i++) {
163+
X509* ca = sk_X509_value(extra_certs, i);
164+
165+
// NOTE: Increments reference count on `ca`
139166
@@ -920,11 +920,12 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
140167
// If the user specified "auto" for dhparams, the JavaScript layer will pass
141168
// true to this function instead of the original string. Any other string
@@ -150,11 +177,30 @@ index c924a54639e8c22d765dc240dffacfffb200ca0c..661e8a13c9245f76441414982dc4a996
150177
DHPointer dh;
151178
{
152179
BIOPointer bio(LoadBIO(env, args[0]));
180+
@@ -1150,7 +1151,7 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) {
181+
}
182+
183+
// Add CA certs too
184+
- for (int i = 0; i < sk_X509_num(extra_certs.get()); i++) {
185+
+ for (size_t i = 0; i < sk_X509_num(extra_certs.get()); i++) {
186+
X509* ca = sk_X509_value(extra_certs.get(), i);
187+
188+
X509_STORE_add_cert(sc->GetCertStoreOwnedByThisSecureContext(), ca);
153189
diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc
154-
index e5664dfa2bc7e11922fa965f28acdf21470d1147..d8df6b46013ed8177270648e89b5f9ce6bf548f2 100644
190+
index e5664dfa2bc7e11922fa965f28acdf21470d1147..c9e32ee754cec137f3e7673956e6af1360cb767f 100644
155191
--- a/src/crypto/crypto_dh.cc
156192
+++ b/src/crypto/crypto_dh.cc
157-
@@ -86,11 +86,7 @@ void New(const FunctionCallbackInfo<Value>& args) {
193+
@@ -7,7 +7,9 @@
194+
#include "memory_tracker-inl.h"
195+
#include "ncrypto.h"
196+
#include "node_errors.h"
197+
+#ifndef OPENSSL_IS_BORINGSSL
198+
#include "openssl/bnerr.h"
199+
+#endif
200+
#include "openssl/dh.h"
201+
#include "threadpoolwork-inl.h"
202+
#include "v8.h"
203+
@@ -86,11 +88,7 @@ void New(const FunctionCallbackInfo<Value>& args) {
158204
if (args[0]->IsInt32()) {
159205
int32_t bits = args[0].As<Int32>()->Value();
160206
if (bits < 2) {
@@ -167,7 +213,7 @@ index e5664dfa2bc7e11922fa965f28acdf21470d1147..d8df6b46013ed8177270648e89b5f9ce
167213
return ThrowCryptoError(env, ERR_get_error(), "Invalid prime length");
168214
}
169215

170-
@@ -103,7 +99,7 @@ void New(const FunctionCallbackInfo<Value>& args) {
216+
@@ -103,7 +101,7 @@ void New(const FunctionCallbackInfo<Value>& args) {
171217
}
172218
int32_t generator = args[1].As<Int32>()->Value();
173219
if (generator < 2) {
@@ -176,7 +222,7 @@ index e5664dfa2bc7e11922fa965f28acdf21470d1147..d8df6b46013ed8177270648e89b5f9ce
176222
return ThrowCryptoError(env, ERR_get_error(), "Invalid generator");
177223
}
178224

179-
@@ -132,12 +128,12 @@ void New(const FunctionCallbackInfo<Value>& args) {
225+
@@ -132,12 +130,12 @@ void New(const FunctionCallbackInfo<Value>& args) {
180226
if (args[1]->IsInt32()) {
181227
int32_t generator = args[1].As<Int32>()->Value();
182228
if (generator < 2) {
@@ -191,7 +237,7 @@ index e5664dfa2bc7e11922fa965f28acdf21470d1147..d8df6b46013ed8177270648e89b5f9ce
191237
return ThrowCryptoError(env, ERR_get_error(), "Invalid generator");
192238
}
193239
} else {
194-
@@ -146,11 +142,11 @@ void New(const FunctionCallbackInfo<Value>& args) {
240+
@@ -146,11 +144,11 @@ void New(const FunctionCallbackInfo<Value>& args) {
195241
return THROW_ERR_OUT_OF_RANGE(env, "generator is too big");
196242
bn_g = BignumPointer(reinterpret_cast<uint8_t*>(arg1.data()), arg1.size());
197243
if (!bn_g) {
@@ -205,7 +251,25 @@ index e5664dfa2bc7e11922fa965f28acdf21470d1147..d8df6b46013ed8177270648e89b5f9ce
205251
return ThrowCryptoError(env, ERR_get_error(), "Invalid generator");
206252
}
207253
}
208-
@@ -398,9 +394,11 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
254+
@@ -258,15 +256,15 @@ void ComputeSecret(const FunctionCallbackInfo<Value>& args) {
255+
BignumPointer key(key_buf.data(), key_buf.size());
256+
257+
switch (dh.checkPublicKey(key)) {
258+
- case DHPointer::CheckPublicKeyResult::INVALID:
259+
- // Fall-through
260+
case DHPointer::CheckPublicKeyResult::CHECK_FAILED:
261+
return THROW_ERR_CRYPTO_INVALID_KEYTYPE(env,
262+
"Unspecified validation error");
263+
+#ifndef OPENSSL_IS_BORINGSSL
264+
case DHPointer::CheckPublicKeyResult::TOO_SMALL:
265+
return THROW_ERR_CRYPTO_INVALID_KEYLEN(env, "Supplied key is too small");
266+
case DHPointer::CheckPublicKeyResult::TOO_LARGE:
267+
return THROW_ERR_CRYPTO_INVALID_KEYLEN(env, "Supplied key is too large");
268+
+#endif
269+
case DHPointer::CheckPublicKeyResult::NONE:
270+
break;
271+
}
272+
@@ -398,9 +396,11 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
209273
key_params = EVPKeyPointer(EVP_PKEY_new());
210274
CHECK(key_params);
211275
CHECK_EQ(EVP_PKEY_assign_DH(key_params.get(), dh.release()), 1);
@@ -218,7 +282,7 @@ index e5664dfa2bc7e11922fa965f28acdf21470d1147..d8df6b46013ed8177270648e89b5f9ce
218282
if (!param_ctx ||
219283
EVP_PKEY_paramgen_init(param_ctx.get()) <= 0 ||
220284
EVP_PKEY_CTX_set_dh_paramgen_prime_len(
221-
@@ -414,6 +412,9 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
285+
@@ -414,6 +414,9 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
222286
}
223287

224288
key_params = EVPKeyPointer(raw_params);

patches/node/src_stop_using_deprecated_fields_of_fastapicallbackoptions.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ index 4dbdea9be5721486d71a9dda77311b4919d450a3..4aacaa2a5d12533a039b4b96cb7f1fd7
4040
}
4141
HistogramBase* histogram;
4242
diff --git a/src/node_file.cc b/src/node_file.cc
43-
index b565beae625d970ba92ab667a145d8897d4e8a6e..b61f3ef87d6095fc2d4c015df2af32bfba697e76 100644
43+
index b565beae625d970ba92ab667a145d8897d4e8a6e..31c2fe82299d6905855c4efffeea4a4d161a88d5 100644
4444
--- a/src/node_file.cc
4545
+++ b/src/node_file.cc
46-
@@ -1049,22 +1049,8 @@ static int32_t FastInternalModuleStat(
46+
@@ -1049,23 +1049,10 @@ static int32_t FastInternalModuleStat(
4747
const FastOneByteString& input,
4848
// NOLINTNEXTLINE(runtime/references) This is V8 api.
4949
FastApiCallbackOptions& options) {

0 commit comments

Comments
 (0)