Blame SOURCES/0004-Disable-unsupported-OpenSSL-features.patch

f0ceb1
From e7e0a4fc073b3d17fcdee6cebea74f1aae4e6f69 Mon Sep 17 00:00:00 2001
3f476a
From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= <jstanek@redhat.com>
f0ceb1
Date: Wed, 7 Jul 2021 13:37:48 +0200
3f476a
Subject: [PATCH] Disable unsupported OpenSSL features
3f476a
MIME-Version: 1.0
3f476a
Content-Type: text/plain; charset=UTF-8
3f476a
Content-Transfer-Encoding: 8bit
3f476a
3f476a
- Disable no-certificate PSK authentication
3f476a
3f476a
  There is no obvious way to reimplement it using only OpenSSL 1.0 public APIs.
3f476a
3f476a
- Disable queries for standard cipher name
3f476a
3f476a
  OpenSSL 1.0 does not record said names.
3f476a
3f476a
- Remove ClientHello getters
3f476a
3f476a
  The disabled functions internally use
3f476a
  `SSL_client_hello_get0_ext`/`SSL_client_hello_get0_ciphers`,
3f476a
  which are not available on legacy OpenSSL.
3f476a
  There may be another way to get to the same data,
3f476a
  but nothing jumps out in the OpenSSL 1.0.2 documentation.
3f476a
3f476a
- Remove TLSv1.3 CLI options
3f476a
3f476a
Signed-off-by: Jan Staněk <jstanek@redhat.com>
3f476a
---
3f476a
 doc/api/cli.md                                 | 18 ------------------
3f476a
 doc/api/tls.md                                 | 15 +++++++--------
3f476a
 src/env.h                                      | 11 ++++++++++-
3f476a
 src/node_crypto_common.cc                      | 12 ++++++++++++
3f476a
 src/node_crypto_common.h                       |  6 ++++++
3f476a
 src/node_options.cc                            | 10 +++++++++-
3f476a
 .../test-tls-cli-max-version-1.3.js            |  0
3f476a
 .../test-tls-cli-min-max-conflict.js           |  0
3f476a
 .../test-tls-cli-min-version-1.3.js            |  0
3f476a
 9 files changed, 44 insertions(+), 28 deletions(-)
3f476a
 rename test/{parallel => known_issues}/test-tls-cli-max-version-1.3.js (100%)
3f476a
 rename test/{parallel => known_issues}/test-tls-cli-min-max-conflict.js (100%)
3f476a
 rename test/{parallel => known_issues}/test-tls-cli-min-version-1.3.js (100%)
3f476a
3f476a
diff --git a/doc/api/cli.md b/doc/api/cli.md
f0ceb1
index 6e0702498a..a8ef339430 100644
3f476a
--- a/doc/api/cli.md
3f476a
+++ b/doc/api/cli.md
f0ceb1
@@ -813,14 +813,6 @@ added:
3f476a
 Set [`tls.DEFAULT_MAX_VERSION`][] to 'TLSv1.2'. Use to disable support for
3f476a
 TLSv1.3.
3f476a
 
3f476a
-### `--tls-max-v1.3`
3f476a
-
3f476a
-added: v12.0.0
3f476a
--->
3f476a
-
3f476a
-Set default [`tls.DEFAULT_MAX_VERSION`][] to 'TLSv1.3'. Use to enable support
3f476a
-for TLSv1.3.
3f476a
-
3f476a
 ### `--tls-min-v1.0`
3f476a
 
3f476a
 added:
f0ceb1
@@ -852,14 +844,6 @@ Set default [`tls.DEFAULT_MIN_VERSION`][] to 'TLSv1.2'. This is the default for
3f476a
 12.x and later, but the option is supported for compatibility with older Node.js
3f476a
 versions.
3f476a
 
3f476a
-### `--tls-min-v1.3`
3f476a
-
3f476a
-added: v12.0.0
3f476a
--->
3f476a
-
3f476a
-Set default [`tls.DEFAULT_MIN_VERSION`][] to 'TLSv1.3'. Use to disable support
3f476a
-for TLSv1.2, which is not as secure as TLSv1.3.
3f476a
-
3f476a
 ### `--trace-atomics-wait`
3f476a
 
3f476a
 added: v14.3.0
f0ceb1
@@ -1298,11 +1282,9 @@ Node.js options that are allowed are:
3f476a
 * `--tls-cipher-list`
3f476a
 * `--tls-keylog`
3f476a
 * `--tls-max-v1.2`
3f476a
-* `--tls-max-v1.3`
3f476a
 * `--tls-min-v1.0`
3f476a
 * `--tls-min-v1.1`
3f476a
 * `--tls-min-v1.2`
3f476a
-* `--tls-min-v1.3`
3f476a
 * `--trace-atomics-wait`
3f476a
 * `--trace-deprecation`
3f476a
 * `--trace-event-categories`
3f476a
diff --git a/doc/api/tls.md b/doc/api/tls.md
f0ceb1
index 055ba472b5..f286e9f7ee 100644
3f476a
--- a/doc/api/tls.md
3f476a
+++ b/doc/api/tls.md
f0ceb1
@@ -1970,10 +1970,10 @@ added: v11.4.0
3f476a
 
3f476a
 * {string} The default value of the `maxVersion` option of
3f476a
   [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS
3f476a
-  protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`.
3f476a
-  **Default:** `'TLSv1.3'`, unless changed using CLI options. Using
3f476a
-  `--tls-max-v1.2` sets the default to `'TLSv1.2'`. Using `--tls-max-v1.3` sets
3f476a
-  the default to `'TLSv1.3'`. If multiple of the options are provided, the
3f476a
+  protocol versions, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`.
3f476a
+  **Default:** `'TLSv1.2'`, unless changed using CLI options. Using
3f476a
+  `--tls-max-v1.2` sets the default to `'TLSv1.2'`.
3f476a
+  If multiple of the options are provided, the
3f476a
   highest maximum is used.
3f476a
 
3f476a
 ## `tls.DEFAULT_MIN_VERSION`
f0ceb1
@@ -1983,12 +1983,11 @@ added: v11.4.0
3f476a
 
3f476a
 * {string} The default value of the `minVersion` option of
3f476a
   [`tls.createSecureContext()`][]. It can be assigned any of the supported TLS
3f476a
-  protocol versions, `'TLSv1.3'`, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`.
3f476a
+  protocol versions, `'TLSv1.2'`, `'TLSv1.1'`, or `'TLSv1'`.
3f476a
   **Default:** `'TLSv1.2'`, unless changed using CLI options. Using
3f476a
   `--tls-min-v1.0` sets the default to `'TLSv1'`. Using `--tls-min-v1.1` sets
3f476a
-  the default to `'TLSv1.1'`. Using `--tls-min-v1.3` sets the default to
3f476a
-  `'TLSv1.3'`. If multiple of the options are provided, the lowest minimum is
3f476a
-  used.
3f476a
+  the default to `'TLSv1.1'`. If multiple of the options are provided,
3f476a
+  the lowest minimum is used.
3f476a
 
3f476a
 [Chrome's 'modern cryptography' setting]: https://www.chromium.org/Home/chromium-security/education/tls#TOC-Cipher-Suites
3f476a
 [DHE]: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
3f476a
diff --git a/src/env.h b/src/env.h
f0ceb1
index 1e930170bc..d990212241 100644
3f476a
--- a/src/env.h
3f476a
+++ b/src/env.h
3f476a
@@ -50,6 +50,8 @@
3f476a
 #include <unordered_set>
3f476a
 #include <vector>
3f476a
 
3f476a
+#include <node-ssl-shim/ssl-shim.h>
3f476a
+
3f476a
 namespace node {
3f476a
 
3f476a
 namespace contextify {
3f476a
@@ -141,6 +143,13 @@ constexpr size_t kFsStatsBufferLength =
3f476a
 // Make sure that any macro V defined for use with the PER_ISOLATE_* macros is
3f476a
 // undefined again after use.
3f476a
 
3f476a
+// Some symbols/strings are not defined when using legacy OpenSSL
3f476a
+#if OPENSSL_IS_LEGACY
3f476a
+#   define NODE_ENV_STANDARD_NAME_STRING
3f476a
+#else // OPENSSL_IS_LEGACY
3f476a
+#   define NODE_ENV_STANDARD_NAME_STRING V(standard_name_string, "standardName")
3f476a
+#endif // OPENSSL_IS_LEGACY
3f476a
+
3f476a
 // Private symbols are per-isolate primitives but Environment proxies them
3f476a
 // for the sake of convenience.  Strings should be ASCII-only and have a
3f476a
 // "node:" prefix to avoid name clashes with third-party code.
f0ceb1
@@ -363,7 +372,7 @@ constexpr size_t kFsStatsBufferLength =
3f476a
   V(sni_context_string, "sni_context")                                         \
3f476a
   V(source_string, "source")                                                   \
3f476a
   V(stack_string, "stack")                                                     \
3f476a
-  V(standard_name_string, "standardName")                                      \
3f476a
+  NODE_ENV_STANDARD_NAME_STRING                                                \
3f476a
   V(start_time_string, "startTime")                                            \
3f476a
   V(status_string, "status")                                                   \
3f476a
   V(stdio_string, "stdio")                                                     \
3f476a
diff --git a/src/node_crypto_common.cc b/src/node_crypto_common.cc
3f476a
index da1033fdef..89f01990f0 100644
3f476a
--- a/src/node_crypto_common.cc
3f476a
+++ b/src/node_crypto_common.cc
3f476a
@@ -211,6 +211,7 @@ long VerifyPeerCertificate(  // NOLINT(runtime/int)
3f476a
   if (X509* peer_cert = SSL_get_peer_certificate(ssl.get())) {
3f476a
     X509_free(peer_cert);
3f476a
     err = SSL_get_verify_result(ssl.get());
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
   } else {
3f476a
     const SSL_CIPHER* curr_cipher = SSL_get_current_cipher(ssl.get());
3f476a
     const SSL_SESSION* sess = SSL_get_session(ssl.get());
3f476a
@@ -222,6 +223,7 @@ long VerifyPeerCertificate(  // NOLINT(runtime/int)
3f476a
          SSL_session_reused(ssl.get()))) {
3f476a
       return X509_V_OK;
3f476a
     }
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
   }
3f476a
   return err;
3f476a
 }
3f476a
@@ -239,6 +241,7 @@ int UseSNIContext(const SSLPointer& ssl, BaseObjectPtr<SecureContext> context) {
3f476a
   return err;
3f476a
 }
3f476a
 
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
 const char* GetClientHelloALPN(const SSLPointer& ssl) {
3f476a
   const unsigned char* buf;
3f476a
   size_t len;
3f476a
@@ -285,6 +288,7 @@ const char* GetClientHelloServerName(const SSLPointer& ssl) {
3f476a
     return nullptr;
3f476a
   return reinterpret_cast<const char*>(buf + 5);
3f476a
 }
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
 
3f476a
 const char* GetServerName(SSL* ssl) {
3f476a
   return SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
3f476a
@@ -398,11 +402,13 @@ MaybeLocal<Value> GetCipherName(Environment* env, const SSL_CIPHER* cipher) {
3f476a
   return GetCipherValue(env, cipher, SSL_CIPHER_get_name);
3f476a
 }
3f476a
 
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
 MaybeLocal<Value> GetCipherStandardName(
3f476a
     Environment* env,
3f476a
     const SSL_CIPHER* cipher) {
3f476a
   return GetCipherValue(env, cipher, SSL_CIPHER_standard_name);
3f476a
 }
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
 
3f476a
 MaybeLocal<Value> GetCipherVersion(Environment* env, const SSL_CIPHER* cipher) {
3f476a
 #if OPENSSL_IS_LEGACY
3f476a
@@ -762,16 +768,19 @@ MaybeLocal<Value> GetCipherName(Environment* env, const SSLPointer& ssl) {
3f476a
   return GetCipherName(env, SSL_get_current_cipher(ssl.get()));
3f476a
 }
3f476a
 
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
 MaybeLocal<Value> GetCipherStandardName(
3f476a
     Environment* env,
3f476a
     const SSLPointer& ssl) {
3f476a
   return GetCipherStandardName(env, SSL_get_current_cipher(ssl.get()));
3f476a
 }
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
 
3f476a
 MaybeLocal<Value> GetCipherVersion(Environment* env, const SSLPointer& ssl) {
3f476a
   return GetCipherVersion(env, SSL_get_current_cipher(ssl.get()));
3f476a
 }
3f476a
 
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
 MaybeLocal<Array> GetClientHelloCiphers(
3f476a
     Environment* env,
3f476a
     const SSLPointer& ssl) {
3f476a
@@ -804,6 +813,7 @@ MaybeLocal<Array> GetClientHelloCiphers(
3f476a
   Local<Array> ret = Array::New(env->isolate(), ciphers.out(), count);
3f476a
   return scope.Escape(ret);
3f476a
 }
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
 
3f476a
 
3f476a
 MaybeLocal<Object> GetCipherInfo(Environment* env, const SSLPointer& ssl) {
3f476a
@@ -814,10 +824,12 @@ MaybeLocal<Object> GetCipherInfo(Environment* env, const SSLPointer& ssl) {
3f476a
                   info,
3f476a
                   env->name_string(),
3f476a
                   GetCipherName(env, ssl)) ||
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
       !Set<Value>(env->context(),
3f476a
                   info,
3f476a
                   env->standard_name_string(),
3f476a
                   GetCipherStandardName(env, ssl)) ||
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
       !Set<Value>(env->context(),
3f476a
                   info,
3f476a
                   env->version_string(),
3f476a
diff --git a/src/node_crypto_common.h b/src/node_crypto_common.h
3f476a
index c373a97e47..220cb109bc 100644
3f476a
--- a/src/node_crypto_common.h
3f476a
+++ b/src/node_crypto_common.h
3f476a
@@ -73,15 +73,19 @@ long VerifyPeerCertificate(  // NOLINT(runtime/int)
3f476a
 
3f476a
 int UseSNIContext(const SSLPointer& ssl, BaseObjectPtr<SecureContext> context);
3f476a
 
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
 const char* GetClientHelloALPN(const SSLPointer& ssl);
3f476a
 
3f476a
 const char* GetClientHelloServerName(const SSLPointer& ssl);
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
 
3f476a
 const char* GetServerName(SSL* ssl);
3f476a
 
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
 v8::MaybeLocal<v8::Array> GetClientHelloCiphers(
3f476a
     Environment* env,
3f476a
     const SSLPointer& ssl);
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
 
3f476a
 bool SetGroups(SecureContext* sc, const char* groups);
3f476a
 
3f476a
@@ -97,9 +101,11 @@ v8::MaybeLocal<v8::Value> GetCipherName(
3f476a
     Environment* env,
3f476a
     const SSLPointer& ssl);
3f476a
 
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
 v8::MaybeLocal<v8::Value> GetCipherStandardName(
3f476a
     Environment* env,
3f476a
     const SSLPointer& ssl);
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
 
3f476a
 v8::MaybeLocal<v8::Value> GetCipherVersion(
3f476a
     Environment* env,
3f476a
diff --git a/src/node_options.cc b/src/node_options.cc
f0ceb1
index 3c9fe815df..010232940a 100644
3f476a
--- a/src/node_options.cc
3f476a
+++ b/src/node_options.cc
3f476a
@@ -9,6 +9,8 @@
3f476a
 #include <sstream>
3f476a
 #include <cstdlib>  // strtoul, errno
3f476a
 
3f476a
+#include <node-ssl-shim/features.h>
3f476a
+
3f476a
 using v8::Boolean;
3f476a
 using v8::Context;
3f476a
 using v8::FunctionCallbackInfo;
3f476a
@@ -113,10 +115,12 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
3f476a
     errors->push_back("invalid value for --unhandled-rejections");
3f476a
   }
3f476a
 
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
   if (tls_min_v1_3 && tls_max_v1_2) {
3f476a
     errors->push_back("either --tls-min-v1.3 or --tls-max-v1.2 can be "
3f476a
                       "used, not both");
3f476a
   }
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
 
3f476a
 #if HAVE_INSPECTOR
3f476a
   if (!cpu_prof) {
f0ceb1
@@ -537,14 +541,17 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
3f476a
             "set default TLS minimum to TLSv1.2 (default: TLSv1.2)",
3f476a
             &EnvironmentOptions::tls_min_v1_2,
3f476a
             kAllowedInEnvironment);
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
   AddOption("--tls-min-v1.3",
3f476a
             "set default TLS minimum to TLSv1.3 (default: TLSv1.2)",
3f476a
             &EnvironmentOptions::tls_min_v1_3,
3f476a
             kAllowedInEnvironment);
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
   AddOption("--tls-max-v1.2",
3f476a
-            "set default TLS maximum to TLSv1.2 (default: TLSv1.3)",
3f476a
+            "set default TLS maximum to TLSv1.2 (default: TLSv1.2)",
3f476a
             &EnvironmentOptions::tls_max_v1_2,
3f476a
             kAllowedInEnvironment);
3f476a
+#if !OPENSSL_IS_LEGACY
3f476a
   // Current plan is:
3f476a
   // - 11.x and below: TLS1.3 is opt-in with --tls-max-v1.3
3f476a
   // - 12.x: TLS1.3 is opt-out with --tls-max-v1.2
f0ceb1
@@ -553,6 +560,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
3f476a
             "set default TLS maximum to TLSv1.3 (default: TLSv1.3)",
3f476a
             &EnvironmentOptions::tls_max_v1_3,
3f476a
             kAllowedInEnvironment);
3f476a
+#endif // !OPENSSL_IS_LEGACY
3f476a
 }
3f476a
 
3f476a
 PerIsolateOptionsParser::PerIsolateOptionsParser(
3f476a
diff --git a/test/parallel/test-tls-cli-max-version-1.3.js b/test/known_issues/test-tls-cli-max-version-1.3.js
3f476a
similarity index 100%
3f476a
rename from test/parallel/test-tls-cli-max-version-1.3.js
3f476a
rename to test/known_issues/test-tls-cli-max-version-1.3.js
3f476a
diff --git a/test/parallel/test-tls-cli-min-max-conflict.js b/test/known_issues/test-tls-cli-min-max-conflict.js
3f476a
similarity index 100%
3f476a
rename from test/parallel/test-tls-cli-min-max-conflict.js
3f476a
rename to test/known_issues/test-tls-cli-min-max-conflict.js
3f476a
diff --git a/test/parallel/test-tls-cli-min-version-1.3.js b/test/known_issues/test-tls-cli-min-version-1.3.js
3f476a
similarity index 100%
3f476a
rename from test/parallel/test-tls-cli-min-version-1.3.js
3f476a
rename to test/known_issues/test-tls-cli-min-version-1.3.js
3f476a
-- 
f0ceb1
2.31.1
3f476a