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

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