Blame SOURCES/0001-Use-startTLS-with-FreeIPA.patch

3eb28c
From b53c3e5fb5c90813ce1b47ddc570dd9c800232f9 Mon Sep 17 00:00:00 2001
3eb28c
From: Sumit Bose <sbose@redhat.com>
3eb28c
Date: Fri, 3 Jul 2020 17:18:27 +0200
3eb28c
Subject: [PATCH] Use startTLS with FreeIPA
3eb28c
3eb28c
FreeIPA is planning to required a minimal security strength factor (ssf)
3eb28c
in an upcoming version. This basically means that communication should
3eb28c
be encrypted. The most straight forward way is use TLS by doing a
3eb28c
StartLS operation after the rootDSE lookup. Since FreeIPA supports TLS
3eb28c
since the initial release we will call StartTLS unconditionally but try
3eb28c
without if it fails.
3eb28c
3eb28c
Resolves: https://gitlab.freedesktop.org/realmd/realmd/-/issues/23
3eb28c
---
3eb28c
 service/realm-disco-rootdse.c | 23 +++++++++++++++++++++++
3eb28c
 service/realm-ldap.c          |  4 +++-
3eb28c
 2 files changed, 26 insertions(+), 1 deletion(-)
3eb28c
3eb28c
diff --git a/service/realm-disco-rootdse.c b/service/realm-disco-rootdse.c
3eb28c
index 3100650..7614071 100644
3eb28c
--- a/service/realm-disco-rootdse.c
3eb28c
+++ b/service/realm-disco-rootdse.c
3eb28c
@@ -226,10 +226,33 @@ request_domain_info (GTask *task,
3eb28c
                      LDAP *ldap)
3eb28c
 {
3eb28c
 	const char *attrs[] = { "info", "associatedDomain", NULL };
3eb28c
+	int ret;
3eb28c
+	int ldap_opt_val;
3eb28c
 
3eb28c
 	clo->request = NULL;
3eb28c
 	clo->result = result_domain_info;
3eb28c
 
3eb28c
+	/* Trying to setup a TLS tunnel in the case the IPA server requires an
3eb28c
+	 * encrypted connected. Trying without in case of an error. Since we
3eb28c
+	 * most probably do not have the IPA CA certificate we will not check
3eb28c
+	 * the server certificate. */
3eb28c
+	ldap_opt_val = LDAP_OPT_X_TLS_NEVER;
3eb28c
+	ret = ldap_set_option (ldap, LDAP_OPT_X_TLS_REQUIRE_CERT, &ldap_opt_val);
3eb28c
+	if (ret != LDAP_OPT_SUCCESS) {
3eb28c
+		g_debug ("Failed to disable certificate checking, trying without");
3eb28c
+	}
3eb28c
+
3eb28c
+	ldap_opt_val = 0;
3eb28c
+	ret = ldap_set_option (ldap, LDAP_OPT_X_TLS_NEWCTX, &ldap_opt_val);
3eb28c
+	if (ret != LDAP_OPT_SUCCESS) {
3eb28c
+		g_debug ("Failed to refresh LDAP context for TLS, trying without");
3eb28c
+	}
3eb28c
+
3eb28c
+	ret = ldap_start_tls_s (ldap, NULL, NULL);
3eb28c
+	if (ret != LDAP_SUCCESS) {
3eb28c
+		g_debug ("Failed to setup TLS tunnel, trying without");
3eb28c
+	}
3eb28c
+
3eb28c
 	return search_ldap (task, clo, ldap, clo->default_naming_context,
3eb28c
 	                    LDAP_SCOPE_BASE, NULL, attrs);
3eb28c
 }
3eb28c
diff --git a/service/realm-ldap.c b/service/realm-ldap.c
3eb28c
index 59817fb..7831b5b 100644
3eb28c
--- a/service/realm-ldap.c
3eb28c
+++ b/service/realm-ldap.c
3eb28c
@@ -238,7 +238,9 @@ realm_ldap_connect_anonymous (GSocketAddress *address,
3eb28c
 		if (!g_unix_set_fd_nonblocking (ls->sock, FALSE, NULL))
3eb28c
 			g_warning ("couldn't set to blocking");
3eb28c
 
3eb28c
-		rc = ldap_init_fd (ls->sock, 1, NULL, &ls->ldap);
3eb28c
+		url = g_strdup_printf ("ldap://%s:%d", addrname, port);
3eb28c
+		rc = ldap_init_fd (ls->sock, 1, url, &ls->ldap);
3eb28c
+		g_free (url);
3eb28c
 
3eb28c
 		g_free (native);
3eb28c
 
3eb28c
-- 
3eb28c
2.26.2
3eb28c