[PATCH] Revert "Issue 3584 - Fix PBKDF2_SHA256 hashing in FIPS mode (#4949)"
authorTimo Aaltonen <tjaalton@debian.org>
Wed, 15 Dec 2021 19:40:38 +0000 (21:40 +0200)
committerTimo Aaltonen <tjaalton@debian.org>
Wed, 13 Apr 2022 11:11:20 +0000 (12:11 +0100)
This reverts commit b0d06615e1117799ec156d51489cd49c92635cca.

Gbp-Pq: Name 0001-Revert-Issue-3584-Fix-PBKDF2_SHA256-hashing-in-FIPS-.patch

dirsrvtests/tests/suites/healthcheck/health_security_test.py
ldap/ldif/template-dse-minimal.ldif.in
ldap/ldif/template-dse.ldif.in
ldap/servers/plugins/pwdstorage/pbkdf2_pwd.c
ldap/servers/slapd/main.c
src/lib389/lib389/__init__.py
src/lib389/lib389/topologies.py
src/lib389/lib389/utils.py

index fa3c28615cf185c15fb6218702b75ed6fb3103a9..a07371e0e2599fb3d51a39037068303a171f705e 100644 (file)
@@ -31,6 +31,16 @@ libfaketime.reexec_if_needed()
 log = logging.getLogger(__name__)
 
 
+def is_fips():
+    if os.path.exists('/proc/sys/crypto/fips_enabled'):
+        with open('/proc/sys/crypto/fips_enabled', 'r') as f:
+            state = f.readline().strip()
+            if state == '1':
+                return True
+            else:
+                return False
+
+
 def run_healthcheck_and_flush_log(topology, instance, searched_code, json, searched_code2=None):
     args = FakeArgs()
     args.instance = instance.serverid
index a1700a2daf3de69d1fe1b2bdb801535deb2d732f..5d424fbf52db5c74bbce626792aaebe85b60c8c8 100644 (file)
@@ -185,58 +185,6 @@ nsslapd-plugininitfunc: pbkdf2_sha256_pwd_storage_scheme_init
 nsslapd-plugintype: pwdstoragescheme
 nsslapd-pluginenabled: on
 
-dn: cn=PBKDF2,cn=Password Storage Schemes,cn=plugins,cn=config
-objectclass: top
-objectclass: nsSlapdPlugin
-cn: PBKDF2
-nsslapd-pluginpath: libpwdchan-plugin
-nsslapd-plugininitfunc: pwdchan_pbkdf2_plugin_init
-nsslapd-plugintype: pwdstoragescheme
-nsslapd-pluginenabled: on
-nsslapd-pluginId: PBKDF2
-nsslapd-pluginVersion: none
-nsslapd-pluginVendor: 389 Project
-nsslapd-pluginDescription: PBKDF2
-
-dn: cn=PBKDF2-SHA1,cn=Password Storage Schemes,cn=plugins,cn=config
-objectclass: top
-objectclass: nsSlapdPlugin
-cn: PBKDF2-SHA1
-nsslapd-pluginpath: libpwdchan-plugin
-nsslapd-plugininitfunc: pwdchan_pbkdf2_sha1_plugin_init
-nsslapd-plugintype: pwdstoragescheme
-nsslapd-pluginenabled: on
-nsslapd-pluginId: PBKDF2-SHA1
-nsslapd-pluginVersion: none
-nsslapd-pluginVendor: 389 Project
-nsslapd-pluginDescription: PBKDF2-SHA1\
-
-dn: cn=PBKDF2-SHA256,cn=Password Storage Schemes,cn=plugins,cn=config
-objectclass: top
-objectclass: nsSlapdPlugin
-cn: PBKDF2-SHA256
-nsslapd-pluginpath: libpwdchan-plugin
-nsslapd-plugininitfunc: pwdchan_pbkdf2_sha256_plugin_init
-nsslapd-plugintype: pwdstoragescheme
-nsslapd-pluginenabled: on
-nsslapd-pluginId: PBKDF2-SHA256
-nsslapd-pluginVersion: none
-nsslapd-pluginVendor: 389 Project
-nsslapd-pluginDescription: PBKDF2-SHA256\
-
-dn: cn=PBKDF2-SHA512,cn=Password Storage Schemes,cn=plugins,cn=config
-objectclass: top
-objectclass: nsSlapdPlugin
-cn: PBKDF2-SHA512
-nsslapd-pluginpath: libpwdchan-plugin
-nsslapd-plugininitfunc: pwdchan_pbkdf2_sha512_plugin_init
-nsslapd-plugintype: pwdstoragescheme
-nsslapd-pluginenabled: on
-nsslapd-pluginId: PBKDF2-SHA512
-nsslapd-pluginVersion: none
-nsslapd-pluginVendor: 389 Project
-nsslapd-pluginDescription: PBKDF2-SHA512
-
 dn: cn=AES,cn=Password Storage Schemes,cn=plugins,cn=config
 objectclass: top
 objectclass: nsSlapdPlugin
index 1456761e51f3f07e236fac2e517a20fdea04b2c5..892f62c6b683f729484f5ee2f2ba6f734794d027 100644 (file)
@@ -232,58 +232,6 @@ nsslapd-plugininitfunc: pbkdf2_sha256_pwd_storage_scheme_init
 nsslapd-plugintype: pwdstoragescheme
 nsslapd-pluginenabled: on
 
-dn: cn=PBKDF2,cn=Password Storage Schemes,cn=plugins,cn=config
-objectclass: top
-objectclass: nsSlapdPlugin
-cn: PBKDF2
-nsslapd-pluginpath: libpwdchan-plugin
-nsslapd-plugininitfunc: pwdchan_pbkdf2_plugin_init
-nsslapd-plugintype: pwdstoragescheme
-nsslapd-pluginenabled: on
-nsslapd-pluginId: PBKDF2
-nsslapd-pluginVersion: none
-nsslapd-pluginVendor: 389 Project
-nsslapd-pluginDescription: PBKDF2
-
-dn: cn=PBKDF2-SHA1,cn=Password Storage Schemes,cn=plugins,cn=config
-objectclass: top
-objectclass: nsSlapdPlugin
-cn: PBKDF2-SHA1
-nsslapd-pluginpath: libpwdchan-plugin
-nsslapd-plugininitfunc: pwdchan_pbkdf2_sha1_plugin_init
-nsslapd-plugintype: pwdstoragescheme
-nsslapd-pluginenabled: on
-nsslapd-pluginId: PBKDF2-SHA1
-nsslapd-pluginVersion: none
-nsslapd-pluginVendor: 389 Project
-nsslapd-pluginDescription: PBKDF2-SHA1\
-
-dn: cn=PBKDF2-SHA256,cn=Password Storage Schemes,cn=plugins,cn=config
-objectclass: top
-objectclass: nsSlapdPlugin
-cn: PBKDF2-SHA256
-nsslapd-pluginpath: libpwdchan-plugin
-nsslapd-plugininitfunc: pwdchan_pbkdf2_sha256_plugin_init
-nsslapd-plugintype: pwdstoragescheme
-nsslapd-pluginenabled: on
-nsslapd-pluginId: PBKDF2-SHA256
-nsslapd-pluginVersion: none
-nsslapd-pluginVendor: 389 Project
-nsslapd-pluginDescription: PBKDF2-SHA256\
-
-dn: cn=PBKDF2-SHA512,cn=Password Storage Schemes,cn=plugins,cn=config
-objectclass: top
-objectclass: nsSlapdPlugin
-cn: PBKDF2-SHA512
-nsslapd-pluginpath: libpwdchan-plugin
-nsslapd-plugininitfunc: pwdchan_pbkdf2_sha512_plugin_init
-nsslapd-plugintype: pwdstoragescheme
-nsslapd-pluginenabled: on
-nsslapd-pluginId: PBKDF2-SHA512
-nsslapd-pluginVersion: none
-nsslapd-pluginVendor: 389 Project
-nsslapd-pluginDescription: PBKDF2-SHA512
-
 dn: cn=AES,cn=Password Storage Schemes,cn=plugins,cn=config
 objectclass: top
 objectclass: nsSlapdPlugin
index dcac4fcddcde4fd5232a7f9061faa16559624bcb..d310dc7920b971f6790016688cffc4156e0d8583 100644 (file)
@@ -91,11 +91,10 @@ pbkdf2_sha256_extract(char *hash_in, SECItem *salt, uint32_t *iterations)
 SECStatus
 pbkdf2_sha256_hash(char *hash_out, size_t hash_out_len, SECItem *pwd, SECItem *salt, uint32_t iterations)
 {
+    SECItem *result = NULL;
     SECAlgorithmID *algid = NULL;
     PK11SlotInfo *slot = NULL;
     PK11SymKey *symkey = NULL;
-    SECItem *wrapKeyData = NULL;
-    SECStatus rv = SECFailure;
 
     /* We assume that NSS is already started. */
     algid = PK11_CreatePBEV2AlgorithmID(SEC_OID_PKCS5_PBKDF2, SEC_OID_HMAC_SHA256, SEC_OID_HMAC_SHA256, hash_out_len, iterations, salt);
@@ -105,6 +104,7 @@ pbkdf2_sha256_hash(char *hash_out, size_t hash_out_len, SECItem *pwd, SECItem *s
         slot = PK11_GetBestSlotMultiple(mechanism_array, 2, NULL);
         if (slot != NULL) {
             symkey = PK11_PBEKeyGen(slot, algid, pwd, PR_FALSE, NULL);
+            PK11_FreeSlot(slot);
             if (symkey == NULL) {
                 /* We try to get the Error here but NSS has two or more error interfaces, and sometimes it uses none of them. */
                 int32_t status = PORT_GetError();
@@ -123,60 +123,18 @@ pbkdf2_sha256_hash(char *hash_out, size_t hash_out_len, SECItem *pwd, SECItem *s
         return SECFailure;
     }
 
-    /*
-     * First, we need to generate a wrapped key for PK11_Decrypt call:
-     * slot is the same slot we used in PK11_PBEKeyGen()
-     * 256 bits / 8 bit per byte
-     */
-    PK11SymKey *wrapKey = PK11_KeyGen(slot, CKM_AES_ECB, NULL, 256/8, NULL);
-    PK11_FreeSlot(slot);
-    if (wrapKey == NULL) {
-        slapi_log_err(SLAPI_LOG_ERR, "pbkdf2_sha256_hash", "Unable to generate a wrapped key.\n");
-        return SECFailure;
-       }
-
-    wrapKeyData = (SECItem *)PORT_Alloc(sizeof(SECItem));
-    /* Align the wrapped key with 32 bytes. */
-    wrapKeyData->len = (PK11_GetKeyLength(symkey) + 31) & ~31;
-    /* Allocate the aligned space for pkc5PBE key plus AESKey block */
-    wrapKeyData->data = (unsigned char *)slapi_ch_calloc(wrapKeyData->len, sizeof(unsigned char));
-
-    /* Get symkey wrapped with wrapKey - required for PK11_Decrypt call */
-    rv = PK11_WrapSymKey(CKM_AES_ECB, NULL, wrapKey, symkey, wrapKeyData);
-    if (rv != SECSuccess) {
-        PK11_FreeSymKey(symkey);
-        PK11_FreeSymKey(wrapKey);
-        SECITEM_FreeItem(wrapKeyData, PR_TRUE);
-        slapi_log_err(SLAPI_LOG_ERR, "pbkdf2_sha256_hash", "Unable to wrap the symkey. (%d)\n", rv);
-        return SECFailure;
-    }
-
-    /* Allocate the space for our result */
-    void *result = (char *)slapi_ch_calloc(wrapKeyData->len, sizeof(char));
-    unsigned int result_len = 0;
-
-    /* User wrapKey to decrypt the wrapped contents.
-     * result is the hash that we need;
-     * result_len is the actual lengh of the data;
-     * has_out_len is the maximum (the space we allocted for hash_out)
-     */
-    rv = PK11_Decrypt(wrapKey, CKM_AES_ECB, NULL, result, &result_len, hash_out_len, wrapKeyData->data, wrapKeyData->len);
-    PK11_FreeSymKey(symkey);
-    PK11_FreeSymKey(wrapKey);
-    SECITEM_FreeItem(wrapKeyData, PR_TRUE);
-
-    if (rv == SECSuccess) {
-        if (result != NULL && result_len <= hash_out_len) {
-            memcpy(hash_out, result, result_len);
-            slapi_ch_free((void **)&result);
+    if (PK11_ExtractKeyValue(symkey) == SECSuccess) {
+        result = PK11_GetKeyData(symkey);
+        if (result != NULL && result->len <= hash_out_len) {
+            memcpy(hash_out, result->data, result->len);
+            PK11_FreeSymKey(symkey);
         } else {
-            slapi_log_err(SLAPI_LOG_ERR, "pbkdf2_sha256_hash", "Unable to retrieve (get) hash output.\n");
-            slapi_ch_free((void **)&result);
+            PK11_FreeSymKey(symkey);
+            slapi_log_err(SLAPI_LOG_ERR, (char *)schemeName, "Unable to retrieve (get) hash output.\n");
             return SECFailure;
         }
     } else {
-        slapi_log_err(SLAPI_LOG_ERR, "pbkdf2_sha256_hash", "Unable to extract hash output. (%d)\n", rv);
-        slapi_ch_free((void **)&result);
+        slapi_log_err(SLAPI_LOG_ERR, (char *)schemeName, "Unable to extract hash output.\n");
         return SECFailure;
     }
 
index 0ee80e8ca710d0b0b8b148fb20d232254600dc81..79d7a3702eec26675a15119fe28b9ed7d7a03cdc 100644 (file)
@@ -2929,21 +2929,9 @@ slapd_do_all_nss_ssl_init(int slapd_exemode, int importexport_encrypt, int s_por
      * is enabled or not. We use NSS for random number generation and
      * other things even if we are not going to accept SSL connections.
      * We also need NSS for attribute encryption/decryption on import and export.
-     *
-     * It's important to remember that while in FIPS mode the administrator should always enable
-     * the security, otherwise we don't call slapd_pk11_authenticate which is a requirement for FIPS mode
      */
-    PRBool isFIPS = slapd_pk11_isFIPS();
     int init_ssl = config_get_security();
 
-    if (isFIPS && !init_ssl) {
-        slapi_log_err(SLAPI_LOG_WARNING, "slapd_do_all_nss_ssl_init",
-                      "ERROR: TLS is not enabled, and the machine is in FIPS mode. "
-                      "Some functionality won't work correctly (for example, "
-                      "users with PBKDF2_SHA256 password scheme won't be able to log in). "
-                      "It's highly advisable to enable TLS on this instance.\n");
-    }
-
     if (slapd_exemode == SLAPD_EXEMODE_SLAPD) {
         init_ssl = init_ssl && (0 != s_port) && (s_port <= LDAP_PORT_MAX);
     } else {
index 77f9e0e44f38f29ff40deda24d32c09c0e612758..ea0061c3016cd400ca51e8f55f03ac8939fa259b 100644 (file)
@@ -1534,10 +1534,6 @@ class DirSrv(SimpleLDAPObject, object):
         :param post_open: Open the server connection after restart.
         :type post_open: bool
         """
-        if self.config.get_attr_val_utf8_l("nsslapd-security") == 'on':
-            self.restart(post_open=post_open)
-            return
-
         # If it doesn't exist, create a cadb.
         ssca = NssSsl(dbpath=self.get_ssca_dir())
         if not ssca._db_exists():
index 569818fc10b9bc0f005dd4906a9e170489ae8121..db505535f24d61acbb50c828cf876db23d3cc86a 100644 (file)
@@ -11,7 +11,7 @@ import logging
 import socket  # For hostname detection for GSSAPI tests
 import pytest
 from lib389 import DirSrv
-from lib389.utils import generate_ds_params, is_fips
+from lib389.utils import generate_ds_params
 from lib389.mit_krb5 import MitKrb5
 from lib389.saslmap import SaslMappings
 from lib389.replica import ReplicationManager, Replicas
@@ -103,10 +103,6 @@ def _create_instances(topo_dict, suffix):
             if role == ReplicaRole.HUB:
                 hs[instance.serverid] = instance
                 instances.update(hs)
-            # We should always enable TLS while in FIPS mode because otherwise NSS database won't be
-            # configured in a FIPS compliant way
-            if is_fips():
-                instance.enable_tls()
             if DEBUGGING:
                 instance.config.set('nsslapd-errorlog-level','8192')
                 instance.config.set('nsslapd-accesslog-level','260')
index 5445aa7b03e4f96736430e09f64adc52c854ba32..37eeda27360e20db64c5430df2b1903aba5d589b 100644 (file)
@@ -1434,16 +1434,3 @@ def is_valid_hostname(hostname):
         hostname = hostname[:-1] # strip exactly one dot from the right, if present
     allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
     return all(allowed.match(x) for x in hostname.split("."))
-
-
-def is_fips():
-    if os.path.exists('/proc/sys/crypto/fips_enabled'):
-        with open('/proc/sys/crypto/fips_enabled', 'r') as f:
-            state = f.readline().strip()
-            if state == '1':
-                return True
-            else:
-                return False
-    else:
-        return False
-