Blame SOURCES/0022-Introduce-support-for-EDDHE-based-cipher-suites.patch

d7fdbd
From a6d641a0ccba1033587f6faa0e5e6749fa35f5c4 Mon Sep 17 00:00:00 2001
d7fdbd
From: Martin Sehnoutka <msehnout@redhat.com>
d7fdbd
Date: Thu, 17 Nov 2016 10:49:22 +0100
d7fdbd
Subject: [PATCH 22/59] Introduce support for EDDHE based cipher suites.
d7fdbd
d7fdbd
---
d7fdbd
 parseconf.c   |  1 +
d7fdbd
 ssl.c         | 37 ++++++++++++++++++++++++++++++++++++-
d7fdbd
 tunables.c    |  4 +++-
d7fdbd
 tunables.h    |  1 +
d7fdbd
 vsftpd.conf.5 |  8 ++++++++
d7fdbd
 5 files changed, 49 insertions(+), 2 deletions(-)
d7fdbd
d7fdbd
diff --git a/parseconf.c b/parseconf.c
d7fdbd
index 38e3182..a2c715b 100644
d7fdbd
--- a/parseconf.c
d7fdbd
+++ b/parseconf.c
d7fdbd
@@ -177,6 +177,7 @@ parseconf_str_array[] =
d7fdbd
   { "rsa_cert_file", &tunable_rsa_cert_file },
d7fdbd
   { "dsa_cert_file", &tunable_dsa_cert_file },
d7fdbd
   { "dh_param_file", &tunable_dh_param_file },
d7fdbd
+  { "ecdh_param_file", &tunable_ecdh_param_file },
d7fdbd
   { "ssl_ciphers", &tunable_ssl_ciphers },
d7fdbd
   { "rsa_private_key_file", &tunable_rsa_private_key_file },
d7fdbd
   { "dsa_private_key_file", &tunable_dsa_private_key_file },
d7fdbd
diff --git a/ssl.c b/ssl.c
d7fdbd
index 22b69b3..96bf8ad 100644
d7fdbd
--- a/ssl.c
d7fdbd
+++ b/ssl.c
d7fdbd
@@ -122,7 +122,7 @@ ssl_init(struct vsf_session* p_sess)
d7fdbd
     {
d7fdbd
       die("SSL: could not allocate SSL context");
d7fdbd
     }
d7fdbd
-    options = SSL_OP_ALL | SSL_OP_SINGLE_DH_USE;
d7fdbd
+    options = SSL_OP_ALL | SSL_OP_SINGLE_DH_USE | SSL_OP_SINGLE_ECDH_USE;
d7fdbd
     if (!tunable_sslv2)
d7fdbd
     {
d7fdbd
       options |= SSL_OP_NO_SSLv2;
d7fdbd
@@ -244,6 +244,41 @@ ssl_init(struct vsf_session* p_sess)
d7fdbd
     
d7fdbd
     SSL_CTX_set_tmp_dh_callback(p_ctx, ssl_tmp_dh_callback);
d7fdbd
 
d7fdbd
+    if (tunable_ecdh_param_file)
d7fdbd
+    {
d7fdbd
+      BIO *bio;
d7fdbd
+      int nid;
d7fdbd
+      EC_GROUP *ecparams = NULL;
d7fdbd
+      EC_KEY *eckey;
d7fdbd
+
d7fdbd
+      if ((bio = BIO_new_file(tunable_ecdh_param_file, "r")) == NULL)
d7fdbd
+        die("SSL: cannot load custom ec params");
d7fdbd
+      else
d7fdbd
+      {
d7fdbd
+        ecparams = PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL);
d7fdbd
+        BIO_free(bio);
d7fdbd
+
d7fdbd
+        if (ecparams && (nid = EC_GROUP_get_curve_name(ecparams)) &&
d7fdbd
+            (eckey = EC_KEY_new_by_curve_name(nid)))
d7fdbd
+        {
d7fdbd
+          if (!SSL_CTX_set_tmp_ecdh(p_ctx, eckey))
d7fdbd
+            die("SSL: setting custom EC params failed");
d7fdbd
+	}
d7fdbd
+	else
d7fdbd
+        {
d7fdbd
+          die("SSL: getting ec group or key failed");
d7fdbd
+	}
d7fdbd
+      }
d7fdbd
+    }
d7fdbd
+    else
d7fdbd
+    {
d7fdbd
+#if defined(SSL_CTX_set_ecdh_auto)
d7fdbd
+      SSL_CTX_set_ecdh_auto(p_ctx, 1);
d7fdbd
+#else
d7fdbd
+      SSL_CTX_set_tmp_ecdh(p_ctx, EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
d7fdbd
+#endif
d7fdbd
+    }
d7fdbd
+
d7fdbd
     p_sess->p_ssl_ctx = p_ctx;
d7fdbd
     ssl_inited = 1;
d7fdbd
   }
d7fdbd
diff --git a/tunables.c b/tunables.c
d7fdbd
index 1ea7227..93f85b1 100644
d7fdbd
--- a/tunables.c
d7fdbd
+++ b/tunables.c
d7fdbd
@@ -141,6 +141,7 @@ const char* tunable_email_password_file;
d7fdbd
 const char* tunable_rsa_cert_file;
d7fdbd
 const char* tunable_dsa_cert_file;
d7fdbd
 const char* tunable_dh_param_file;
d7fdbd
+const char* tunable_ecdh_param_file;
d7fdbd
 const char* tunable_ssl_ciphers;
d7fdbd
 const char* tunable_rsa_private_key_file;
d7fdbd
 const char* tunable_dsa_private_key_file;
d7fdbd
@@ -290,7 +291,8 @@ tunables_load_defaults()
d7fdbd
                       &tunable_rsa_cert_file);
d7fdbd
   install_str_setting(0, &tunable_dsa_cert_file);
d7fdbd
   install_str_setting(0, &tunable_dh_param_file);
d7fdbd
-  install_str_setting("AES128-SHA:DES-CBC3-SHA:DHE-RSA-AES256-SHA",
d7fdbd
+  install_str_setting(0, &tunable_ecdh_param_file);
d7fdbd
+  install_str_setting("AES128-SHA:DES-CBC3-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA",
d7fdbd
                       &tunable_ssl_ciphers);
d7fdbd
   install_str_setting(0, &tunable_rsa_private_key_file);
d7fdbd
   install_str_setting(0, &tunable_dsa_private_key_file);
d7fdbd
diff --git a/tunables.h b/tunables.h
d7fdbd
index 3995472..3e2d40c 100644
d7fdbd
--- a/tunables.h
d7fdbd
+++ b/tunables.h
d7fdbd
@@ -143,6 +143,7 @@ extern const char* tunable_email_password_file;
d7fdbd
 extern const char* tunable_rsa_cert_file;
d7fdbd
 extern const char* tunable_dsa_cert_file;
d7fdbd
 extern const char* tunable_dh_param_file;
d7fdbd
+extern const char* tunable_ecdh_param_file;
d7fdbd
 extern const char* tunable_ssl_ciphers;
d7fdbd
 extern const char* tunable_rsa_private_key_file;
d7fdbd
 extern const char* tunable_dsa_private_key_file;
d7fdbd
diff --git a/vsftpd.conf.5 b/vsftpd.conf.5
d7fdbd
index ff94eca..e242873 100644
d7fdbd
--- a/vsftpd.conf.5
d7fdbd
+++ b/vsftpd.conf.5
d7fdbd
@@ -899,6 +899,14 @@ ephemeral Diffie-Hellman key exchange in SSL.
d7fdbd
 
d7fdbd
 Default: (none - use built in parameters appropriate for certificate key size)
d7fdbd
 .TP
d7fdbd
+.B ecdh_param_file
d7fdbd
+This option specifies the location of custom parameters for ephemeral
d7fdbd
+Elliptic Curve Diffie-Hellman (ECDH) key exchange.
d7fdbd
+
d7fdbd
+Default: (none - use built in parameters, NIST P-256 with OpenSSL 1.0.1 and
d7fdbd
+automatically selected curve based on client preferences with OpenSSL 1.0.2
d7fdbd
+and later)
d7fdbd
+.TP
d7fdbd
 .B email_password_file
d7fdbd
 This option can be used to provide an alternate file for usage by the
d7fdbd
 .BR secure_email_list_enable
d7fdbd
-- 
d7fdbd
2.14.4
d7fdbd