From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cheng Zhao <zcbenz@gmail.com>
Date: Fri, 29 Mar 2019 16:50:56 +0900
Subject: fix: key gen APIs are not available in BoringSSL

This will make Node's key pair generation APIs fail.

diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index bca482cc9724fef680196a192a6bbd7b4d2e4fde..1cc2372fe2e385e9a9db27e38f0da61d62de2e81 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -290,24 +290,14 @@ Maybe<bool> Decorate(Environment* env, Local<Object> obj,
     V(BIO)                                                                    \
     V(PKCS7)                                                                  \
     V(X509V3)                                                                 \
-    V(PKCS12)                                                                 \
     V(RAND)                                                                   \
-    V(DSO)                                                                    \
     V(ENGINE)                                                                 \
     V(OCSP)                                                                   \
     V(UI)                                                                     \
     V(COMP)                                                                   \
     V(ECDSA)                                                                  \
     V(ECDH)                                                                   \
-    V(OSSL_STORE)                                                             \
-    V(FIPS)                                                                   \
-    V(CMS)                                                                    \
-    V(TS)                                                                     \
     V(HMAC)                                                                   \
-    V(CT)                                                                     \
-    V(ASYNC)                                                                  \
-    V(KDF)                                                                    \
-    V(SM2)                                                                    \
     V(USER)                                                                   \
 
 #define V(name) case ERR_LIB_##name: lib = #name "_"; break;
@@ -2487,8 +2477,11 @@ void SSLWrap<Base>::GetEphemeralKeyInfo(
             .Check();
         break;
       case EVP_PKEY_EC:
+      // FIXME(zcbenz): This is not available in BoringSSL.
+#ifndef OPENSSL_IS_BORINGSSL
       case EVP_PKEY_X25519:
       case EVP_PKEY_X448:
+#endif
         {
           const char* curve_name;
           if (kid == EVP_PKEY_EC) {
@@ -3742,12 +3735,15 @@ Local<Value> KeyObject::GetAsymmetricKeyType() const {
     return env()->crypto_ec_string();
   case EVP_PKEY_ED25519:
     return env()->crypto_ed25519_string();
+  // FIXME(zcbenz): This is not available in BoringSSL.
+#ifndef OPENSSL_IS_BORINGSSL
   case EVP_PKEY_ED448:
     return env()->crypto_ed448_string();
   case EVP_PKEY_X25519:
     return env()->crypto_x25519_string();
   case EVP_PKEY_X448:
     return env()->crypto_x448_string();
+#endif
   default:
     return Undefined(env()->isolate());
   }
@@ -6240,6 +6236,8 @@ class DSAKeyPairGenerationConfig : public KeyPairGenerationConfig {
     if (EVP_PKEY_paramgen_init(param_ctx.get()) <= 0)
       return nullptr;
 
+    // FIXME(zcbenz): This is not available in BoringSSL.
+#ifndef OPENSSL_IS_BORINGSSL
     if (EVP_PKEY_CTX_set_dsa_paramgen_bits(param_ctx.get(), modulus_bits_) <= 0)
       return nullptr;
 
@@ -6259,6 +6257,8 @@ class DSAKeyPairGenerationConfig : public KeyPairGenerationConfig {
 
     EVPKeyCtxPointer key_ctx(EVP_PKEY_CTX_new(params.get(), nullptr));
     return key_ctx;
+#endif
+    return nullptr;
   }
 
  private:
@@ -6950,9 +6950,12 @@ void Initialize(Local<Object> target,
   env->SetMethod(target, "generateKeyPairEC", GenerateKeyPairEC);
   env->SetMethod(target, "generateKeyPairNid", GenerateKeyPairNid);
   NODE_DEFINE_CONSTANT(target, EVP_PKEY_ED25519);
+  // FIXME(zcbenz): This is not available in BoringSSL.
+#ifndef OPENSSL_IS_BORINGSSL
   NODE_DEFINE_CONSTANT(target, EVP_PKEY_ED448);
   NODE_DEFINE_CONSTANT(target, EVP_PKEY_X25519);
   NODE_DEFINE_CONSTANT(target, EVP_PKEY_X448);
+#endif
   NODE_DEFINE_CONSTANT(target, OPENSSL_EC_NAMED_CURVE);
   NODE_DEFINE_CONSTANT(target, OPENSSL_EC_EXPLICIT_CURVE);
   NODE_DEFINE_CONSTANT(target, kKeyEncodingPKCS1);
