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

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