Blame SOURCES/0029-Ticket-49454-SSL-Client-Authentication-breaks-in-FIP.patch

081b2d
From b1dfe53aaf7cb0260286423b9abf7d71f8edd421 Mon Sep 17 00:00:00 2001
081b2d
From: Mark Reynolds <mreynolds@redhat.com>
081b2d
Date: Wed, 15 Nov 2017 13:27:58 -0500
081b2d
Subject: [PATCH] Ticket 49454 - SSL Client Authentication breaks in FIPS mode
081b2d
081b2d
Bug Description:  Replication using SSL Client Auth breaks when FIPS
081b2d
                  is enabled.  This is because FIPS mode changes the
081b2d
                  internal certificate token name.
081b2d
081b2d
Fix Description:  If FIPS is enabled grab the token name from the internal
081b2d
                  slot instead of using the default hardcoded internal
081b2d
                  token name.
081b2d
081b2d
https://pagure.io/389-ds-base/issue/49454
081b2d
081b2d
Reviewed by: firstyear(Thanks!)
081b2d
081b2d
(cherry picked from commit 6e794a8eff213d49c933f781006e234984160db2)
081b2d
---
081b2d
 ldap/servers/slapd/proto-slap.h        |  1 +
081b2d
 ldap/servers/slapd/security_wrappers.c |  6 ++++++
081b2d
 ldap/servers/slapd/ssl.c               | 24 +++++++++++++++++-------
081b2d
 3 files changed, 24 insertions(+), 7 deletions(-)
081b2d
081b2d
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
081b2d
index 4a30def8b..3b7ab53b2 100644
081b2d
--- a/ldap/servers/slapd/proto-slap.h
081b2d
+++ b/ldap/servers/slapd/proto-slap.h
081b2d
@@ -1130,6 +1130,7 @@ PRBool slapd_pk11_DoesMechanism(PK11SlotInfo *slot, CK_MECHANISM_TYPE type);
081b2d
 PK11SymKey *slapd_pk11_PubUnwrapSymKeyWithFlagsPerm(SECKEYPrivateKey *wrappingKey, SECItem *wrappedKey, CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation, int keySize, CK_FLAGS flags, PRBool isPerm);
081b2d
 PK11SymKey *slapd_pk11_TokenKeyGenWithFlags(PK11SlotInfo *slot, CK_MECHANISM_TYPE type, SECItem *param, int keySize, SECItem *keyid, CK_FLAGS opFlags, PK11AttrFlags attrFlags, void *wincx);
081b2d
 CK_MECHANISM_TYPE slapd_PK11_GetPBECryptoMechanism(SECAlgorithmID *algid, SECItem **params, SECItem *pwitem);
081b2d
+char *slapd_PK11_GetTokenName(PK11SlotInfo *slot);
081b2d
 
081b2d
 /*
081b2d
  * start_tls_extop.c
081b2d
diff --git a/ldap/servers/slapd/security_wrappers.c b/ldap/servers/slapd/security_wrappers.c
081b2d
index bec28d2f3..41fe03608 100644
081b2d
--- a/ldap/servers/slapd/security_wrappers.c
081b2d
+++ b/ldap/servers/slapd/security_wrappers.c
081b2d
@@ -401,3 +401,9 @@ slapd_PK11_GetPBECryptoMechanism(SECAlgorithmID *algid, SECItem **params, SECIte
081b2d
 {
081b2d
     return PK11_GetPBECryptoMechanism(algid, params, pwitem);
081b2d
 }
081b2d
+
081b2d
+char *
081b2d
+slapd_PK11_GetTokenName(PK11SlotInfo *slot)
081b2d
+{
081b2d
+    return PK11_GetTokenName(slot);
081b2d
+}
081b2d
diff --git a/ldap/servers/slapd/ssl.c b/ldap/servers/slapd/ssl.c
081b2d
index efe32d5d0..52ac7ea9f 100644
081b2d
--- a/ldap/servers/slapd/ssl.c
081b2d
+++ b/ldap/servers/slapd/ssl.c
081b2d
@@ -2365,13 +2365,23 @@ slapd_SSL_client_auth(LDAP *ld)
081b2d
                 ssltoken = slapi_entry_attr_get_charptr(entry, "nsssltoken");
081b2d
                 if (ssltoken && personality) {
081b2d
                     if (!PL_strcasecmp(ssltoken, "internal") ||
081b2d
-                        !PL_strcasecmp(ssltoken, "internal (software)")) {
081b2d
-
081b2d
-                        /* Translate config internal name to more
081b2d
-                          * readable form.  Certificate name is just
081b2d
-                          * the personality for internal tokens.
081b2d
-                          */
081b2d
-                        token = slapi_ch_strdup(internalTokenName);
081b2d
+                        !PL_strcasecmp(ssltoken, "internal (software)"))
081b2d
+                    {
081b2d
+                        if ( slapd_pk11_isFIPS() ) {
081b2d
+                            /*
081b2d
+                             * FIPS mode changes the internal token name, so we need to
081b2d
+                             * grab the new token name from the internal slot.
081b2d
+                             */
081b2d
+                            PK11SlotInfo *slot = slapd_pk11_getInternalSlot();
081b2d
+                            token = slapi_ch_strdup(slapd_PK11_GetTokenName(slot));
081b2d
+                            PK11_FreeSlot(slot);
081b2d
+                        } else {
081b2d
+                            /*
081b2d
+                             * Translate config internal name to more readable form.
081b2d
+                             * Certificate name is just the personality for internal tokens.
081b2d
+                             */
081b2d
+                            token = slapi_ch_strdup(internalTokenName);
081b2d
+                        }
081b2d
 #if defined(USE_OPENLDAP)
081b2d
                         /* openldap needs tokenname:certnick */
081b2d
                         PR_snprintf(cert_name, sizeof(cert_name), "%s:%s", token, personality);
081b2d
-- 
081b2d
2.13.6
081b2d