8ff60a
From 2840bd0becee307f4ee896b26e9f29baac03c347 Mon Sep 17 00:00:00 2001
8ff60a
From: Andreas Schneider <asn@samba.org>
8ff60a
Date: Mon, 15 Jun 2020 11:50:16 +0200
8ff60a
Subject: [PATCH 1/2] s3:lib:tls: Use better priority lists for modern GnuTLS
8ff60a
8ff60a
We should use the default priority list. That is a good practice,
8ff60a
because TLS protocol hardening and phasing out of legacy algorithms,
8ff60a
is easier to co-ordinate when happens at a single place. See crypto
8ff60a
policies of Fedora.
8ff60a
8ff60a
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14408
8ff60a
8ff60a
Signed-off-by: Andreas Schneider <asn@samba.org>
8ff60a
Reviewed-by: Alexander Bokovoy <ab@samba.org>
8ff60a
8ff60a
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
8ff60a
Autobuild-Date(master): Wed Jun 17 17:42:02 UTC 2020 on sn-devel-184
8ff60a
---
8ff60a
 docs-xml/smbdotconf/security/tlspriority.xml | 10 ++---
8ff60a
 lib/param/loadparm.c                         | 10 ++++-
8ff60a
 python/samba/tests/docs.py                   | 20 ++++++++++
8ff60a
 source3/param/loadparm.c                     | 11 +++++-
8ff60a
 source4/lib/tls/tls_tstream.c                | 40 +++++++++++++++-----
8ff60a
 wscript_configure_system_gnutls              |  3 ++
8ff60a
 6 files changed, 76 insertions(+), 18 deletions(-)
8ff60a
8ff60a
diff --git a/docs-xml/smbdotconf/security/tlspriority.xml b/docs-xml/smbdotconf/security/tlspriority.xml
8ff60a
index d7214a4c1ea..6d1f0dcb912 100644
8ff60a
--- a/docs-xml/smbdotconf/security/tlspriority.xml
8ff60a
+++ b/docs-xml/smbdotconf/security/tlspriority.xml
8ff60a
@@ -7,15 +7,15 @@
8ff60a
    to be supported in the parts of Samba that use GnuTLS, specifically
8ff60a
    the AD DC.
8ff60a
    </para>
8ff60a
-   <para>The default turns off SSLv3, as this protocol is no longer considered
8ff60a
-   secure after CVE-2014-3566 (otherwise known as POODLE) impacted SSLv3 use
8ff60a
-   in HTTPS applications.
8ff60a
-   </para>
8ff60a
+   <para>The string is appended to the default priority list of GnuTLS.</para>
8ff60a
    <para>The valid options are described in the
8ff60a
    <ulink url="http://gnutls.org/manual/html_node/Priority-Strings.html">GNUTLS
8ff60a
    Priority-Strings documentation at http://gnutls.org/manual/html_node/Priority-Strings.html</ulink>
8ff60a
    </para>
8ff60a
+   <para>By default it will try to find a config file matching "SAMBA", but if
8ff60a
+   that does not exist will use the entry for "SYSTEM" and last fallback to
8ff60a
+   NORMAL. In all cases the SSL3.0 protocol will be disabled.</para>
8ff60a
  </description>
8ff60a
 
8ff60a
- <value type="default">NORMAL:-VERS-SSL3.0</value>
8ff60a
+ <value type="default">@SAMBA,SYSTEM,NORMAL:!-VERS-SSL3.0</value>
8ff60a
 </samba:parameter>
8ff60a
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
8ff60a
index 63291283905..8fdd844fbaa 100644
8ff60a
--- a/lib/param/loadparm.c
8ff60a
+++ b/lib/param/loadparm.c
8ff60a
@@ -2803,7 +2803,15 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
8ff60a
 	lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
8ff60a
 	lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
8ff60a
 	lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
8ff60a
-	lpcfg_do_global_parameter(lp_ctx, "tls priority", "NORMAL:-VERS-SSL3.0");
8ff60a
+#ifdef HAVE_GNUTLS_SET_DEFAULT_PRIORITY_APPEND
8ff60a
+	lpcfg_do_global_parameter(lp_ctx,
8ff60a
+				  "tls priority",
8ff60a
+				  "@SAMBA,SYSTEM,NORMAL:!-VERS-SSL3.0");
8ff60a
+#else
8ff60a
+	lpcfg_do_global_parameter(lp_ctx,
8ff60a
+				  "tls priority",
8ff60a
+				  "NORMAL:-VERS-SSL3.0");
8ff60a
+#endif
8ff60a
 
8ff60a
 	lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
8ff60a
 
8ff60a
diff --git a/python/samba/tests/docs.py b/python/samba/tests/docs.py
8ff60a
index 32a16a98fbc..789865221cb 100644
8ff60a
--- a/python/samba/tests/docs.py
8ff60a
+++ b/python/samba/tests/docs.py
8ff60a
@@ -26,6 +26,21 @@ import os
8ff60a
 import subprocess
8ff60a
 import xml.etree.ElementTree as ET
8ff60a
 
8ff60a
+config_h = os.path.join("bin/default/include/config.h")
8ff60a
+config_hash = dict()
8ff60a
+
8ff60a
+if os.path.exists(config_h):
8ff60a
+    config_hash = dict()
8ff60a
+    f = open(config_h, 'r')
8ff60a
+    try:
8ff60a
+        lines = f.readlines()
8ff60a
+        config_hash = dict((x[0], ' '.join(x[1:]))
8ff60a
+                           for x in map(lambda line: line.strip().split(' ')[1:],
8ff60a
+                                        list(filter(lambda line: (line[0:7] == '#define') and (len(line.split(' ')) > 2), lines))))
8ff60a
+    finally:
8ff60a
+        f.close()
8ff60a
+
8ff60a
+have_gnutls_system_config_support = ("HAVE_GNUTLS_SET_DEFAULT_PRIORITY_APPEND" in config_hash)
8ff60a
 
8ff60a
 class TestCase(samba.tests.TestCaseInTempDir):
8ff60a
 
8ff60a
@@ -127,6 +142,11 @@ class SmbDotConfTests(TestCase):
8ff60a
         'smbd max async dosmode',
8ff60a
     ])
8ff60a
 
8ff60a
+    # 'tls priority' has a legacy default value if we don't link against a
8ff60a
+    # modern GnuTLS version.
8ff60a
+    if not have_gnutls_system_config_support:
8ff60a
+        special_cases.add('tls priority')
8ff60a
+
8ff60a
     def setUp(self):
8ff60a
         super(SmbDotConfTests, self).setUp()
8ff60a
         # create a minimal smb.conf file for testparm
8ff60a
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
8ff60a
index d3d81f6ece5..2b1a63998d6 100644
8ff60a
--- a/source3/param/loadparm.c
8ff60a
+++ b/source3/param/loadparm.c
8ff60a
@@ -885,8 +885,15 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
8ff60a
 	lpcfg_string_set(Globals.ctx, &Globals._tls_keyfile, "tls/key.pem");
8ff60a
 	lpcfg_string_set(Globals.ctx, &Globals._tls_certfile, "tls/cert.pem");
8ff60a
 	lpcfg_string_set(Globals.ctx, &Globals._tls_cafile, "tls/ca.pem");
8ff60a
-	lpcfg_string_set(Globals.ctx, &Globals.tls_priority,
8ff60a
-			 "NORMAL:-VERS-SSL3.0");
8ff60a
+#ifdef HAVE_GNUTLS_SET_DEFAULT_PRIORITY_APPEND
8ff60a
+	lpcfg_string_set(Globals.ctx,
8ff60a
+			 &Globals.tls_priority,
8ff60a
+			 "@SAMBA,SYSTEM,NORMAL:!-VERS-SSL3.0");
8ff60a
+#else
8ff60a
+	lpcfg_string_set(Globals.ctx,
8ff60a
+			 &Globals.tls_priority,
8ff60a
+			 "NORMAL!-VERS-SSL3.0");
8ff60a
+#endif
8ff60a
 
8ff60a
 	lpcfg_string_set(Globals.ctx, &Globals.share_backend, "classic");
8ff60a
 
8ff60a
diff --git a/source4/lib/tls/tls_tstream.c b/source4/lib/tls/tls_tstream.c
8ff60a
index 55bca036776..d984addeec5 100644
8ff60a
--- a/source4/lib/tls/tls_tstream.c
8ff60a
+++ b/source4/lib/tls/tls_tstream.c
8ff60a
@@ -1035,16 +1035,26 @@ struct tevent_req *_tstream_tls_connect_send(TALLOC_CTX *mem_ctx,
8ff60a
 		return tevent_req_post(req, ev);
8ff60a
 	}
8ff60a
 
8ff60a
-	ret = gnutls_priority_set_direct(tlss->tls_session,
8ff60a
-					 tls_params->tls_priority,
8ff60a
-					 &error_pos);
8ff60a
+	ret = gnutls_set_default_priority(tlss->tls_session);
8ff60a
 	if (ret != GNUTLS_E_SUCCESS) {
8ff60a
-		DEBUG(0,("TLS %s - %s.  Check 'tls priority' option at '%s'\n",
8ff60a
-			 __location__, gnutls_strerror(ret), error_pos));
8ff60a
+		DBG_ERR("TLS %s - %s. Failed to set default priorities\n",
8ff60a
+			__location__, gnutls_strerror(ret));
8ff60a
 		tevent_req_error(req, EINVAL);
8ff60a
 		return tevent_req_post(req, ev);
8ff60a
 	}
8ff60a
 
8ff60a
+	if (strlen(tls_params->tls_priority) > 0) {
8ff60a
+		ret = gnutls_priority_set_direct(tlss->tls_session,
8ff60a
+						 tls_params->tls_priority,
8ff60a
+						 &error_pos);
8ff60a
+		if (ret != GNUTLS_E_SUCCESS) {
8ff60a
+			DEBUG(0,("TLS %s - %s.  Check 'tls priority' option at '%s'\n",
8ff60a
+				 __location__, gnutls_strerror(ret), error_pos));
8ff60a
+			tevent_req_error(req, EINVAL);
8ff60a
+			return tevent_req_post(req, ev);
8ff60a
+		}
8ff60a
+	}
8ff60a
+
8ff60a
 	ret = gnutls_credentials_set(tlss->tls_session,
8ff60a
 				     GNUTLS_CRD_CERTIFICATE,
8ff60a
 				     tls_params->x509_cred);
8ff60a
@@ -1284,16 +1294,26 @@ struct tevent_req *_tstream_tls_accept_send(TALLOC_CTX *mem_ctx,
8ff60a
 		return tevent_req_post(req, ev);
8ff60a
 	}
8ff60a
 
8ff60a
-	ret = gnutls_priority_set_direct(tlss->tls_session,
8ff60a
-					 tlsp->tls_priority,
8ff60a
-					 &error_pos);
8ff60a
+	ret = gnutls_set_default_priority(tlss->tls_session);
8ff60a
 	if (ret != GNUTLS_E_SUCCESS) {
8ff60a
-		DEBUG(0,("TLS %s - %s.  Check 'tls priority' option at '%s'\n",
8ff60a
-			 __location__, gnutls_strerror(ret), error_pos));
8ff60a
+		DBG_ERR("TLS %s - %s. Failed to set default priorities\n",
8ff60a
+			__location__, gnutls_strerror(ret));
8ff60a
 		tevent_req_error(req, EINVAL);
8ff60a
 		return tevent_req_post(req, ev);
8ff60a
 	}
8ff60a
 
8ff60a
+	if (strlen(tlsp->tls_priority) > 0) {
8ff60a
+		ret = gnutls_priority_set_direct(tlss->tls_session,
8ff60a
+						 tlsp->tls_priority,
8ff60a
+						 &error_pos);
8ff60a
+		if (ret != GNUTLS_E_SUCCESS) {
8ff60a
+			DEBUG(0,("TLS %s - %s.  Check 'tls priority' option at '%s'\n",
8ff60a
+				 __location__, gnutls_strerror(ret), error_pos));
8ff60a
+			tevent_req_error(req, EINVAL);
8ff60a
+			return tevent_req_post(req, ev);
8ff60a
+		}
8ff60a
+	}
8ff60a
+
8ff60a
 	ret = gnutls_credentials_set(tlss->tls_session, GNUTLS_CRD_CERTIFICATE,
8ff60a
 				     tlsp->x509_cred);
8ff60a
 	if (ret != GNUTLS_E_SUCCESS) {
8ff60a
diff --git a/wscript_configure_system_gnutls b/wscript_configure_system_gnutls
8ff60a
index b2b955f3c90..631405fa34c 100644
8ff60a
--- a/wscript_configure_system_gnutls
8ff60a
+++ b/wscript_configure_system_gnutls
8ff60a
@@ -20,6 +20,9 @@ conf.SET_TARGET_TYPE('gnutls', 'SYSLIB')
8ff60a
 # Check for gnutls_pkcs7_get_embedded_data_oid (>= 3.5.5) required by libmscat
8ff60a
 conf.CHECK_FUNCS_IN('gnutls_pkcs7_get_embedded_data_oid', 'gnutls')
8ff60a
 
8ff60a
+# Check for gnutls_set_default_priority_append (>= 3.6.3)
8ff60a
+conf.CHECK_FUNCS_IN('gnutls_set_default_priority_append', 'gnutls')
8ff60a
+
8ff60a
 # Check for gnutls_aead_cipher_encryptv2
8ff60a
 #
8ff60a
 # This is available since version 3.6.10, but 3.6.10 has a bug which got fixed
8ff60a
-- 
8ff60a
2.26.2
8ff60a
8ff60a
8ff60a
From fdcf9f23f659025f174b32109a273e80b2ad289e Mon Sep 17 00:00:00 2001
8ff60a
From: Andreas Schneider <asn@samba.org>
8ff60a
Date: Tue, 30 Jun 2020 17:12:17 +0200
8ff60a
Subject: [PATCH 2/2] tls: Use NORMAL:-VERS-SSL3.0 as the default configuration
8ff60a
8ff60a
This seems to be really broken in GnuTLS and the documentation is also
8ff60a
not correct.
8ff60a
8ff60a
This partially reverts 53e3a959b958a3b099df6ecc5f6e294e96bd948e
8ff60a
8ff60a
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14408
8ff60a
8ff60a
Signed-off-by: Andreas Schneider <asn@samba.org>
8ff60a
Reviewed-by: Alexander Bokovoy <ab@samba.org>
8ff60a
8ff60a
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
8ff60a
Autobuild-Date(master): Wed Jul  1 14:56:33 UTC 2020 on sn-devel-184
8ff60a
---
8ff60a
 docs-xml/smbdotconf/security/tlspriority.xml |  6 ++----
8ff60a
 lib/param/loadparm.c                         |  6 ------
8ff60a
 python/samba/tests/docs.py                   | 21 --------------------
8ff60a
 source3/param/loadparm.c                     |  8 +-------
8ff60a
 4 files changed, 3 insertions(+), 38 deletions(-)
8ff60a
8ff60a
diff --git a/docs-xml/smbdotconf/security/tlspriority.xml b/docs-xml/smbdotconf/security/tlspriority.xml
8ff60a
index 6d1f0dcb912..471dc25ba3b 100644
8ff60a
--- a/docs-xml/smbdotconf/security/tlspriority.xml
8ff60a
+++ b/docs-xml/smbdotconf/security/tlspriority.xml
8ff60a
@@ -12,10 +12,8 @@
8ff60a
    <ulink url="http://gnutls.org/manual/html_node/Priority-Strings.html">GNUTLS
8ff60a
    Priority-Strings documentation at http://gnutls.org/manual/html_node/Priority-Strings.html</ulink>
8ff60a
    </para>
8ff60a
-   <para>By default it will try to find a config file matching "SAMBA", but if
8ff60a
-   that does not exist will use the entry for "SYSTEM" and last fallback to
8ff60a
-   NORMAL. In all cases the SSL3.0 protocol will be disabled.</para>
8ff60a
+   <para>The SSL3.0 protocol will be disabled.</para>
8ff60a
  </description>
8ff60a
 
8ff60a
- <value type="default">@SAMBA,SYSTEM,NORMAL:!-VERS-SSL3.0</value>
8ff60a
+ <value type="default">NORMAL:-VERS-SSL3.0</value>
8ff60a
 </samba:parameter>
8ff60a
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
8ff60a
index 8fdd844fbaa..4e7e3f599dd 100644
8ff60a
--- a/lib/param/loadparm.c
8ff60a
+++ b/lib/param/loadparm.c
8ff60a
@@ -2803,15 +2803,9 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
8ff60a
 	lpcfg_do_global_parameter(lp_ctx, "tls keyfile", "tls/key.pem");
8ff60a
 	lpcfg_do_global_parameter(lp_ctx, "tls certfile", "tls/cert.pem");
8ff60a
 	lpcfg_do_global_parameter(lp_ctx, "tls cafile", "tls/ca.pem");
8ff60a
-#ifdef HAVE_GNUTLS_SET_DEFAULT_PRIORITY_APPEND
8ff60a
-	lpcfg_do_global_parameter(lp_ctx,
8ff60a
-				  "tls priority",
8ff60a
-				  "@SAMBA,SYSTEM,NORMAL:!-VERS-SSL3.0");
8ff60a
-#else
8ff60a
 	lpcfg_do_global_parameter(lp_ctx,
8ff60a
 				  "tls priority",
8ff60a
 				  "NORMAL:-VERS-SSL3.0");
8ff60a
-#endif
8ff60a
 
8ff60a
 	lpcfg_do_global_parameter(lp_ctx, "nsupdate command", "/usr/bin/nsupdate -g");
8ff60a
 
8ff60a
diff --git a/python/samba/tests/docs.py b/python/samba/tests/docs.py
8ff60a
index 789865221cb..654a192b510 100644
8ff60a
--- a/python/samba/tests/docs.py
8ff60a
+++ b/python/samba/tests/docs.py
8ff60a
@@ -26,22 +26,6 @@ import os
8ff60a
 import subprocess
8ff60a
 import xml.etree.ElementTree as ET
8ff60a
 
8ff60a
-config_h = os.path.join("bin/default/include/config.h")
8ff60a
-config_hash = dict()
8ff60a
-
8ff60a
-if os.path.exists(config_h):
8ff60a
-    config_hash = dict()
8ff60a
-    f = open(config_h, 'r')
8ff60a
-    try:
8ff60a
-        lines = f.readlines()
8ff60a
-        config_hash = dict((x[0], ' '.join(x[1:]))
8ff60a
-                           for x in map(lambda line: line.strip().split(' ')[1:],
8ff60a
-                                        list(filter(lambda line: (line[0:7] == '#define') and (len(line.split(' ')) > 2), lines))))
8ff60a
-    finally:
8ff60a
-        f.close()
8ff60a
-
8ff60a
-have_gnutls_system_config_support = ("HAVE_GNUTLS_SET_DEFAULT_PRIORITY_APPEND" in config_hash)
8ff60a
-
8ff60a
 class TestCase(samba.tests.TestCaseInTempDir):
8ff60a
 
8ff60a
     def _format_message(self, parameters, message):
8ff60a
@@ -142,11 +126,6 @@ class SmbDotConfTests(TestCase):
8ff60a
         'smbd max async dosmode',
8ff60a
     ])
8ff60a
 
8ff60a
-    # 'tls priority' has a legacy default value if we don't link against a
8ff60a
-    # modern GnuTLS version.
8ff60a
-    if not have_gnutls_system_config_support:
8ff60a
-        special_cases.add('tls priority')
8ff60a
-
8ff60a
     def setUp(self):
8ff60a
         super(SmbDotConfTests, self).setUp()
8ff60a
         # create a minimal smb.conf file for testparm
8ff60a
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
8ff60a
index 2b1a63998d6..901f01b1c6a 100644
8ff60a
--- a/source3/param/loadparm.c
8ff60a
+++ b/source3/param/loadparm.c
8ff60a
@@ -885,15 +885,9 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
8ff60a
 	lpcfg_string_set(Globals.ctx, &Globals._tls_keyfile, "tls/key.pem");
8ff60a
 	lpcfg_string_set(Globals.ctx, &Globals._tls_certfile, "tls/cert.pem");
8ff60a
 	lpcfg_string_set(Globals.ctx, &Globals._tls_cafile, "tls/ca.pem");
8ff60a
-#ifdef HAVE_GNUTLS_SET_DEFAULT_PRIORITY_APPEND
8ff60a
 	lpcfg_string_set(Globals.ctx,
8ff60a
 			 &Globals.tls_priority,
8ff60a
-			 "@SAMBA,SYSTEM,NORMAL:!-VERS-SSL3.0");
8ff60a
-#else
8ff60a
-	lpcfg_string_set(Globals.ctx,
8ff60a
-			 &Globals.tls_priority,
8ff60a
-			 "NORMAL!-VERS-SSL3.0");
8ff60a
-#endif
8ff60a
+			 "NORMAL:-VERS-SSL3.0");
8ff60a
 
8ff60a
 	lpcfg_string_set(Globals.ctx, &Globals.share_backend, "classic");
8ff60a
 
8ff60a
-- 
8ff60a
2.26.2
8ff60a