andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0013-Issue-4460-BUG-lib389-should-use-system-tls-policy.patch

27c138
From 389b2c825742392365262a719be7c8f594e7e522 Mon Sep 17 00:00:00 2001
27c138
From: William Brown <william@blackhats.net.au>
27c138
Date: Thu, 26 Nov 2020 09:08:13 +1000
27c138
Subject: [PATCH] Issue 4460 - BUG  - lib389 should use system tls policy
27c138
27c138
Bug Description: Due to some changes in dsrc for tlsreqcert
27c138
and how def open was structured in lib389, the system ldap.conf
27c138
policy was ignored.
27c138
27c138
Fix Description: Default to using the system ldap.conf policy
27c138
if undefined in lib389 or the tls_reqcert param in dsrc.
27c138
27c138
fixes: #4460
27c138
27c138
Author: William Brown <william@blackhats.net.au>
27c138
27c138
Review by: ???
27c138
---
27c138
 src/lib389/lib389/__init__.py      | 11 +++++++----
27c138
 src/lib389/lib389/cli_base/dsrc.py | 16 +++++++++-------
27c138
 2 files changed, 16 insertions(+), 11 deletions(-)
27c138
27c138
diff --git a/src/lib389/lib389/__init__.py b/src/lib389/lib389/__init__.py
27c138
index 99ea9cc6a..4e6a1905a 100644
27c138
--- a/src/lib389/lib389/__init__.py
27c138
+++ b/src/lib389/lib389/__init__.py
27c138
@@ -962,7 +962,7 @@ class DirSrv(SimpleLDAPObject, object):
27c138
         # Now, we are still an allocated ds object so we can be re-installed
27c138
         self.state = DIRSRV_STATE_ALLOCATED
27c138
 
27c138
-    def open(self, uri=None, saslmethod=None, sasltoken=None, certdir=None, starttls=False, connOnly=False, reqcert=ldap.OPT_X_TLS_HARD,
27c138
+    def open(self, uri=None, saslmethod=None, sasltoken=None, certdir=None, starttls=False, connOnly=False, reqcert=None,
27c138
                 usercert=None, userkey=None):
27c138
         '''
27c138
             It opens a ldap bound connection to dirsrv so that online
27c138
@@ -1025,9 +1025,12 @@ class DirSrv(SimpleLDAPObject, object):
27c138
             try:
27c138
                 # Note this sets LDAP.OPT not SELF. Because once self has opened
27c138
                 # it can NOT change opts on reused (ie restart)
27c138
-                self.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, reqcert)
27c138
-                self.log.debug("Using certificate policy %s", reqcert)
27c138
-                self.log.debug("ldap.OPT_X_TLS_REQUIRE_CERT = %s", reqcert)
27c138
+                if reqcert is not None:
27c138
+                    self.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, reqcert)
27c138
+                    self.log.debug("Using lib389 certificate policy %s", reqcert)
27c138
+                else:
27c138
+                    self.log.debug("Using /etc/openldap/ldap.conf certificate policy")
27c138
+                self.log.debug("ldap.OPT_X_TLS_REQUIRE_CERT = %s", self.get_option(ldap.OPT_X_TLS_REQUIRE_CERT))
27c138
             except ldap.LDAPError as e:
27c138
                 self.log.fatal('TLS negotiation failed: %s', e)
27c138
                 raise e
27c138
diff --git a/src/lib389/lib389/cli_base/dsrc.py b/src/lib389/lib389/cli_base/dsrc.py
27c138
index fec18a5f9..9b09ea568 100644
27c138
--- a/src/lib389/lib389/cli_base/dsrc.py
27c138
+++ b/src/lib389/lib389/cli_base/dsrc.py
27c138
@@ -45,7 +45,7 @@ def dsrc_arg_concat(args, dsrc_inst):
27c138
             'tls_cacertdir': None,
27c138
             'tls_cert': None,
27c138
             'tls_key': None,
27c138
-            'tls_reqcert': ldap.OPT_X_TLS_HARD,
27c138
+            'tls_reqcert': None,
27c138
             'starttls': args.starttls,
27c138
             'prompt': False,
27c138
             'pwdfile': None,
27c138
@@ -134,7 +134,7 @@ def dsrc_to_ldap(path, instance_name, log):
27c138
     dsrc_inst['binddn'] = config.get(instance_name, 'binddn', fallback=None)
27c138
     dsrc_inst['saslmech'] = config.get(instance_name, 'saslmech', fallback=None)
27c138
     if dsrc_inst['saslmech'] is not None and dsrc_inst['saslmech'] not in ['EXTERNAL', 'PLAIN']:
27c138
-        raise Exception("%s [%s] saslmech must be one of EXTERNAL or PLAIN" % (path, instance_name))
27c138
+        raise ValueError("%s [%s] saslmech must be one of EXTERNAL or PLAIN" % (path, instance_name))
27c138
 
27c138
     dsrc_inst['tls_cacertdir'] = config.get(instance_name, 'tls_cacertdir', fallback=None)
27c138
     # At this point, we should check if the provided cacertdir is indeed, a dir. This can be a cause
27c138
@@ -145,16 +145,18 @@ def dsrc_to_ldap(path, instance_name, log):
27c138
 
27c138
     dsrc_inst['tls_cert'] = config.get(instance_name, 'tls_cert', fallback=None)
27c138
     dsrc_inst['tls_key'] = config.get(instance_name, 'tls_key', fallback=None)
27c138
-    dsrc_inst['tls_reqcert'] = config.get(instance_name, 'tls_reqcert', fallback='hard')
27c138
-    if dsrc_inst['tls_reqcert'] not in ['never', 'allow', 'hard']:
27c138
-        raise Exception("dsrc tls_reqcert value invalid. %s [%s] tls_reqcert should be one of never, allow or hard" % (instance_name,
27c138
-                                                                                                                       path))
27c138
+    dsrc_inst['tls_reqcert'] = config.get(instance_name, 'tls_reqcert', fallback=None)
27c138
     if dsrc_inst['tls_reqcert'] == 'never':
27c138
         dsrc_inst['tls_reqcert'] = ldap.OPT_X_TLS_NEVER
27c138
     elif dsrc_inst['tls_reqcert'] == 'allow':
27c138
         dsrc_inst['tls_reqcert'] = ldap.OPT_X_TLS_ALLOW
27c138
-    else:
27c138
+    elif dsrc_inst['tls_reqcert'] == 'hard':
27c138
         dsrc_inst['tls_reqcert'] = ldap.OPT_X_TLS_HARD
27c138
+    elif dsrc_inst['tls_reqcert'] is None:
27c138
+        # Use system value
27c138
+        pass
27c138
+    else:
27c138
+        raise ValueError("dsrc tls_reqcert value invalid. %s [%s] tls_reqcert should be one of never, allow or hard" % (instance_name, path))
27c138
     dsrc_inst['starttls'] = config.getboolean(instance_name, 'starttls', fallback=False)
27c138
     dsrc_inst['pwdfile'] = None
27c138
     dsrc_inst['prompt'] = False
27c138
-- 
27c138
2.26.2
27c138