Blame SOURCES/0063-Ticket-49557-Add-config-option-for-checking-CRL-on-o.patch

b045b9
From 656b141630c5f37a953a75ff05d3a1a30b14eef1 Mon Sep 17 00:00:00 2001
b045b9
From: Mark Reynolds <mreynolds@redhat.com>
b045b9
Date: Thu, 1 Feb 2018 14:28:24 -0500
b045b9
Subject: [PATCH] Ticket 49557 - Add config option for checking CRL on outbound
b045b9
 SSL Connections
b045b9
b045b9
Bug Description:  There are cases where a CRL is not available during an outbound
b045b9
                  replication connection.  This is seen as an error by openldap,
b045b9
                  and the connection fails.
b045b9
b045b9
Fix Description:  Add on/off option for checking the CRL.  The default is not to
b045b9
                  check the CRL.
b045b9
b045b9
https://pagure.io/389-ds-base/issue/49557
b045b9
b045b9
Reviewed by: wibrown, Ludwig Krispenz, Thierry Bordaz
b045b9
---
b045b9
 dirsrvtests/tests/suites/{ssl => tls}/__init__.py  |  0
b045b9
 dirsrvtests/tests/suites/tls/tls_check_crl_test.py | 52 +++++++++++++++++
b045b9
 ldap/schema/01core389.ldif                         |  1 +
b045b9
 ldap/servers/slapd/ldaputil.c                      |  9 ++-
b045b9
 ldap/servers/slapd/libglobs.c                      | 66 +++++++++++++++++++++-
b045b9
 ldap/servers/slapd/proto-slap.h                    |  2 +
b045b9
 ldap/servers/slapd/slap.h                          | 10 +++-
b045b9
 7 files changed, 135 insertions(+), 5 deletions(-)
b045b9
 rename dirsrvtests/tests/suites/{ssl => tls}/__init__.py (100%)
b045b9
 create mode 100644 dirsrvtests/tests/suites/tls/tls_check_crl_test.py
b045b9
b045b9
diff --git a/dirsrvtests/tests/suites/ssl/__init__.py b/dirsrvtests/tests/suites/tls/__init__.py
b045b9
similarity index 100%
b045b9
rename from dirsrvtests/tests/suites/ssl/__init__.py
b045b9
rename to dirsrvtests/tests/suites/tls/__init__.py
b045b9
diff --git a/dirsrvtests/tests/suites/tls/tls_check_crl_test.py b/dirsrvtests/tests/suites/tls/tls_check_crl_test.py
b045b9
new file mode 100644
b045b9
index 000000000..8b4d07f94
b045b9
--- /dev/null
b045b9
+++ b/dirsrvtests/tests/suites/tls/tls_check_crl_test.py
b045b9
@@ -0,0 +1,52 @@
b045b9
+# --- BEGIN COPYRIGHT BLOCK ---
b045b9
+# Copyright (C) 2018 Red Hat, Inc.
b045b9
+# All rights reserved.
b045b9
+#
b045b9
+# License: GPL (version 3 or any later version).
b045b9
+# See LICENSE for details.
b045b9
+# --- END COPYRIGHT BLOCK ---
b045b9
+#
b045b9
+
b045b9
+
b045b9
+import pytest
b045b9
+import ldap
b045b9
+from lib389.topologies import topology_st
b045b9
+
b045b9
+def test_tls_check_crl(topology_st):
b045b9
+    """Test that TLS check_crl configurations work as expected.
b045b9
+
b045b9
+    :id:
b045b9
+    :steps:
b045b9
+        1. Enable TLS
b045b9
+        2. Set invalid value
b045b9
+        3. Set valid values
b045b9
+        4. Check config reset
b045b9
+    :expectedresults:
b045b9
+        1. TlS is setup
b045b9
+        2. The invalid value is rejected
b045b9
+        3. The valid values are used
b045b9
+        4. The value can be reset
b045b9
+    """
b045b9
+    standalone = topology_st.standalone
b045b9
+    # Enable TLS
b045b9
+    standalone.enable_tls()
b045b9
+    # Check all the valid values.
b045b9
+    assert(standalone.config.get_attr_val_utf8('nsslapd-tls-check-crl') == 'none')
b045b9
+    with pytest.raises(ldap.OPERATIONS_ERROR):
b045b9
+        standalone.config.set('nsslapd-tls-check-crl', 'tnhoeutnoeutn')
b045b9
+    assert(standalone.config.get_attr_val_utf8('nsslapd-tls-check-crl') == 'none')
b045b9
+
b045b9
+    standalone.config.set('nsslapd-tls-check-crl', 'peer')
b045b9
+    assert(standalone.config.get_attr_val_utf8('nsslapd-tls-check-crl') == 'peer')
b045b9
+
b045b9
+    standalone.config.set('nsslapd-tls-check-crl', 'none')
b045b9
+    assert(standalone.config.get_attr_val_utf8('nsslapd-tls-check-crl') == 'none')
b045b9
+
b045b9
+    standalone.config.set('nsslapd-tls-check-crl', 'all')
b045b9
+    assert(standalone.config.get_attr_val_utf8('nsslapd-tls-check-crl') == 'all')
b045b9
+
b045b9
+    standalone.config.remove_all('nsslapd-tls-check-crl')
b045b9
+    assert(standalone.config.get_attr_val_utf8('nsslapd-tls-check-crl') == 'none')
b045b9
+
b045b9
+
b045b9
+
b045b9
diff --git a/ldap/schema/01core389.ldif b/ldap/schema/01core389.ldif
b045b9
index ab124c86c..c7f9fef2b 100644
b045b9
--- a/ldap/schema/01core389.ldif
b045b9
+++ b/ldap/schema/01core389.ldif
b045b9
@@ -304,6 +304,7 @@ attributeTypes: ( 2.16.840.1.113730.3.1.2332 NAME 'allowWeakDHParam' DESC 'Netsc
b045b9
 attributeTypes: ( 2.16.840.1.113730.3.1.2333 NAME 'nsds5ReplicaReleaseTimeout' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
b045b9
 attributeTypes: ( 2.16.840.1.113730.3.1.2335 NAME 'nsds5ReplicaIgnoreMissingChange' DESC 'Netscape defined attribute type' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
b045b9
 attributeTypes: ( 2.16.840.1.113730.3.1.2336 NAME 'nsDS5ReplicaBindDnGroupCheckInterval' DESC 'Replication configuration setting for controlling the bind dn group check interval' SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE X-ORIGIN 'Netscape Directory Server' )
b045b9
+attributeTypes: ( 2.16.840.1.113730.3.1.2344 NAME 'nsslapd-tls-check-crl' DESC 'Check CRL when opening outbound TLS connections. Valid options are none, peer, all.' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN '389 Directory Server' )
b045b9
 #
b045b9
 # objectclasses
b045b9
 #
b045b9
diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c
b045b9
index fa9d276a3..2fc2f0615 100644
b045b9
--- a/ldap/servers/slapd/ldaputil.c
b045b9
+++ b/ldap/servers/slapd/ldaputil.c
b045b9
@@ -570,6 +570,7 @@ slapi_ldif_parse_line(
b045b9
 }
b045b9
 
b045b9
 #if defined(USE_OPENLDAP)
b045b9
+
b045b9
 static int
b045b9
 setup_ol_tls_conn(LDAP *ld, int clientauth)
b045b9
 {
b045b9
@@ -602,7 +603,13 @@ setup_ol_tls_conn(LDAP *ld, int clientauth)
b045b9
             }
b045b9
         }
b045b9
         if (slapi_client_uses_openssl(ld)) {
b045b9
-            const int crlcheck = LDAP_OPT_X_TLS_CRL_ALL;
b045b9
+            int32_t crlcheck = LDAP_OPT_X_TLS_CRL_NONE;
b045b9
+            tls_check_crl_t tls_check_state = config_get_tls_check_crl();
b045b9
+            if (tls_check_state == TLS_CHECK_PEER) {
b045b9
+                crlcheck = LDAP_OPT_X_TLS_CRL_PEER;
b045b9
+            } else if (tls_check_state == TLS_CHECK_ALL) {
b045b9
+                crlcheck = LDAP_OPT_X_TLS_CRL_ALL;
b045b9
+            }
b045b9
             /* Sets the CRL evaluation strategy. */
b045b9
             rc = ldap_set_option(ld, LDAP_OPT_X_TLS_CRLCHECK, &crlcheck);
b045b9
             if (rc) {
b045b9
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
b045b9
index c1a765aca..eb6552af1 100644
b045b9
--- a/ldap/servers/slapd/libglobs.c
b045b9
+++ b/ldap/servers/slapd/libglobs.c
b045b9
@@ -157,7 +157,8 @@ typedef enum {
b045b9
     CONFIG_STRING_OR_EMPTY,              /* use an empty string */
b045b9
     CONFIG_SPECIAL_ANON_ACCESS_SWITCH,   /* maps strings to an enumeration */
b045b9
     CONFIG_SPECIAL_VALIDATE_CERT_SWITCH, /* maps strings to an enumeration */
b045b9
-    CONFIG_SPECIAL_UNHASHED_PW_SWITCH    /* unhashed pw: on/off/nolog */
b045b9
+    CONFIG_SPECIAL_UNHASHED_PW_SWITCH,   /* unhashed pw: on/off/nolog */
b045b9
+    CONFIG_SPECIAL_TLS_CHECK_CRL,        /* maps enum tls_check_crl_t to char * */
b045b9
 } ConfigVarType;
b045b9
 
b045b9
 static int32_t config_set_onoff(const char *attrname, char *value, int32_t *configvalue, char *errorbuf, int apply);
b045b9
@@ -1173,7 +1174,15 @@ static struct config_get_and_set
b045b9
     {CONFIG_LOGGING_BACKEND, NULL,
b045b9
      log_set_backend, 0,
b045b9
      (void **)&global_slapdFrontendConfig.logging_backend,
b045b9
-     CONFIG_STRING_OR_EMPTY, NULL, SLAPD_INIT_LOGGING_BACKEND_INTERNAL}};
b045b9
+     CONFIG_STRING_OR_EMPTY, NULL, SLAPD_INIT_LOGGING_BACKEND_INTERNAL},
b045b9
+    {CONFIG_TLS_CHECK_CRL_ATTRIBUTE, config_set_tls_check_crl,
b045b9
+     NULL, 0,
b045b9
+     (void **)&global_slapdFrontendConfig.tls_check_crl,
b045b9
+     CONFIG_SPECIAL_TLS_CHECK_CRL, (ConfigGetFunc)config_get_tls_check_crl,
b045b9
+     "none" /* Allow reset to this value */}
b045b9
+
b045b9
+    /* End config */
b045b9
+    };
b045b9
 
b045b9
 /*
b045b9
  * hashNocaseString - used for case insensitive hash lookups
b045b9
@@ -1506,7 +1515,6 @@ FrontendConfig_init(void)
b045b9
     cfg->maxdescriptors = SLAPD_DEFAULT_MAXDESCRIPTORS;
b045b9
     cfg->groupevalnestlevel = SLAPD_DEFAULT_GROUPEVALNESTLEVEL;
b045b9
     cfg->snmp_index = SLAPD_DEFAULT_SNMP_INDEX;
b045b9
-
b045b9
     cfg->SSLclientAuth = SLAPD_DEFAULT_SSLCLIENTAUTH;
b045b9
 
b045b9
 #ifdef USE_SYSCONF
b045b9
@@ -1524,6 +1532,7 @@ FrontendConfig_init(void)
b045b9
 #endif
b045b9
     init_security = cfg->security = LDAP_OFF;
b045b9
     init_ssl_check_hostname = cfg->ssl_check_hostname = LDAP_ON;
b045b9
+    cfg->tls_check_crl = TLS_CHECK_NONE;
b045b9
     init_return_exact_case = cfg->return_exact_case = LDAP_ON;
b045b9
     init_result_tweak = cfg->result_tweak = LDAP_OFF;
b045b9
     init_attrname_exceptions = cfg->attrname_exceptions = LDAP_OFF;
b045b9
@@ -2042,6 +2051,7 @@ config_set_port(const char *attrname, char *port, char *errorbuf, int apply)
b045b9
     return retVal;
b045b9
 }
b045b9
 
b045b9
+
b045b9
 int
b045b9
 config_set_secureport(const char *attrname, char *port, char *errorbuf, int apply)
b045b9
 {
b045b9
@@ -2073,6 +2083,33 @@ config_set_secureport(const char *attrname, char *port, char *errorbuf, int appl
b045b9
 }
b045b9
 
b045b9
 
b045b9
+int32_t
b045b9
+config_set_tls_check_crl(const char *attrname, char *value, char *errorbuf, int apply)
b045b9
+{
b045b9
+    int32_t retVal = LDAP_SUCCESS;
b045b9
+    /* Default */
b045b9
+    tls_check_crl_t state = TLS_CHECK_NONE;
b045b9
+    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
b045b9
+
b045b9
+    if (strcasecmp(value, "none") == 0) {
b045b9
+        state = TLS_CHECK_NONE;
b045b9
+    } else if (strcasecmp(value, "peer") == 0) {
b045b9
+        state = TLS_CHECK_PEER;
b045b9
+    } else if (strcasecmp(value, "all") == 0) {
b045b9
+        state = TLS_CHECK_ALL;
b045b9
+    } else {
b045b9
+        retVal = LDAP_OPERATIONS_ERROR;
b045b9
+        slapi_create_errormsg(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, "%s: unsupported value: %s", attrname, value);
b045b9
+    }
b045b9
+
b045b9
+    if (retVal == LDAP_SUCCESS && apply) {
b045b9
+        slapi_atomic_store_32((int32_t *)&(slapdFrontendConfig->tls_check_crl), state, __ATOMIC_RELEASE);
b045b9
+    }
b045b9
+
b045b9
+    return retVal;
b045b9
+}
b045b9
+
b045b9
+
b045b9
 int
b045b9
 config_set_SSLclientAuth(const char *attrname, char *value, char *errorbuf, int apply)
b045b9
 {
b045b9
@@ -4591,6 +4628,12 @@ config_set_versionstring(const char *attrname __attribute__((unused)), char *ver
b045b9
 
b045b9
 #define config_copy_strval(s) s ? slapi_ch_strdup(s) : NULL;
b045b9
 
b045b9
+tls_check_crl_t
b045b9
+config_get_tls_check_crl() {
b045b9
+    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
b045b9
+    return (tls_check_crl_t)slapi_atomic_load_32((int32_t *)&(slapdFrontendConfig->tls_check_crl), __ATOMIC_ACQUIRE);
b045b9
+}
b045b9
+
b045b9
 int
b045b9
 config_get_port()
b045b9
 {
b045b9
@@ -7439,6 +7482,23 @@ config_set_value(
b045b9
         slapi_entry_attr_set_int(e, cgas->attr_name, ival);
b045b9
         break;
b045b9
 
b045b9
+    case CONFIG_SPECIAL_TLS_CHECK_CRL:
b045b9
+        if (!value) {
b045b9
+            slapi_entry_attr_set_charptr(e, cgas->attr_name, (char *)cgas->initvalue);
b045b9
+            break;
b045b9
+        }
b045b9
+        tls_check_crl_t state = *(tls_check_crl_t *)value;
b045b9
+
b045b9
+        if (state == TLS_CHECK_ALL) {
b045b9
+            sval = "all";
b045b9
+        } else if (state == TLS_CHECK_PEER) {
b045b9
+            sval = "peer";
b045b9
+        } else {
b045b9
+            sval = "none";
b045b9
+        }
b045b9
+        slapi_entry_attr_set_charptr(e, cgas->attr_name, sval);
b045b9
+        break;
b045b9
+
b045b9
     case CONFIG_SPECIAL_SSLCLIENTAUTH:
b045b9
         if (!value) {
b045b9
             slapi_entry_attr_set_charptr(e, cgas->attr_name, "off");
b045b9
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
b045b9
index 3b7ab53b2..b13334ad1 100644
b045b9
--- a/ldap/servers/slapd/proto-slap.h
b045b9
+++ b/ldap/servers/slapd/proto-slap.h
b045b9
@@ -236,6 +236,7 @@ int config_set_port(const char *attrname, char *port, char *errorbuf, int apply)
b045b9
 int config_set_secureport(const char *attrname, char *port, char *errorbuf, int apply);
b045b9
 int config_set_SSLclientAuth(const char *attrname, char *value, char *errorbuf, int apply);
b045b9
 int config_set_ssl_check_hostname(const char *attrname, char *value, char *errorbuf, int apply);
b045b9
+int32_t config_set_tls_check_crl(const char *attrname, char *value, char *errorbuf, int apply);
b045b9
 int config_set_SSL3ciphers(const char *attrname, char *value, char *errorbuf, int apply);
b045b9
 int config_set_localhost(const char *attrname, char *value, char *errorbuf, int apply);
b045b9
 int config_set_listenhost(const char *attrname, char *value, char *errorbuf, int apply);
b045b9
@@ -397,6 +398,7 @@ void log_disable_hr_timestamps(void);
b045b9
 
b045b9
 int config_get_SSLclientAuth(void);
b045b9
 int config_get_ssl_check_hostname(void);
b045b9
+tls_check_crl_t config_get_tls_check_crl(void);
b045b9
 char *config_get_SSL3ciphers(void);
b045b9
 char *config_get_localhost(void);
b045b9
 char *config_get_listenhost(void);
b045b9
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
b045b9
index 216d94afd..443d90094 100644
b045b9
--- a/ldap/servers/slapd/slap.h
b045b9
+++ b/ldap/servers/slapd/slap.h
b045b9
@@ -443,6 +443,13 @@ typedef void (*VFPV)(); /* takes undefined arguments */
b045b9
 typedef int32_t slapi_onoff_t;
b045b9
 typedef int32_t slapi_int_t;
b045b9
 
b045b9
+typedef enum _tls_check_crl_t {
b045b9
+    TLS_CHECK_NONE = 0,
b045b9
+    TLS_CHECK_PEER = 1,
b045b9
+    TLS_CHECK_ALL = 2,
b045b9
+} tls_check_crl_t;
b045b9
+
b045b9
+
b045b9
 struct subfilt
b045b9
 {
b045b9
     char *sf_type;
b045b9
@@ -2151,6 +2158,7 @@ typedef struct _slapdEntryPoints
b045b9
 #define CONFIG_RUNDIR_ATTRIBUTE "nsslapd-rundir"
b045b9
 #define CONFIG_SSLCLIENTAUTH_ATTRIBUTE "nsslapd-SSLclientAuth"
b045b9
 #define CONFIG_SSL_CHECK_HOSTNAME_ATTRIBUTE "nsslapd-ssl-check-hostname"
b045b9
+#define CONFIG_TLS_CHECK_CRL_ATTRIBUTE "nsslapd-tls-check-crl"
b045b9
 #define CONFIG_HASH_FILTERS_ATTRIBUTE "nsslapd-hash-filters"
b045b9
 #define CONFIG_OUTBOUND_LDAP_IO_TIMEOUT_ATTRIBUTE "nsslapd-outbound-ldap-io-timeout"
b045b9
 #define CONFIG_FORCE_SASL_EXTERNAL_ATTRIBUTE "nsslapd-force-sasl-external"
b045b9
@@ -2263,6 +2271,7 @@ typedef struct _slapdFrontendConfig
b045b9
     slapi_onoff_t security;
b045b9
     int SSLclientAuth;
b045b9
     slapi_onoff_t ssl_check_hostname;
b045b9
+    tls_check_crl_t tls_check_crl;
b045b9
     int validate_cert;
b045b9
     int sizelimit;
b045b9
     int SNMPenabled;
b045b9
@@ -2294,7 +2303,6 @@ typedef struct _slapdFrontendConfig
b045b9
     slapi_onoff_t plugin_track;
b045b9
     slapi_onoff_t moddn_aci;
b045b9
     struct pw_scheme *pw_storagescheme;
b045b9
-
b045b9
     slapi_onoff_t pwpolicy_local;
b045b9
     slapi_onoff_t pw_is_global_policy;
b045b9
     slapi_onoff_t pwpolicy_inherit_global;
b045b9
-- 
b045b9
2.13.6
b045b9