fix_handle_boringssl_and_openssl_incompatibilities.patch 24 KB

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