File tree Expand file tree Collapse file tree 3 files changed +23
-8
lines changed Expand file tree Collapse file tree 3 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,10 @@ Available settings
3737 # Initiate TLS on connection.
3838 LDAP_AUTH_USE_TLS = False
3939
40+ # Specify which TLS version to use (Python 3.10 requires TLSv1 or higher)
41+ import ssl
42+ LDAP_AUTH_TLS_VERSION = ssl.PROTOCOL_TLSv1_2
43+
4044 # The LDAP search base for looking up users.
4145 LDAP_AUTH_SEARCH_BASE = " ou=people,dc=example,dc=com"
4246
Original file line number Diff line number Diff line change @@ -43,6 +43,11 @@ def __init__(self, settings):
4343 default = False ,
4444 )
4545
46+ LDAP_AUTH_TLS_VERSION = LazySetting (
47+ name = "LDAP_AUTH_TLS_VERSION" ,
48+ default = "SSLv3" ,
49+ )
50+
4651 LDAP_AUTH_SEARCH_BASE = LazySetting (
4752 name = "LDAP_AUTH_SEARCH_BASE" ,
4853 default = "ou=people,dc=example,dc=com" ,
Original file line number Diff line number Diff line change @@ -166,23 +166,29 @@ def connection(**kwargs):
166166 )
167167 # Connect.
168168 try :
169+ # Include SSL / TLS, if requested.
170+ connection_args = {
171+ "user" : username ,
172+ "password" : password ,
173+ "auto_bind" : False ,
174+ "raise_exceptions" : True ,
175+ "receive_timeout" : settings .LDAP_AUTH_RECEIVE_TIMEOUT ,
176+ }
177+ if settings .LDAP_AUTH_USE_TLS :
178+ connection_args ["tls" ] = ldap3 .Tls (
179+ ciphers = 'ALL' ,
180+ version = settings .LDAP_AUTH_TLS_VERSION ,
181+ )
169182 c = ldap3 .Connection (
170183 server_pool ,
171- user = username ,
172- password = password ,
173- auto_bind = False ,
174- raise_exceptions = True ,
175- receive_timeout = settings .LDAP_AUTH_RECEIVE_TIMEOUT ,
184+ ** connection_args ,
176185 )
177186 except LDAPException as ex :
178187 logger .warning ("LDAP connect failed: {ex}" .format (ex = ex ))
179188 yield None
180189 return
181190 # Configure.
182191 try :
183- # Start TLS, if requested.
184- if settings .LDAP_AUTH_USE_TLS :
185- c .start_tls (read_server_info = False )
186192 # Perform initial authentication bind.
187193 c .bind (read_server_info = True )
188194 # If the settings specify an alternative username and password for querying, rebind as that.
You can’t perform that action at this time.
0 commit comments