File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Expand file tree Collapse file tree 3 files changed +17
-3
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,28 @@ def connection(**kwargs):
166166 )
167167 # Connect.
168168 try :
169+ # Include SSL / TLS, if requested.
170+ if settings .LDAP_AUTH_USE_TLS :
171+ tls = ldap3 .Tls (
172+ ciphers = 'ALL' ,
173+ version = settings .LDAP_AUTH_TLS_VERSION ,
174+ )
175+
169176 c = ldap3 .Connection (
170177 server_pool ,
171178 user = username ,
172179 password = password ,
173180 auto_bind = False ,
174181 raise_exceptions = True ,
175182 receive_timeout = settings .LDAP_AUTH_RECEIVE_TIMEOUT ,
183+ tls = tls ,
176184 )
177185 except LDAPException as ex :
178186 logger .warning ("LDAP connect failed: {ex}" .format (ex = ex ))
179187 yield None
180188 return
181189 # Configure.
182190 try :
183- # Start TLS, if requested.
184- if settings .LDAP_AUTH_USE_TLS :
185- c .start_tls (read_server_info = False )
186191 # Perform initial authentication bind.
187192 c .bind (read_server_info = True )
188193 # 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