Blame SOURCES/0001-Remove-OpenSSL-1.0.2-features.patch

6261c9
From e7f1280d006dc5e50f0d3844b63b7c746ced3cb9 Mon Sep 17 00:00:00 2001
6261c9
From: Your Name <you@example.com>
6261c9
Date: Thu, 13 Sep 2018 13:55:29 +0000
6261c9
Subject: [PATCH 1/2] Rebase 10.1
6261c9
6261c9
---
6261c9
 src/node_constants.cc                              |  12 +-
6261c9
 src/node_crypto.cc                                 | 294 ++++++++++++++++++---
6261c9
 src/node_crypto.h                                  |   2 +
6261c9
 .../test-tls-client-getephemeralkeyinfo.js         |   6 +-
6261c9
 4 files changed, 271 insertions(+), 43 deletions(-)
6261c9
6261c9
diff --git a/src/node_constants.cc b/src/node_constants.cc
6261c9
index b6c7bf3..28ca346 100644
6261c9
--- a/src/node_constants.cc
6261c9
+++ b/src/node_constants.cc
6261c9
@@ -951,8 +951,12 @@ void DefineOpenSSLConstants(Local<Object> target) {
6261c9
     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_RAND);
6261c9
 # endif
6261c9
 
6261c9
-# ifdef ENGINE_METHOD_EC
6261c9
-    NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_EC);
6261c9
+# ifdef ENGINE_METHOD_ECDH
6261c9
+    NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_ECDH);
6261c9
+# endif
6261c9
+
6261c9
+# ifdef ENGINE_METHOD_ECDSA
6261c9
+    NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_ECDSA);
6261c9
 # endif
6261c9
 
6261c9
 # ifdef ENGINE_METHOD_CIPHERS
6261c9
@@ -963,6 +967,10 @@ void DefineOpenSSLConstants(Local<Object> target) {
6261c9
     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_DIGESTS);
6261c9
 # endif
6261c9
 
6261c9
+# ifdef ENGINE_METHOD_STORE
6261c9
+    NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_STORE);
6261c9
+# endif
6261c9
+
6261c9
 # ifdef ENGINE_METHOD_PKEY_METHS
6261c9
     NODE_DEFINE_CONSTANT(target, ENGINE_METHOD_PKEY_METHS);
6261c9
 # endif
6261c9
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
6261c9
index 203d6b4..7bdb1b1 100644
6261c9
--- a/src/node_crypto.cc
6261c9
+++ b/src/node_crypto.cc
6261c9
@@ -109,6 +109,119 @@ struct OpenSSLBufferDeleter {
6261c9
 };
6261c9
 using OpenSSLBuffer = std::unique_ptr<char[], OpenSSLBufferDeleter>;
6261c9
 
6261c9
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
6261c9
+static void RSA_get0_key(const RSA* r, const BIGNUM** n, const BIGNUM** e,
6261c9
+                         const BIGNUM** d) {
6261c9
+  if (n != nullptr) {
6261c9
+    *n = r->n;
6261c9
+  }
6261c9
+  if (e != nullptr) {
6261c9
+    *e = r->e;
6261c9
+  }
6261c9
+  if (d != nullptr) {
6261c9
+    *d = r->d;
6261c9
+  }
6261c9
+}
6261c9
+
6261c9
+static void DH_get0_pqg(const DH* dh, const BIGNUM** p, const BIGNUM** q,
6261c9
+                        const BIGNUM** g) {
6261c9
+  if (p != nullptr) {
6261c9
+    *p = dh->p;
6261c9
+  }
6261c9
+  if (q != nullptr) {
6261c9
+    *q = dh->q;
6261c9
+  }
6261c9
+  if (g != nullptr) {
6261c9
+    *g = dh->g;
6261c9
+  }
6261c9
+}
6261c9
+
6261c9
+static int DH_set0_pqg(DH* dh, BIGNUM* p, BIGNUM* q, BIGNUM* g) {
6261c9
+  if ((dh->p == nullptr && p == nullptr) ||
6261c9
+      (dh->g == nullptr && g == nullptr)) {
6261c9
+    return 0;
6261c9
+  }
6261c9
+
6261c9
+  if (p != nullptr) {
6261c9
+    BN_free(dh->p);
6261c9
+    dh->p = p;
6261c9
+  }
6261c9
+  if (q != nullptr) {
6261c9
+    BN_free(dh->q);
6261c9
+    dh->q = q;
6261c9
+  }
6261c9
+  if (g != nullptr) {
6261c9
+    BN_free(dh->g);
6261c9
+    dh->g = g;
6261c9
+  }
6261c9
+
6261c9
+  return 1;
6261c9
+}
6261c9
+
6261c9
+static void DH_get0_key(const DH* dh, const BIGNUM** pub_key,
6261c9
+                        const BIGNUM** priv_key) {
6261c9
+  if (pub_key != nullptr) {
6261c9
+    *pub_key = dh->pub_key;
6261c9
+  }
6261c9
+  if (priv_key != nullptr) {
6261c9
+    *priv_key = dh->priv_key;
6261c9
+  }
6261c9
+}
6261c9
+
6261c9
+static int DH_set0_key(DH* dh, BIGNUM* pub_key, BIGNUM* priv_key) {
6261c9
+  if (pub_key != nullptr) {
6261c9
+    BN_free(dh->pub_key);
6261c9
+    dh->pub_key = pub_key;
6261c9
+  }
6261c9
+  if (priv_key != nullptr) {
6261c9
+    BN_free(dh->priv_key);
6261c9
+    dh->priv_key = priv_key;
6261c9
+  }
6261c9
+
6261c9
+  return 1;
6261c9
+}
6261c9
+
6261c9
+static const SSL_METHOD* TLS_method() { return SSLv23_method(); }
6261c9
+
6261c9
+static void SSL_SESSION_get0_ticket(const SSL_SESSION* s,
6261c9
+                                    const unsigned char** tick, size_t* len) {
6261c9
+  *len = s->tlsext_ticklen;
6261c9
+  if (tick != nullptr) {
6261c9
+    *tick = s->tlsext_tick;
6261c9
+  }
6261c9
+}
6261c9
+
6261c9
+#define SSL_get_tlsext_status_type(ssl) (ssl->tlsext_status_type)
6261c9
+
6261c9
+static int X509_STORE_up_ref(X509_STORE* store) {
6261c9
+  CRYPTO_add(&store->references, 1, CRYPTO_LOCK_X509_STORE);
6261c9
+  return 1;
6261c9
+}
6261c9
+
6261c9
+static int X509_up_ref(X509* cert) {
6261c9
+  CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
6261c9
+  return 1;
6261c9
+}
6261c9
+
6261c9
+#define EVP_MD_CTX_new EVP_MD_CTX_create
6261c9
+#define EVP_MD_CTX_free EVP_MD_CTX_destroy
6261c9
+
6261c9
+HMAC_CTX* HMAC_CTX_new() {
6261c9
+  HMAC_CTX* ctx = Malloc<HMAC_CTX>(1);
6261c9
+  HMAC_CTX_init(ctx);
6261c9
+  return ctx;
6261c9
+}
6261c9
+
6261c9
+void HMAC_CTX_free(HMAC_CTX* ctx) {
6261c9
+  if (ctx == nullptr) {
6261c9
+    return;
6261c9
+  }
6261c9
+  HMAC_CTX_cleanup(ctx);
6261c9
+  free(ctx);
6261c9
+}
6261c9
+#endif  // OPENSSL_VERSION_NUMBER < 0x10100000L
6261c9
+
6261c9
+
6261c9
 static const char* const root_certs[] = {
6261c9
 #include "node_root_certs.h"  // NOLINT(build/include_order)
6261c9
 };
6261c9
@@ -125,11 +238,19 @@ template void SSLWrap<TLSWrap>::AddMethods(Environment* env,
6261c9
 template void SSLWrap<TLSWrap>::ConfigureSecureContext(SecureContext* sc);
6261c9
 template void SSLWrap<TLSWrap>::SetSNIContext(SecureContext* sc);
6261c9
 template int SSLWrap<TLSWrap>::SetCACerts(SecureContext* sc);
6261c9
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
6261c9
+template SSL_SESSION* SSLWrap<TLSWrap>::GetSessionCallback(
6261c9
+    SSL* s,
6261c9
+    unsigned char* key,
6261c9
+    int len,
6261c9
+    int* copy);
6261c9
+#else
6261c9
 template SSL_SESSION* SSLWrap<TLSWrap>::GetSessionCallback(
6261c9
     SSL* s,
6261c9
     const unsigned char* key,
6261c9
     int len,
6261c9
     int* copy);
6261c9
+#endif
6261c9
 template int SSLWrap<TLSWrap>::NewSessionCallback(SSL* s,
6261c9
                                                   SSL_SESSION* sess);
6261c9
 template void SSLWrap<TLSWrap>::OnClientHello(
6261c9
@@ -148,6 +269,34 @@ template int SSLWrap<TLSWrap>::SelectALPNCallback(
6261c9
     void* arg);
6261c9
 
6261c9
 
6261c9
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
6261c9
+static Mutex* mutexes;
6261c9
+
6261c9
+static void crypto_threadid_cb(CRYPTO_THREADID* tid) {
6261c9
+  static_assert(sizeof(uv_thread_t) <= sizeof(void*),
6261c9
+                "uv_thread_t does not fit in a pointer");
6261c9
+  CRYPTO_THREADID_set_pointer(tid, reinterpret_cast<void*>(uv_thread_self()));
6261c9
+}
6261c9
+
6261c9
+
6261c9
+static void crypto_lock_init(void) {
6261c9
+  mutexes = new Mutex[CRYPTO_num_locks()];
6261c9
+}
6261c9
+
6261c9
+
6261c9
+static void crypto_lock_cb(int mode, int n, const char* file, int line) {
6261c9
+  CHECK(!(mode & CRYPTO_LOCK) ^ !(mode & CRYPTO_UNLOCK));
6261c9
+  CHECK(!(mode & CRYPTO_READ) ^ !(mode & CRYPTO_WRITE));
6261c9
+
6261c9
+  auto mutex = &mutexes[n];
6261c9
+  if (mode & CRYPTO_LOCK)
6261c9
+    mutex->Lock();
6261c9
+  else
6261c9
+    mutex->Unlock();
6261c9
+}
6261c9
+#endif
6261c9
+
6261c9
+
6261c9
 static int PasswordCallback(char* buf, int size, int rwflag, void* u) {
6261c9
   if (u) {
6261c9
     size_t buflen = static_cast<size_t>(size);
6261c9
@@ -381,8 +530,8 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
6261c9
   ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());
6261c9
   Environment* env = sc->env();
6261c9
 
6261c9
-  int min_version = 0;
6261c9
-  int max_version = 0;
6261c9
+  // int min_version = 0;
6261c9
+  // int max_version = 0;
6261c9
   const SSL_METHOD* method = TLS_method();
6261c9
 
6261c9
   if (args.Length() == 1 && args[0]->IsString()) {
6261c9
@@ -405,47 +554,47 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
6261c9
     } else if (strcmp(*sslmethod, "SSLv3_client_method") == 0) {
6261c9
       return env->ThrowError("SSLv3 methods disabled");
6261c9
     } else if (strcmp(*sslmethod, "SSLv23_method") == 0) {
6261c9
-      method = TLS_method();
6261c9
+      method = SSLv23_method();
6261c9
     } else if (strcmp(*sslmethod, "SSLv23_server_method") == 0) {
6261c9
-      method = TLS_server_method();
6261c9
+      method = SSLv23_server_method();
6261c9
     } else if (strcmp(*sslmethod, "SSLv23_client_method") == 0) {
6261c9
-      method = TLS_client_method();
6261c9
+      method = SSLv23_client_method();
6261c9
     } else if (strcmp(*sslmethod, "TLSv1_method") == 0) {
6261c9
-      min_version = TLS1_VERSION;
6261c9
-      max_version = TLS1_VERSION;
6261c9
-      method = TLS_method();
6261c9
+      // min_version = TLS1_VERSION;
6261c9
+      // max_version = TLS1_VERSION;
6261c9
+      method = TLSv1_method();
6261c9
     } else if (strcmp(*sslmethod, "TLSv1_server_method") == 0) {
6261c9
-      min_version = TLS1_VERSION;
6261c9
-      max_version = TLS1_VERSION;
6261c9
-      method = TLS_server_method();
6261c9
+      // min_version = TLS1_VERSION;
6261c9
+      // max_version = TLS1_VERSION;
6261c9
+      method = TLSv1_server_method();
6261c9
     } else if (strcmp(*sslmethod, "TLSv1_client_method") == 0) {
6261c9
-      min_version = TLS1_VERSION;
6261c9
-      max_version = TLS1_VERSION;
6261c9
-      method = TLS_client_method();
6261c9
+      // min_version = TLS1_VERSION;
6261c9
+      // max_version = TLS1_VERSION;
6261c9
+      method = TLSv1_client_method();
6261c9
     } else if (strcmp(*sslmethod, "TLSv1_1_method") == 0) {
6261c9
-      min_version = TLS1_1_VERSION;
6261c9
-      max_version = TLS1_1_VERSION;
6261c9
-      method = TLS_method();
6261c9
+      // min_version = TLS1_1_VERSION;
6261c9
+      // max_version = TLS1_1_VERSION;
6261c9
+      method = TLSv1_1_method();
6261c9
     } else if (strcmp(*sslmethod, "TLSv1_1_server_method") == 0) {
6261c9
-      min_version = TLS1_1_VERSION;
6261c9
-      max_version = TLS1_1_VERSION;
6261c9
-      method = TLS_server_method();
6261c9
+      // min_version = TLS1_1_VERSION;
6261c9
+      // max_version = TLS1_1_VERSION;
6261c9
+      method = TLSv1_1_server_method();
6261c9
     } else if (strcmp(*sslmethod, "TLSv1_1_client_method") == 0) {
6261c9
-      min_version = TLS1_1_VERSION;
6261c9
-      max_version = TLS1_1_VERSION;
6261c9
-      method = TLS_client_method();
6261c9
+      // min_version = TLS1_1_VERSION;
6261c9
+      // max_version = TLS1_1_VERSION;
6261c9
+      method = TLSv1_1_client_method();
6261c9
     } else if (strcmp(*sslmethod, "TLSv1_2_method") == 0) {
6261c9
-      min_version = TLS1_2_VERSION;
6261c9
-      max_version = TLS1_2_VERSION;
6261c9
-      method = TLS_method();
6261c9
+      // min_version = TLS1_2_VERSION;
6261c9
+      // max_version = TLS1_2_VERSION;
6261c9
+      method = TLSv1_2_method();
6261c9
     } else if (strcmp(*sslmethod, "TLSv1_2_server_method") == 0) {
6261c9
-      min_version = TLS1_2_VERSION;
6261c9
-      max_version = TLS1_2_VERSION;
6261c9
-      method = TLS_server_method();
6261c9
+      // min_version = TLS1_2_VERSION;
6261c9
+      // max_version = TLS1_2_VERSION;
6261c9
+      method = TLSv1_2_server_method();
6261c9
     } else if (strcmp(*sslmethod, "TLSv1_2_client_method") == 0) {
6261c9
-      min_version = TLS1_2_VERSION;
6261c9
-      max_version = TLS1_2_VERSION;
6261c9
-      method = TLS_client_method();
6261c9
+      // min_version = TLS1_2_VERSION;
6261c9
+      // max_version = TLS1_2_VERSION;
6261c9
+      method = TLSv1_2_client_method();
6261c9
     } else {
6261c9
       return env->ThrowError("Unknown method");
6261c9
     }
6261c9
@@ -467,6 +616,7 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
6261c9
                                  SSL_SESS_CACHE_NO_INTERNAL |
6261c9
                                  SSL_SESS_CACHE_NO_AUTO_CLEAR);
6261c9
 
6261c9
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
6261c9
   SSL_CTX_set_min_proto_version(sc->ctx_.get(), min_version);
6261c9
   SSL_CTX_set_max_proto_version(sc->ctx_.get(), max_version);
6261c9
   // OpenSSL 1.1.0 changed the ticket key size, but the OpenSSL 1.0.x size was
6261c9
@@ -478,6 +628,7 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
6261c9
     return env->ThrowError("Error generating ticket keys");
6261c9
   }
6261c9
   SSL_CTX_set_tlsext_ticket_key_cb(sc->ctx_.get(), TicketCompatibilityCallback);
6261c9
+#endif
6261c9
 }
6261c9
 
6261c9
 
6261c9
@@ -925,6 +1076,11 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo<Value>& args) {
6261c9
 
6261c9
   node::Utf8Value curve(env->isolate(), args[0]);
6261c9
 
6261c9
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
6261c9
+  SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_ECDH_USE);
6261c9
+  SSL_CTX_set_ecdh_auto(sc->ctx_, 1);
6261c9
+#endif
6261c9
+
6261c9
   if (strcmp(*curve, "auto") == 0)
6261c9
     return;
6261c9
 
6261c9
@@ -1179,9 +1335,17 @@ void SecureContext::GetTicketKeys(const FunctionCallbackInfo<Value>& args) {
6261c9
   ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
6261c9
 
6261c9
   Local<Object> buff = Buffer::New(wrap->env(), 48).ToLocalChecked();
6261c9
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
6261c9
   memcpy(Buffer::Data(buff), wrap->ticket_key_name_, 16);
6261c9
   memcpy(Buffer::Data(buff) + 16, wrap->ticket_key_hmac_, 16);
6261c9
   memcpy(Buffer::Data(buff) + 32, wrap->ticket_key_aes_, 16);
6261c9
+#else
6261c9
+  if (SSL_CTX_get_tlsext_ticket_keys(wrap->ctx_,
6261c9
+                                     Buffer::Data(buff),
6261c9
+                                     Buffer::Length(buff)) != 1) {
6261c9
+    return wrap->env()->ThrowError("Failed to fetch tls ticket keys");
6261c9
+  }
6261c9
+#endif
6261c9
 
6261c9
   args.GetReturnValue().Set(buff);
6261c9
 #endif  // !def(OPENSSL_NO_TLSEXT) && def(SSL_CTX_get_tlsext_ticket_keys)
6261c9
@@ -1205,9 +1369,17 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
6261c9
         env, "Ticket keys length must be 48 bytes");
6261c9
   }
6261c9
 
6261c9
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
6261c9
   memcpy(wrap->ticket_key_name_, Buffer::Data(args[0]), 16);
6261c9
   memcpy(wrap->ticket_key_hmac_, Buffer::Data(args[0]) + 16, 16);
6261c9
   memcpy(wrap->ticket_key_aes_, Buffer::Data(args[0]) + 32, 16);
6261c9
+#else
6261c9
+  if (SSL_CTX_set_tlsext_ticket_keys(wrap->ctx_,
6261c9
+                                     Buffer::Data(args[0]),
6261c9
+                                     Buffer::Length(args[0])) != 1) {
6261c9
+    return env->ThrowError("Failed to fetch tls ticket keys");
6261c9
+  }
6261c9
+#endif
6261c9
 
6261c9
   args.GetReturnValue().Set(true);
6261c9
 #endif  // !def(OPENSSL_NO_TLSEXT) && def(SSL_CTX_get_tlsext_ticket_keys)
6261c9
@@ -1215,6 +1387,14 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
6261c9
 
6261c9
 
6261c9
 void SecureContext::SetFreeListLength(const FunctionCallbackInfo<Value>& args) {
6261c9
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
6261c9
+  // |freelist_max_len| was removed in OpenSSL 1.1.0. In that version OpenSSL
6261c9
+  // mallocs and frees buffers directly, without the use of a freelist.
6261c9
+  SecureContext* wrap;
6261c9
+  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
6261c9
+
6261c9
+  wrap->ctx_->freelist_max_len = args[0]->Int32Value();
6261c9
+#endif
6261c9
 }
6261c9
 
6261c9
 
6261c9
@@ -1311,6 +1491,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
6261c9
 }
6261c9
 
6261c9
 
6261c9
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
6261c9
 int SecureContext::TicketCompatibilityCallback(SSL* ssl,
6261c9
                                                unsigned char* name,
6261c9
                                                unsigned char* iv,
6261c9
@@ -1345,6 +1526,7 @@ int SecureContext::TicketCompatibilityCallback(SSL* ssl,
6261c9
   }
6261c9
   return 1;
6261c9
 }
6261c9
+#endif
6261c9
 
6261c9
 
6261c9
 template <bool primary>
6261c9
@@ -1413,11 +1595,19 @@ void SSLWrap<Base>::ConfigureSecureContext(SecureContext* sc) {
6261c9
 }
6261c9
 
6261c9
 
6261c9
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
6261c9
+template <class Base>
6261c9
+SSL_SESSION* SSLWrap<Base>::GetSessionCallback(SSL* s,
6261c9
+                                               unsigned char* key,
6261c9
+                                               int len,
6261c9
+                                               int* copy) {
6261c9
+#else
6261c9
 template <class Base>
6261c9
 SSL_SESSION* SSLWrap<Base>::GetSessionCallback(SSL* s,
6261c9
                                                const unsigned char* key,
6261c9
                                                int len,
6261c9
                                                int* copy) {
6261c9
+#endif
6261c9
   Base* w = static_cast<Base*>(SSL_get_app_data(s));
6261c9
 
6261c9
   *copy = 0;
6261c9
@@ -2077,6 +2267,7 @@ void SSLWrap<Base>::GetEphemeralKeyInfo(
6261c9
                   Integer::New(env->isolate(), EVP_PKEY_bits(key))).FromJust();
6261c9
         break;
6261c9
       case EVP_PKEY_EC:
6261c9
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
6261c9
       // TODO(shigeki) Change this to EVP_PKEY_X25519 and add EVP_PKEY_X448
6261c9
       // after upgrading to 1.1.1.
6261c9
       case NID_X25519:
6261c9
@@ -2097,9 +2288,24 @@ void SSLWrap<Base>::GetEphemeralKeyInfo(
6261c9
                                   curve_name)).FromJust();
6261c9
           info->Set(context, env->size_string(),
6261c9
                     Integer::New(env->isolate(),
6261c9
-                                 EVP_PKEY_bits(key))).FromJust();
6261c9
+                                  EVP_PKEY_bits(key))).FromJust();
6261c9
         }
6261c9
         break;
6261c9
+#else
6261c9
+        {
6261c9
+          EC_KEY* ec = EVP_PKEY_get1_EC_KEY(key);
6261c9
+          int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
6261c9
+          EC_KEY_free(ec);
6261c9
+          info->Set(context, env->type_string(),
6261c9
+                    FIXED_ONE_BYTE_STRING(env->isolate(), "ECDH")).FromJust();
6261c9
+          info->Set(context, env->name_string(),
6261c9
+                    OneByteString(args.GetIsolate(),
6261c9
+                                  OBJ_nid2sn(nid))).FromJust();
6261c9
+          info->Set(context, env->size_string(),
6261c9
+                    Integer::New(env->isolate(),
6261c9
+                                  EVP_PKEY_bits(key))).FromJust();
6261c9
+         }
6261c9
+#endif
6261c9
     }
6261c9
     EVP_PKEY_free(key);
6261c9
   }
6261c9
@@ -2778,10 +2984,10 @@ bool CipherBase::InitAuthenticated(const char* cipher_type, int iv_len,
6261c9
   CHECK(IsAuthenticatedMode());
6261c9
   MarkPopErrorOnReturn mark_pop_error_on_return;
6261c9
 
6261c9
-  if (!EVP_CIPHER_CTX_ctrl(ctx_.get(),
6261c9
-                           EVP_CTRL_AEAD_SET_IVLEN,
6261c9
-                           iv_len,
6261c9
-                           nullptr)) {
6261c9
+  // TODO(tniessen) Use EVP_CTRL_AEAD_SET_IVLEN when migrating to OpenSSL 1.1.0
6261c9
+  static_assert(EVP_CTRL_CCM_SET_IVLEN == EVP_CTRL_GCM_SET_IVLEN,
6261c9
+                "OpenSSL constants differ between GCM and CCM");
6261c9
+  if (!EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_GCM_SET_IVLEN, iv_len, nullptr)) {
6261c9
     env()->ThrowError("Invalid IV length");
6261c9
     return false;
6261c9
   }
6261c9
@@ -3137,8 +3343,10 @@ bool CipherBase::Final(unsigned char** out, int* out_len) {
6261c9
         CHECK(mode == EVP_CIPH_GCM_MODE);
6261c9
         auth_tag_len_ = sizeof(auth_tag_);
6261c9
       }
6261c9
-      CHECK_EQ(1, EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_GET_TAG,
6261c9
-                      auth_tag_len_,
6261c9
+      // TOOD(tniessen) Use EVP_CTRL_AEAP_GET_TAG in OpenSSL 1.1.0
6261c9
+      static_assert(EVP_CTRL_CCM_GET_TAG == EVP_CTRL_GCM_GET_TAG,
6261c9
+                    "OpenSSL constants differ between GCM and CCM");
6261c9
+      CHECK_EQ(1, EVP_CIPHER_CTX_ctrl(ctx_, EVP_CTRL_GCM_GET_TAG, auth_tag_len_,
6261c9
                       reinterpret_cast<unsigned char*>(auth_tag_)));
6261c9
     }
6261c9
   }
6261c9
@@ -3414,12 +3622,14 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
6261c9
 
6261c9
 SignBase::Error SignBase::Init(const char* sign_type) {
6261c9
   CHECK_NULL(mdctx_);
6261c9
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
6261c9
   // Historically, "dss1" and "DSS1" were DSA aliases for SHA-1
6261c9
   // exposed through the public API.
6261c9
   if (strcmp(sign_type, "dss1") == 0 ||
6261c9
       strcmp(sign_type, "DSS1") == 0) {
6261c9
     sign_type = "SHA1";
6261c9
   }
6261c9
+#endif
6261c9
   const EVP_MD* md = EVP_get_digestbyname(sign_type);
6261c9
   if (md == nullptr)
6261c9
     return kSignUnknownDigest;
6261c9
@@ -5124,6 +5334,12 @@ void InitCryptoOnce() {
6261c9
   SSL_library_init();
6261c9
   OpenSSL_add_all_algorithms();
6261c9
 
6261c9
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
6261c9
+  crypto_lock_init();
6261c9
+  CRYPTO_set_locking_callback(crypto_lock_cb);
6261c9
+  CRYPTO_THREADID_set_callback(crypto_threadid_cb);
6261c9
+#endif
6261c9
+
6261c9
 #ifdef NODE_FIPS_MODE
6261c9
   /* Override FIPS settings in cnf file, if needed. */
6261c9
   unsigned long err = 0;  // NOLINT(runtime/int)
6261c9
diff --git a/src/node_crypto.h b/src/node_crypto.h
6261c9
index 86aa3ba..e850358 100644
6261c9
--- a/src/node_crypto.h
6261c9
+++ b/src/node_crypto.h
6261c9
@@ -44,8 +44,10 @@
6261c9
 #endif  // !OPENSSL_NO_ENGINE
6261c9
 #include <openssl/err.h>
6261c9
 #include <openssl/evp.h>
6261c9
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
6261c9
 // TODO(shigeki) Remove this after upgrading to 1.1.1
6261c9
 #include <openssl/obj_mac.h>
6261c9
+#endif
6261c9
 #include <openssl/pem.h>
6261c9
 #include <openssl/x509.h>
6261c9
 #include <openssl/x509v3.h>
6261c9
diff --git a/test/parallel/test-tls-client-getephemeralkeyinfo.js b/test/parallel/test-tls-client-getephemeralkeyinfo.js
6261c9
index 9432a27..411fdc7 100644
6261c9
--- a/test/parallel/test-tls-client-getephemeralkeyinfo.js
6261c9
+++ b/test/parallel/test-tls-client-getephemeralkeyinfo.js
6261c9
@@ -82,18 +82,20 @@ function testECDHE256() {
6261c9
 }
6261c9
 
6261c9
 function testECDHE512() {
6261c9
-  test(521, 'ECDH', 'secp521r1', testX25519);
6261c9
+  test(521, 'ECDH', 'secp521r1', null);
6261c9
   ntests++;
6261c9
 }
6261c9
 
6261c9
+/*
6261c9
 function testX25519() {
6261c9
   test(253, 'ECDH', 'X25519', null);
6261c9
   ntests++;
6261c9
 }
6261c9
+*/
6261c9
 
6261c9
 testNOT_PFS();
6261c9
 
6261c9
 process.on('exit', function() {
6261c9
   assert.strictEqual(ntests, nsuccess);
6261c9
-  assert.strictEqual(ntests, 6);
6261c9
+  assert.strictEqual(ntests, 5);
6261c9
 });
6261c9
-- 
6261c9
1.8.3.1
6261c9