pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0202-ipa_pwd_extop-do-not-generate-NT-hashes-in-FIPS-mode.patch

483b06
From 84be5dc9e72fbf4c85b6f061da94a4316c90d65e Mon Sep 17 00:00:00 2001
483b06
From: Sumit Bose <sbose@redhat.com>
483b06
Date: Fri, 16 Jun 2017 17:49:44 +0200
483b06
Subject: [PATCH] ipa_pwd_extop: do not generate NT hashes in FIPS mode
483b06
483b06
In FIPS mode NT hashes (aka md4) are not allowed. If FIPS more is
483b06
detected we disable NT hashes even is the are allowed by IPA
483b06
configuration.
483b06
483b06
Resolves https://pagure.io/freeipa/issue/7026
483b06
483b06
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
483b06
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
483b06
---
483b06
 daemons/ipa-slapi-plugins/ipa-pwd-extop/common.c | 53 ++++++++++++++++++------
483b06
 1 file changed, 40 insertions(+), 13 deletions(-)
483b06
483b06
diff --git a/daemons/ipa-slapi-plugins/ipa-pwd-extop/common.c b/daemons/ipa-slapi-plugins/ipa-pwd-extop/common.c
483b06
index 761f7a8e3e9ee539f97797c98b8719ad752bdcf1..5efadac5b1fd57e5f91a886224fa2f1ab88305ac 100644
483b06
--- a/daemons/ipa-slapi-plugins/ipa-pwd-extop/common.c
483b06
+++ b/daemons/ipa-slapi-plugins/ipa-pwd-extop/common.c
483b06
@@ -46,6 +46,8 @@
483b06
 /* Type of connection for this operation;*/
483b06
 #define LDAP_EXTOP_PASSMOD_CONN_SECURE
483b06
 
483b06
+#define PROC_SYS_FIPS "/proc/sys/crypto/fips_enabled"
483b06
+
483b06
 /* Uncomment the following #undef FOR TESTING:
483b06
  * allows non-SSL connections to use the password change extended op */
483b06
 /* #undef LDAP_EXTOP_PASSMOD_CONN_SECURE */
483b06
@@ -62,6 +64,27 @@ static const char *ipapwd_def_encsalts[] = {
483b06
     NULL
483b06
 };
483b06
 
483b06
+static bool fips_enabled(void)
483b06
+{
483b06
+    int fd;
483b06
+    ssize_t len;
483b06
+    char buf[8];
483b06
+
483b06
+    fd = open(PROC_SYS_FIPS, O_RDONLY);
483b06
+    if (fd != -1) {
483b06
+        len = read(fd, buf, sizeof(buf));
483b06
+        close(fd);
483b06
+        /* Assume FIPS in enabled if PROC_SYS_FIPS contains a non-0 value
483b06
+         * similar to the is_fips_enabled() check in
483b06
+         * ipaplatform/redhat/tasks.py */
483b06
+        if (!(len == 2 && buf[0] == '0' && buf[1] == '\n')) {
483b06
+            return true;
483b06
+        }
483b06
+    }
483b06
+
483b06
+    return false;
483b06
+}
483b06
+
483b06
 static struct ipapwd_krbcfg *ipapwd_getConfig(void)
483b06
 {
483b06
     krb5_error_code krberr;
483b06
@@ -232,23 +255,27 @@ static struct ipapwd_krbcfg *ipapwd_getConfig(void)
483b06
 
483b06
     /* get the ipa etc/ipaConfig entry */
483b06
     config->allow_nt_hash = false;
483b06
-    ret = ipapwd_getEntry(ipa_etc_config_dn, &config_entry, NULL);
483b06
-    if (ret != LDAP_SUCCESS) {
483b06
-        LOG_FATAL("No config Entry?\n");
483b06
-        goto free_and_error;
483b06
+    if (fips_enabled()) {
483b06
+        LOG("FIPS mode is enabled, NT hashes are not allowed.\n");
483b06
     } else {
483b06
-        tmparray = slapi_entry_attr_get_charray(config_entry,
483b06
-                                                "ipaConfigString");
483b06
-        for (i = 0; tmparray && tmparray[i]; i++) {
483b06
-            if (strcasecmp(tmparray[i], "AllowNThash") == 0) {
483b06
-                config->allow_nt_hash = true;
483b06
-                continue;
483b06
+        ret = ipapwd_getEntry(ipa_etc_config_dn, &config_entry, NULL);
483b06
+        if (ret != LDAP_SUCCESS) {
483b06
+            LOG_FATAL("No config Entry?\n");
483b06
+            goto free_and_error;
483b06
+        } else {
483b06
+            tmparray = slapi_entry_attr_get_charray(config_entry,
483b06
+                                                    "ipaConfigString");
483b06
+            for (i = 0; tmparray && tmparray[i]; i++) {
483b06
+                if (strcasecmp(tmparray[i], "AllowNThash") == 0) {
483b06
+                    config->allow_nt_hash = true;
483b06
+                    continue;
483b06
+                }
483b06
             }
483b06
+            if (tmparray) slapi_ch_array_free(tmparray);
483b06
         }
483b06
-        if (tmparray) slapi_ch_array_free(tmparray);
483b06
-    }
483b06
 
483b06
-    slapi_entry_free(config_entry);
483b06
+        slapi_entry_free(config_entry);
483b06
+    }
483b06
 
483b06
     return config;
483b06
 
483b06
-- 
483b06
2.9.4
483b06