Blame SOURCES/0001-adenroll-make-sure-only-allowed-enctypes-are-used-in.patch

ee8dc1
From 341974aae7d0755fc32a0b7e2b34d8e1ef60d195 Mon Sep 17 00:00:00 2001
ee8dc1
From: Sumit Bose <sbose@redhat.com>
ee8dc1
Date: Thu, 20 Dec 2018 21:05:35 +0100
ee8dc1
Subject: [PATCH 1/4] adenroll: make sure only allowed enctypes are used in
ee8dc1
 FIPS mode
ee8dc1
ee8dc1
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1717355
ee8dc1
---
ee8dc1
 library/adenroll.c | 36 +++++++++++++++++++++++++++++++++++-
ee8dc1
 1 file changed, 35 insertions(+), 1 deletion(-)
ee8dc1
ee8dc1
diff --git a/library/adenroll.c b/library/adenroll.c
ee8dc1
index 52aa8a8..f617f28 100644
ee8dc1
--- a/library/adenroll.c
ee8dc1
+++ b/library/adenroll.c
ee8dc1
@@ -41,11 +41,19 @@
ee8dc1
 #include <netdb.h>
ee8dc1
 #include <stdio.h>
ee8dc1
 #include <unistd.h>
ee8dc1
+#include <sys/stat.h>
ee8dc1
+#include <fcntl.h>
ee8dc1
 
ee8dc1
 #ifndef SAMBA_DATA_TOOL
ee8dc1
 #define SAMBA_DATA_TOOL "/usr/bin/net"
ee8dc1
 #endif
ee8dc1
 
ee8dc1
+static krb5_enctype v60_later_enctypes_fips[] = {
ee8dc1
+	ENCTYPE_AES256_CTS_HMAC_SHA1_96,
ee8dc1
+	ENCTYPE_AES128_CTS_HMAC_SHA1_96,
ee8dc1
+	0
ee8dc1
+};
ee8dc1
+
ee8dc1
 static krb5_enctype v60_later_enctypes[] = {
ee8dc1
 	ENCTYPE_AES256_CTS_HMAC_SHA1_96,
ee8dc1
 	ENCTYPE_AES128_CTS_HMAC_SHA1_96,
ee8dc1
@@ -2594,6 +2602,28 @@ adcli_enroll_set_keytab_name (adcli_enroll *enroll,
ee8dc1
 	enroll->keytab_name_is_krb5 = 0;
ee8dc1
 }
ee8dc1
 
ee8dc1
+#define PROC_SYS_FIPS "/proc/sys/crypto/fips_enabled"
ee8dc1
+
ee8dc1
+static bool adcli_fips_enabled (void)
ee8dc1
+{
ee8dc1
+	int fd;
ee8dc1
+	ssize_t len;
ee8dc1
+	char buf[8];
ee8dc1
+
ee8dc1
+	fd = open (PROC_SYS_FIPS, O_RDONLY);
ee8dc1
+	if (fd != -1) {
ee8dc1
+		len = read (fd, buf, sizeof (buf));
ee8dc1
+		close (fd);
ee8dc1
+		/* Assume FIPS in enabled if PROC_SYS_FIPS contains a
ee8dc1
+		 * non-0 value. */
ee8dc1
+		if ( ! (len == 2 && buf[0] == '0' && buf[1] == '\n')) {
ee8dc1
+			return true;
ee8dc1
+		}
ee8dc1
+	}
ee8dc1
+
ee8dc1
+	return false;
ee8dc1
+}
ee8dc1
+
ee8dc1
 krb5_enctype *
ee8dc1
 adcli_enroll_get_keytab_enctypes (adcli_enroll *enroll)
ee8dc1
 {
ee8dc1
@@ -2602,7 +2632,11 @@ adcli_enroll_get_keytab_enctypes (adcli_enroll *enroll)
ee8dc1
 		return enroll->keytab_enctypes;
ee8dc1
 
ee8dc1
 	if (adcli_conn_server_has_capability (enroll->conn, ADCLI_CAP_V60_OID))
ee8dc1
-		return v60_later_enctypes;
ee8dc1
+		if (adcli_fips_enabled ()) {
ee8dc1
+			return v60_later_enctypes_fips;
ee8dc1
+		} else {
ee8dc1
+			return v60_later_enctypes;
ee8dc1
+		}
ee8dc1
 	else
ee8dc1
 		return v51_earlier_enctypes;
ee8dc1
 }
ee8dc1
-- 
ee8dc1
2.21.0
ee8dc1