fix_handle_boringssl_and_openssl_incompatibilities.patch 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Wed, 12 Feb 2020 15:08:04 -0800
  4. Subject: fix: handle BoringSSL and OpenSSL incompatibilities
  5. This patch corrects for imcompatibilities between OpenSSL, which Node.js uses,
  6. and BoringSSL which Electron uses via Chromium. Each incompatibility typically has
  7. ~2 paths forward:
  8. * Upstream a shim or adapted implementation to BoringSSL
  9. * Alter Node.js functionality to something which both libraries can handle.
  10. Where possible, we should seek to make this patch as minimal as possible.
  11. Upstreams:
  12. - https://github.com/nodejs/node/pull/39054
  13. - https://github.com/nodejs/node/pull/39138
  14. - https://github.com/nodejs/node/pull/39136
  15. diff --git a/deps/ncrypto/ncrypto.cc b/deps/ncrypto/ncrypto.cc
  16. index eb3533bb4623b152605c3c590f37f086cce5f073..ded231aeaa15af22845704cfcc7d24a44bd88f8e 100644
  17. --- a/deps/ncrypto/ncrypto.cc
  18. +++ b/deps/ncrypto/ncrypto.cc
  19. @@ -6,13 +6,11 @@
  20. #include <openssl/evp.h>
  21. #include <openssl/hmac.h>
  22. #include <openssl/pkcs12.h>
  23. +#include <openssl/rand.h>
  24. #include <openssl/x509v3.h>
  25. #if OPENSSL_VERSION_MAJOR >= 3
  26. #include <openssl/provider.h>
  27. #endif
  28. -#ifdef OPENSSL_IS_BORINGSSL
  29. -#include "dh-primes.h"
  30. -#endif // OPENSSL_IS_BORINGSSL
  31. namespace ncrypto {
  32. namespace {
  33. @@ -665,7 +663,7 @@ bool SafeX509SubjectAltNamePrint(const BIOPointer& out, X509_EXTENSION* ext) {
  34. bool ok = true;
  35. - for (int i = 0; i < sk_GENERAL_NAME_num(names); i++) {
  36. + for (size_t i = 0; i < sk_GENERAL_NAME_num(names); i++) {
  37. GENERAL_NAME* gen = sk_GENERAL_NAME_value(names, i);
  38. if (i != 0)
  39. @@ -691,7 +689,7 @@ bool SafeX509InfoAccessPrint(const BIOPointer& out, X509_EXTENSION* ext) {
  40. bool ok = true;
  41. - for (int i = 0; i < sk_ACCESS_DESCRIPTION_num(descs); i++) {
  42. + for (size_t i = 0; i < sk_ACCESS_DESCRIPTION_num(descs); i++) {
  43. ACCESS_DESCRIPTION* desc = sk_ACCESS_DESCRIPTION_value(descs, i);
  44. if (i != 0)
  45. @@ -1002,7 +1000,11 @@ BIOPointer BIOPointer::NewMem() {
  46. }
  47. BIOPointer BIOPointer::NewSecMem() {
  48. +#ifdef OPENSSL_IS_BORINGSSL
  49. + return BIOPointer(BIO_new(BIO_s_mem()));
  50. +#else
  51. return BIOPointer(BIO_new(BIO_s_secmem()));
  52. +#endif
  53. }
  54. BIOPointer BIOPointer::New(const BIO_METHOD* method) {
  55. @@ -1057,8 +1059,10 @@ BignumPointer DHPointer::FindGroup(const std::string_view name,
  56. FindGroupOption option) {
  57. #define V(n, p) if (EqualNoCase(name, n)) return BignumPointer(p(nullptr));
  58. if (option != FindGroupOption::NO_SMALL_PRIMES) {
  59. +#ifndef OPENSSL_IS_BORINGSSL
  60. V("modp1", BN_get_rfc2409_prime_768);
  61. V("modp2", BN_get_rfc2409_prime_1024);
  62. +#endif
  63. V("modp5", BN_get_rfc3526_prime_1536);
  64. }
  65. V("modp14", BN_get_rfc3526_prime_2048);
  66. @@ -1130,11 +1134,13 @@ DHPointer::CheckPublicKeyResult DHPointer::checkPublicKey(const BignumPointer& p
  67. int codes = 0;
  68. if (DH_check_pub_key(dh_.get(), pub_key.get(), &codes) != 1)
  69. return DHPointer::CheckPublicKeyResult::CHECK_FAILED;
  70. +#ifndef OPENSSL_IS_BORINGSSL
  71. if (codes & DH_CHECK_PUBKEY_TOO_SMALL) {
  72. return DHPointer::CheckPublicKeyResult::TOO_SMALL;
  73. } else if (codes & DH_CHECK_PUBKEY_TOO_SMALL) {
  74. return DHPointer::CheckPublicKeyResult::TOO_LARGE;
  75. - } else if (codes != 0) {
  76. +#endif
  77. + if (codes != 0) {
  78. return DHPointer::CheckPublicKeyResult::INVALID;
  79. }
  80. return CheckPublicKeyResult::NONE;
  81. diff --git a/deps/ncrypto/ncrypto.h b/deps/ncrypto/ncrypto.h
  82. index 661c996889d0a89c1c38658a0933fcf5e3cdc1b9..1261d5d99fdf4e17b8dec66660028ce184f1cf89 100644
  83. --- a/deps/ncrypto/ncrypto.h
  84. +++ b/deps/ncrypto/ncrypto.h
  85. @@ -413,8 +413,8 @@ public:
  86. #ifndef OPENSSL_IS_BORINGSSL
  87. TOO_SMALL = DH_R_CHECK_PUBKEY_TOO_SMALL,
  88. TOO_LARGE = DH_R_CHECK_PUBKEY_TOO_LARGE,
  89. - INVALID = DH_R_CHECK_PUBKEY_INVALID,
  90. #endif
  91. + INVALID = DH_R_INVALID_PUBKEY,
  92. CHECK_FAILED = 512,
  93. };
  94. // Check to see if the given public key is suitable for this DH instance.
  95. diff --git a/deps/ncrypto/unofficial.gni b/deps/ncrypto/unofficial.gni
  96. index ea024af73e215b3cad5f08796ac405f419530c86..41061b524eea74330b8d2452635a38c48f21386b 100644
  97. --- a/deps/ncrypto/unofficial.gni
  98. +++ b/deps/ncrypto/unofficial.gni
  99. @@ -27,6 +27,6 @@ template("ncrypto_gn_build") {
  100. forward_variables_from(invoker, "*")
  101. public_configs = [ ":ncrypto_config" ]
  102. sources = gypi_values.ncrypto_sources
  103. - deps = [ "../openssl" ]
  104. + deps = [ "$node_crypto_path" ]
  105. }
  106. }
  107. diff --git a/node.gni b/node.gni
  108. index 32709b860ccb12d8d1e75342a65dda0b86129b21..18d58591e3d0f1f3512db00033c3410a65702864 100644
  109. --- a/node.gni
  110. +++ b/node.gni
  111. @@ -10,6 +10,8 @@ declare_args() {
  112. # The location of V8, use the one from node's deps by default.
  113. node_v8_path = "//v8"
  114. + node_crypto_path = "//third_party/boringssl"
  115. +
  116. # The NODE_MODULE_VERSION defined in node_version.h.
  117. node_module_version = exec_script("$node_path/tools/getmoduleversion.py", [], "value")
  118. diff --git a/src/crypto/crypto_cipher.cc b/src/crypto/crypto_cipher.cc
  119. index fe35a8e0f6bbb7ab515a0343a7ed046c44e86474..43a7abbf237d8d809953e302b83755a3283a1bf4 100644
  120. --- a/src/crypto/crypto_cipher.cc
  121. +++ b/src/crypto/crypto_cipher.cc
  122. @@ -1078,7 +1078,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
  123. if (EVP_PKEY_decrypt_init(ctx.get()) <= 0) {
  124. return ThrowCryptoError(env, ERR_get_error());
  125. }
  126. -
  127. +#ifndef OPENSSL_IS_BORINGSSL
  128. int rsa_pkcs1_implicit_rejection =
  129. EVP_PKEY_CTX_ctrl_str(ctx.get(), "rsa_pkcs1_implicit_rejection", "1");
  130. // From the doc -2 means that the option is not supported.
  131. @@ -1094,6 +1094,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
  132. "RSA_PKCS1_PADDING is no longer supported for private decryption,"
  133. " this can be reverted with --security-revert=CVE-2024-PEND");
  134. }
  135. +#endif
  136. }
  137. const EVP_MD* digest = nullptr;
  138. diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc
  139. index 6a967702b22df0eb8aa10e853fd232794955860d..31058cccc6ffeed6b09aaecda320ee2f15849ec8 100644
  140. --- a/src/crypto/crypto_common.cc
  141. +++ b/src/crypto/crypto_common.cc
  142. @@ -134,7 +134,7 @@ const char* GetClientHelloALPN(const SSLPointer& ssl) {
  143. const unsigned char* buf;
  144. size_t len;
  145. size_t rem;
  146. -
  147. +#ifndef OPENSSL_IS_BORINGSSL
  148. if (!SSL_client_hello_get0_ext(
  149. ssl.get(),
  150. TLSEXT_TYPE_application_layer_protocol_negotiation,
  151. @@ -147,13 +147,15 @@ const char* GetClientHelloALPN(const SSLPointer& ssl) {
  152. len = (buf[0] << 8) | buf[1];
  153. if (len + 2 != rem) return nullptr;
  154. return reinterpret_cast<const char*>(buf + 3);
  155. +#endif
  156. + return nullptr;
  157. }
  158. const char* GetClientHelloServerName(const SSLPointer& ssl) {
  159. const unsigned char* buf;
  160. size_t len;
  161. size_t rem;
  162. -
  163. +#ifndef OPENSSL_IS_BORINGSSL
  164. if (!SSL_client_hello_get0_ext(
  165. ssl.get(),
  166. TLSEXT_TYPE_server_name,
  167. @@ -175,6 +177,8 @@ const char* GetClientHelloServerName(const SSLPointer& ssl) {
  168. if (len + 2 > rem)
  169. return nullptr;
  170. return reinterpret_cast<const char*>(buf + 5);
  171. +#endif
  172. + return nullptr;
  173. }
  174. const char* GetServerName(SSL* ssl) {
  175. @@ -282,7 +286,7 @@ StackOfX509 CloneSSLCerts(X509Pointer&& cert,
  176. if (!peer_certs) return StackOfX509();
  177. if (cert && !sk_X509_push(peer_certs.get(), cert.release()))
  178. return StackOfX509();
  179. - for (int i = 0; i < sk_X509_num(ssl_certs); i++) {
  180. + for (size_t i = 0; i < sk_X509_num(ssl_certs); i++) {
  181. X509Pointer cert(X509_dup(sk_X509_value(ssl_certs, i)));
  182. if (!cert || !sk_X509_push(peer_certs.get(), cert.get()))
  183. return StackOfX509();
  184. @@ -298,7 +302,7 @@ MaybeLocal<Object> AddIssuerChainToObject(X509Pointer* cert,
  185. Environment* const env) {
  186. cert->reset(sk_X509_delete(peer_certs.get(), 0));
  187. for (;;) {
  188. - int i;
  189. + size_t i;
  190. for (i = 0; i < sk_X509_num(peer_certs.get()); i++) {
  191. ncrypto::X509View ca(sk_X509_value(peer_certs.get(), i));
  192. if (!cert->view().isIssuedBy(ca)) continue;
  193. @@ -384,14 +388,14 @@ MaybeLocal<Array> GetClientHelloCiphers(
  194. Environment* env,
  195. const SSLPointer& ssl) {
  196. EscapableHandleScope scope(env->isolate());
  197. - const unsigned char* buf;
  198. - size_t len = SSL_client_hello_get0_ciphers(ssl.get(), &buf);
  199. + // const unsigned char* buf = nullptr;
  200. + size_t len = 0; // SSL_client_hello_get0_ciphers(ssl.get(), &buf);
  201. size_t count = len / 2;
  202. MaybeStackBuffer<Local<Value>, 16> ciphers(count);
  203. int j = 0;
  204. for (size_t n = 0; n < len; n += 2) {
  205. - const SSL_CIPHER* cipher = SSL_CIPHER_find(ssl.get(), buf);
  206. - buf += 2;
  207. + const SSL_CIPHER* cipher = nullptr; // SSL_CIPHER_find(ssl.get(), buf);
  208. + // buf += 2;
  209. Local<Object> obj = Object::New(env->isolate());
  210. if (!Set(env->context(),
  211. obj,
  212. @@ -444,8 +448,11 @@ MaybeLocal<Object> GetEphemeralKey(Environment* env, const SSLPointer& ssl) {
  213. EscapableHandleScope scope(env->isolate());
  214. Local<Object> info = Object::New(env->isolate());
  215. +#ifndef OPENSSL_IS_BORINGSSL
  216. if (!SSL_get_peer_tmp_key(ssl.get(), &raw_key)) return scope.Escape(info);
  217. -
  218. +#else
  219. + if (!SSL_get_server_tmp_key(ssl.get(), &raw_key)) return scope.Escape(info);
  220. +#endif
  221. Local<Context> context = env->context();
  222. crypto::EVPKeyPointer key(raw_key);
  223. diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc
  224. index c924a54639e8c22d765dc240dffacfffb200ca0c..287afcc792a0a2b7e19126ee9a48ebe21cc8844e 100644
  225. --- a/src/crypto/crypto_context.cc
  226. +++ b/src/crypto/crypto_context.cc
  227. @@ -94,7 +94,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx,
  228. // the CA certificates.
  229. SSL_CTX_clear_extra_chain_certs(ctx);
  230. - for (int i = 0; i < sk_X509_num(extra_certs); i++) {
  231. + for (size_t i = 0; i < sk_X509_num(extra_certs); i++) {
  232. X509* ca = sk_X509_value(extra_certs, i);
  233. // NOTE: Increments reference count on `ca`
  234. @@ -920,11 +920,12 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
  235. // If the user specified "auto" for dhparams, the JavaScript layer will pass
  236. // true to this function instead of the original string. Any other string
  237. // value will be interpreted as custom DH parameters below.
  238. +#ifndef OPENSSL_IS_BORINGSSL
  239. if (args[0]->IsTrue()) {
  240. CHECK(SSL_CTX_set_dh_auto(sc->ctx_.get(), true));
  241. return;
  242. }
  243. -
  244. +#endif
  245. DHPointer dh;
  246. {
  247. BIOPointer bio(LoadBIO(env, args[0]));
  248. @@ -1150,7 +1151,7 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) {
  249. }
  250. // Add CA certs too
  251. - for (int i = 0; i < sk_X509_num(extra_certs.get()); i++) {
  252. + for (size_t i = 0; i < sk_X509_num(extra_certs.get()); i++) {
  253. X509* ca = sk_X509_value(extra_certs.get(), i);
  254. X509_STORE_add_cert(sc->GetCertStoreOwnedByThisSecureContext(), ca);
  255. diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc
  256. index e5664dfa2bc7e11922fa965f28acdf21470d1147..33ffbbb85d05f5356183e3aa1ca23707c5629b5d 100644
  257. --- a/src/crypto/crypto_dh.cc
  258. +++ b/src/crypto/crypto_dh.cc
  259. @@ -7,7 +7,9 @@
  260. #include "memory_tracker-inl.h"
  261. #include "ncrypto.h"
  262. #include "node_errors.h"
  263. +#ifndef OPENSSL_IS_BORINGSSL
  264. #include "openssl/bnerr.h"
  265. +#endif
  266. #include "openssl/dh.h"
  267. #include "threadpoolwork-inl.h"
  268. #include "v8.h"
  269. @@ -86,11 +88,7 @@ void New(const FunctionCallbackInfo<Value>& args) {
  270. if (args[0]->IsInt32()) {
  271. int32_t bits = args[0].As<Int32>()->Value();
  272. if (bits < 2) {
  273. -#if OPENSSL_VERSION_MAJOR >= 3
  274. - ERR_put_error(ERR_LIB_DH, 0, DH_R_MODULUS_TOO_SMALL, __FILE__, __LINE__);
  275. -#else
  276. - ERR_put_error(ERR_LIB_BN, 0, BN_R_BITS_TOO_SMALL, __FILE__, __LINE__);
  277. -#endif
  278. + OPENSSL_PUT_ERROR(BN, BN_R_BITS_TOO_SMALL);
  279. return ThrowCryptoError(env, ERR_get_error(), "Invalid prime length");
  280. }
  281. @@ -103,7 +101,7 @@ void New(const FunctionCallbackInfo<Value>& args) {
  282. }
  283. int32_t generator = args[1].As<Int32>()->Value();
  284. if (generator < 2) {
  285. - ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__);
  286. + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
  287. return ThrowCryptoError(env, ERR_get_error(), "Invalid generator");
  288. }
  289. @@ -132,12 +130,12 @@ void New(const FunctionCallbackInfo<Value>& args) {
  290. if (args[1]->IsInt32()) {
  291. int32_t generator = args[1].As<Int32>()->Value();
  292. if (generator < 2) {
  293. - ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__);
  294. + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
  295. return ThrowCryptoError(env, ERR_get_error(), "Invalid generator");
  296. }
  297. bn_g = BignumPointer::New();
  298. if (!bn_g.setWord(generator)) {
  299. - ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__);
  300. + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
  301. return ThrowCryptoError(env, ERR_get_error(), "Invalid generator");
  302. }
  303. } else {
  304. @@ -146,11 +144,11 @@ void New(const FunctionCallbackInfo<Value>& args) {
  305. return THROW_ERR_OUT_OF_RANGE(env, "generator is too big");
  306. bn_g = BignumPointer(reinterpret_cast<uint8_t*>(arg1.data()), arg1.size());
  307. if (!bn_g) {
  308. - ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__);
  309. + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
  310. return ThrowCryptoError(env, ERR_get_error(), "Invalid generator");
  311. }
  312. if (bn_g.getWord() < 2) {
  313. - ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__);
  314. + OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
  315. return ThrowCryptoError(env, ERR_get_error(), "Invalid generator");
  316. }
  317. }
  318. @@ -258,15 +256,17 @@ void ComputeSecret(const FunctionCallbackInfo<Value>& args) {
  319. BignumPointer key(key_buf.data(), key_buf.size());
  320. switch (dh.checkPublicKey(key)) {
  321. - case DHPointer::CheckPublicKeyResult::INVALID:
  322. - // Fall-through
  323. case DHPointer::CheckPublicKeyResult::CHECK_FAILED:
  324. return THROW_ERR_CRYPTO_INVALID_KEYTYPE(env,
  325. "Unspecified validation error");
  326. +#ifndef OPENSSL_IS_BORINGSSL
  327. case DHPointer::CheckPublicKeyResult::TOO_SMALL:
  328. return THROW_ERR_CRYPTO_INVALID_KEYLEN(env, "Supplied key is too small");
  329. case DHPointer::CheckPublicKeyResult::TOO_LARGE:
  330. return THROW_ERR_CRYPTO_INVALID_KEYLEN(env, "Supplied key is too large");
  331. +#endif
  332. + case DHPointer::CheckPublicKeyResult::INVALID:
  333. + return THROW_ERR_CRYPTO_INVALID_KEYTYPE(env, "Supplied key is invalid");
  334. case DHPointer::CheckPublicKeyResult::NONE:
  335. break;
  336. }
  337. @@ -398,9 +398,11 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
  338. key_params = EVPKeyPointer(EVP_PKEY_new());
  339. CHECK(key_params);
  340. CHECK_EQ(EVP_PKEY_assign_DH(key_params.get(), dh.release()), 1);
  341. - } else if (int* prime_size = std::get_if<int>(&params->params.prime)) {
  342. + } else if (std::get_if<int>(&params->params.prime)) {
  343. EVPKeyCtxPointer param_ctx(EVP_PKEY_CTX_new_id(EVP_PKEY_DH, nullptr));
  344. EVP_PKEY* raw_params = nullptr;
  345. +#ifndef OPENSSL_IS_BORINGSSL
  346. + int* prime_size = std::get_if<int>(&params->params.prime);
  347. if (!param_ctx ||
  348. EVP_PKEY_paramgen_init(param_ctx.get()) <= 0 ||
  349. EVP_PKEY_CTX_set_dh_paramgen_prime_len(
  350. @@ -414,6 +416,9 @@ EVPKeyCtxPointer DhKeyGenTraits::Setup(DhKeyPairGenConfig* params) {
  351. }
  352. key_params = EVPKeyPointer(raw_params);
  353. +#else
  354. + return EVPKeyCtxPointer();
  355. +#endif
  356. } else {
  357. UNREACHABLE();
  358. }
  359. diff --git a/src/crypto/crypto_dsa.cc b/src/crypto/crypto_dsa.cc
  360. index 5d081863cf2dcdcf8c2d09db6060eeb5e78c452f..67523ec1c406e345945e1dde663c784c43a1c624 100644
  361. --- a/src/crypto/crypto_dsa.cc
  362. +++ b/src/crypto/crypto_dsa.cc
  363. @@ -40,7 +40,7 @@ namespace crypto {
  364. EVPKeyCtxPointer DsaKeyGenTraits::Setup(DsaKeyPairGenConfig* params) {
  365. EVPKeyCtxPointer param_ctx(EVP_PKEY_CTX_new_id(EVP_PKEY_DSA, nullptr));
  366. EVP_PKEY* raw_params = nullptr;
  367. -
  368. +#ifndef OPENSSL_IS_BORINGSSL
  369. if (!param_ctx ||
  370. EVP_PKEY_paramgen_init(param_ctx.get()) <= 0 ||
  371. EVP_PKEY_CTX_set_dsa_paramgen_bits(
  372. @@ -55,7 +55,9 @@ EVPKeyCtxPointer DsaKeyGenTraits::Setup(DsaKeyPairGenConfig* params) {
  373. return EVPKeyCtxPointer();
  374. }
  375. }
  376. -
  377. +#else
  378. + return EVPKeyCtxPointer();
  379. +#endif
  380. if (EVP_PKEY_paramgen(param_ctx.get(), &raw_params) <= 0)
  381. return EVPKeyCtxPointer();
  382. diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc
  383. index 8488fc57faaf722174032c5a927d150c76120d60..c51efc92d4818ee7701b4725585fb7e1d2d644ad 100644
  384. --- a/src/crypto/crypto_keys.cc
  385. +++ b/src/crypto/crypto_keys.cc
  386. @@ -1204,6 +1204,7 @@ void KeyObjectHandle::GetAsymmetricKeyType(
  387. }
  388. bool KeyObjectHandle::CheckEcKeyData() const {
  389. +#ifndef OPENSSL_IS_BORINGSSL
  390. MarkPopErrorOnReturn mark_pop_error_on_return;
  391. const auto& key = data_.GetAsymmetricKey();
  392. @@ -1220,6 +1221,9 @@ bool KeyObjectHandle::CheckEcKeyData() const {
  393. #else
  394. return EVP_PKEY_public_check(ctx.get()) == 1;
  395. #endif
  396. +#else
  397. + return true;
  398. +#endif
  399. }
  400. void KeyObjectHandle::CheckEcKeyData(const FunctionCallbackInfo<Value>& args) {
  401. diff --git a/src/crypto/crypto_random.cc b/src/crypto/crypto_random.cc
  402. index b59e394d9a7e2c19fdf1f2b0177753ff488da0fa..91218f49da5392c6f769495ee7f9275a47ce09b1 100644
  403. --- a/src/crypto/crypto_random.cc
  404. +++ b/src/crypto/crypto_random.cc
  405. @@ -134,7 +134,7 @@ Maybe<void> RandomPrimeTraits::AdditionalConfig(
  406. params->bits = bits;
  407. params->safe = safe;
  408. - params->prime = BignumPointer::NewSecure();
  409. + params->prime = BignumPointer::New();
  410. if (!params->prime) {
  411. THROW_ERR_CRYPTO_OPERATION_FAILED(env, "could not generate prime");
  412. return Nothing<void>();
  413. diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc
  414. index 02e8e24b4054afd4c3ca797c19a78927319a0d9e..d2a931a3f8f9490fe17ef8a82d0204ee2cca409d 100644
  415. --- a/src/crypto/crypto_rsa.cc
  416. +++ b/src/crypto/crypto_rsa.cc
  417. @@ -608,10 +608,11 @@ Maybe<void> GetRsaKeyDetail(Environment* env,
  418. }
  419. if (params->saltLength != nullptr) {
  420. - if (ASN1_INTEGER_get_int64(&salt_length, params->saltLength) != 1) {
  421. - ThrowCryptoError(env, ERR_get_error(), "ASN1_INTEGER_get_in64 error");
  422. - return Nothing<void>();
  423. - }
  424. + // TODO(codebytere): Upstream a shim to BoringSSL?
  425. + // if (ASN1_INTEGER_get_int64(&salt_length, params->saltLength) != 1) {
  426. + // ThrowCryptoError(env, ERR_get_error(), "ASN1_INTEGER_get_in64 error");
  427. + // return Nothing<void>();
  428. + // }
  429. }
  430. if (target
  431. diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc
  432. index 793c196f8ce538c66b20611d00e12392ff9e878b..ee81048caab4ccfe26ea9e677782c9c955d162a9 100644
  433. --- a/src/crypto/crypto_util.cc
  434. +++ b/src/crypto/crypto_util.cc
  435. @@ -495,24 +495,15 @@ Maybe<void> Decorate(Environment* env,
  436. V(BIO) \
  437. V(PKCS7) \
  438. V(X509V3) \
  439. - V(PKCS12) \
  440. V(RAND) \
  441. - V(DSO) \
  442. V(ENGINE) \
  443. V(OCSP) \
  444. V(UI) \
  445. V(COMP) \
  446. V(ECDSA) \
  447. V(ECDH) \
  448. - V(OSSL_STORE) \
  449. - V(FIPS) \
  450. - V(CMS) \
  451. - V(TS) \
  452. V(HMAC) \
  453. - V(CT) \
  454. - V(ASYNC) \
  455. - V(KDF) \
  456. - V(SM2) \
  457. + V(HKDF) \
  458. V(USER) \
  459. #define V(name) case ERR_LIB_##name: lib = #name "_"; break;
  460. @@ -654,7 +645,7 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
  461. CHECK(args[0]->IsUint32());
  462. Environment* env = Environment::GetCurrent(args);
  463. uint32_t len = args[0].As<Uint32>()->Value();
  464. - void* data = OPENSSL_secure_zalloc(len);
  465. + void* data = OPENSSL_malloc(len);
  466. if (data == nullptr) {
  467. // There's no memory available for the allocation.
  468. // Return nothing.
  469. @@ -665,7 +656,7 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
  470. data,
  471. len,
  472. [](void* data, size_t len, void* deleter_data) {
  473. - OPENSSL_secure_clear_free(data, len);
  474. + OPENSSL_clear_free(data, len);
  475. },
  476. data);
  477. Local<ArrayBuffer> buffer = ArrayBuffer::New(env->isolate(), store);
  478. @@ -673,10 +664,12 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
  479. }
  480. void SecureHeapUsed(const FunctionCallbackInfo<Value>& args) {
  481. +#ifndef OPENSSL_IS_BORINGSSL
  482. Environment* env = Environment::GetCurrent(args);
  483. if (CRYPTO_secure_malloc_initialized())
  484. args.GetReturnValue().Set(
  485. BigInt::New(env->isolate(), CRYPTO_secure_used()));
  486. +#endif
  487. }
  488. } // namespace
  489. diff --git a/src/env.h b/src/env.h
  490. index fc8dbd615255851cad90e1d8ffe225f5e0c6a718..49ca9c0042ccf22ad1fffa54f05fd443cbc681ba 100644
  491. --- a/src/env.h
  492. +++ b/src/env.h
  493. @@ -50,7 +50,7 @@
  494. #include "uv.h"
  495. #include "v8.h"
  496. -#if HAVE_OPENSSL
  497. +#if HAVE_OPENSSL && OPENSSL_VERSION_MAJOR >= 3
  498. #include <openssl/evp.h>
  499. #endif
  500. @@ -1073,7 +1073,7 @@ class Environment final : public MemoryRetainer {
  501. kExitInfoFieldCount
  502. };
  503. -#if HAVE_OPENSSL
  504. +#if HAVE_OPENSSL// && !defined(OPENSSL_IS_BORINGSSL)
  505. #if OPENSSL_VERSION_MAJOR >= 3
  506. // We declare another alias here to avoid having to include crypto_util.h
  507. using EVPMDPointer = DeleteFnPtr<EVP_MD, EVP_MD_free>;
  508. diff --git a/src/node_metadata.h b/src/node_metadata.h
  509. index c59e65ad1fe3fac23f1fc25ca77e6133d1ccaccd..f2f07434e076e2977755ef7dac7d489aedb760b0 100644
  510. --- a/src/node_metadata.h
  511. +++ b/src/node_metadata.h
  512. @@ -6,7 +6,7 @@
  513. #include <string>
  514. #include "node_version.h"
  515. -#if HAVE_OPENSSL
  516. +#if 0
  517. #include <openssl/crypto.h>
  518. #if NODE_OPENSSL_HAS_QUIC
  519. #include <openssl/quic.h>
  520. diff --git a/src/node_options.cc b/src/node_options.cc
  521. index cfc599ec9a6197231c3469d318f02c620cdb03a8..29630fcccc3bd9d24ad6aec64bef2fedfc3c4031 100644
  522. --- a/src/node_options.cc
  523. +++ b/src/node_options.cc
  524. @@ -6,7 +6,7 @@
  525. #include "node_external_reference.h"
  526. #include "node_internals.h"
  527. #include "node_sea.h"
  528. -#if HAVE_OPENSSL
  529. +#if HAVE_OPENSSL && !defined(OPENSSL_IS_BORINGSSL)
  530. #include "openssl/opensslv.h"
  531. #endif
  532. diff --git a/src/node_options.h b/src/node_options.h
  533. index 9e656a2815045aa5da7eb267708c03058be9f362..600e0850f01e01024414d42b25605f256200540a 100644
  534. --- a/src/node_options.h
  535. +++ b/src/node_options.h
  536. @@ -11,7 +11,7 @@
  537. #include "node_mutex.h"
  538. #include "util.h"
  539. -#if HAVE_OPENSSL
  540. +#if 0
  541. #include "openssl/opensslv.h"
  542. #endif
  543. diff --git a/unofficial.gni b/unofficial.gni
  544. index de6ff5548ca5282199b7d85c11941c1fa351a9d9..3d8b7957e791ce2fa2a8d0937a87b6010087803d 100644
  545. --- a/unofficial.gni
  546. +++ b/unofficial.gni
  547. @@ -145,7 +145,6 @@ template("node_gn_build") {
  548. ]
  549. deps = [
  550. ":run_node_js2c",
  551. - "deps/brotli",
  552. "deps/cares",
  553. "deps/histogram",
  554. "deps/llhttp",
  555. @@ -156,6 +155,8 @@ template("node_gn_build") {
  556. "deps/sqlite",
  557. "deps/uvwasi",
  558. "//third_party/zlib",
  559. + "//third_party/brotli:dec",
  560. + "//third_party/brotli:enc",
  561. "$node_v8_path:v8_libplatform",
  562. ]
  563. @@ -182,10 +183,8 @@ template("node_gn_build") {
  564. deps += [ "//third_party/icu" ]
  565. }
  566. if (node_use_openssl) {
  567. - deps += [
  568. - "deps/ncrypto",
  569. - "//third_party/boringssl"
  570. - ]
  571. + deps += [ "deps/ncrypto" ]
  572. + public_deps += [ "$node_crypto_path" ]
  573. sources += gypi_values.node_crypto_sources
  574. }
  575. if (node_enable_inspector) {