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

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