From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Wed, 27 May 2020 13:02:13 -0700
Subject: fix: comment out incompatible crypto modules

Node.js introduced some functionality in https://github.com/nodejs/node/pull/32739
and https://github.com/nodejs/node/pull/31178 that is not currently compatible
with what's exposed through BoringSSL. I plan to upstream parts of this or
otherwise introduce shims to reduce friction.

diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 91cb94d8dbe9db0adbee5e005649188e1ccbcbf9..2000c789d9daac835c0ecc1e4144179575c9b502 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -5192,11 +5192,11 @@ bool DiffieHellman::Init(int primeLength, int g) {
 bool DiffieHellman::Init(const char* p, int p_len, int g) {
   dh_.reset(DH_new());
   if (p_len <= 0) {
-    BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);
+    OPENSSL_PUT_ERROR(BN, BN_R_BITS_TOO_SMALL);
     return false;
   }
   if (g <= 1) {
-    DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
+    OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
     return false;
   }
   BIGNUM* bn_p =
@@ -5215,18 +5215,18 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) {
 bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) {
   dh_.reset(DH_new());
   if (p_len <= 0) {
-    BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);
+    OPENSSL_PUT_ERROR(BN, BN_R_BITS_TOO_SMALL);
     return false;
   }
   if (g_len <= 0) {
-    DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
+    OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
     return false;
   }
   BIGNUM* bn_g =
       BN_bin2bn(reinterpret_cast<const unsigned char*>(g), g_len, nullptr);
   if (BN_is_zero(bn_g) || BN_is_one(bn_g)) {
     BN_free(bn_g);
-    DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
+    OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
     return false;
   }
   BIGNUM* bn_p =
@@ -5719,7 +5719,7 @@ void ECDH::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
   if (!EC_KEY_set_public_key(new_key.get(), pub.get()))
     return env->ThrowError("Failed to set generated public key");
 
-  EC_KEY_copy(ecdh->key_.get(), new_key.get());
+  ecdh->key_.reset(EC_KEY_dup(new_key.get()));
   ecdh->group_ = EC_KEY_get0_group(ecdh->key_.get());
 }
 
@@ -6207,6 +6207,7 @@ class DHKeyPairGenerationConfig : public KeyPairGenerationConfig {
   EVPKeyCtxPointer Setup() override {
     EVPKeyPointer params;
     if (prime_info_.fixed_value_) {
+#if 0
       DHPointer dh(DH_new());
       if (!dh)
         return nullptr;
@@ -6223,6 +6224,7 @@ class DHKeyPairGenerationConfig : public KeyPairGenerationConfig {
       params = EVPKeyPointer(EVP_PKEY_new());
       CHECK(params);
       EVP_PKEY_assign_DH(params.get(), dh.release());
+#endif
     } else {
       EVPKeyCtxPointer param_ctx(EVP_PKEY_CTX_new_id(EVP_PKEY_DH, nullptr));
       if (!param_ctx)
@@ -6230,7 +6232,7 @@ class DHKeyPairGenerationConfig : public KeyPairGenerationConfig {
 
       if (EVP_PKEY_paramgen_init(param_ctx.get()) <= 0)
         return nullptr;
-
+#if 0
       if (EVP_PKEY_CTX_set_dh_paramgen_prime_len(param_ctx.get(),
                                                  prime_info_.prime_size_) <= 0)
         return nullptr;
@@ -6238,7 +6240,7 @@ class DHKeyPairGenerationConfig : public KeyPairGenerationConfig {
       if (EVP_PKEY_CTX_set_dh_paramgen_generator(param_ctx.get(),
                                                  generator_) <= 0)
         return nullptr;
-
+#endif
       EVP_PKEY* raw_params = nullptr;
       if (EVP_PKEY_paramgen(param_ctx.get(), &raw_params) <= 0)
         return nullptr;
