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

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