Skip to content

Commit bea610e

Browse files
authored
Merge pull request #275 from Freddo3000/feature/tls-settings
Add additional Tls/SSL arguments
2 parents 8285859 + 162fa56 commit bea610e

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ Available settings
4141
import ssl
4242
LDAP_AUTH_TLS_VERSION = ssl.PROTOCOL_TLSv1_2
4343
44+
# Specify which TLS ciphers to use.
45+
LDAP_AUTH_TLS_CIPHERS = "ALL"
46+
47+
# Unspecified TLS keyword arguments applied to the connection on the underlying `ldap3` library.
48+
LDAP_AUTH_TLS_ARGS = {}
49+
4450
# The LDAP search base for looking up users.
4551
LDAP_AUTH_SEARCH_BASE = "ou=people,dc=example,dc=com"
4652
@@ -90,10 +96,16 @@ Available settings
9096
LDAP_AUTH_CONNECTION_USERNAME = None
9197
LDAP_AUTH_CONNECTION_PASSWORD = None
9298
99+
# Use SSL on the connection.
100+
LDAP_AUTH_CONNECT_USE_SSL = False
101+
93102
# Set connection/receive timeouts (in seconds) on the underlying `ldap3` library.
94103
LDAP_AUTH_CONNECT_TIMEOUT = None
95104
LDAP_AUTH_RECEIVE_TIMEOUT = None
96105
106+
# Unspecified keyword arguments to apply to the connection in the underlying `ldap3` library.
107+
LDAP_AUTH_CONNECT_ARGS = {}
108+
97109
# Set connection pool `active` parameter on the underlying `ldap3` library.
98110
LDAP_AUTH_POOL_ACTIVE = True
99111

django_python3_ldap/conf.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ def __init__(self, settings):
4444
default=False,
4545
)
4646

47+
LDAP_AUTH_TLS_CIPHERS = LazySetting(
48+
name="LDAP_AUTH_TLS_CIPHERS",
49+
default="ALL",
50+
)
51+
4752
LDAP_AUTH_TLS_VERSION = LazySetting(
4853
name="LDAP_AUTH_TLS_VERSION",
4954
default=PROTOCOL_TLS,
5055
)
5156

57+
LDAP_AUTH_TLS_ARGS = LazySetting(
58+
name="LDAP_AUTH_TLS_ARGS",
59+
default={},
60+
)
61+
5262
LDAP_AUTH_SEARCH_BASE = LazySetting(
5363
name="LDAP_AUTH_SEARCH_BASE",
5464
default="ou=people,dc=example,dc=com",
@@ -126,6 +136,16 @@ def __init__(self, settings):
126136
default=None,
127137
)
128138

139+
LDAP_AUTH_CONNECT_ARGS = LazySetting(
140+
name="LDAP_AUTH_CONNECT_ARGS",
141+
default={},
142+
)
143+
144+
LDAP_AUTH_CONNECT_USE_SSL = LazySetting(
145+
name="LDAP_AUTH_CONNECT_USE_SSL",
146+
default=False,
147+
)
148+
129149
LDAP_AUTH_CONNECT_TIMEOUT = LazySetting(
130150
name="LDAP_AUTH_CONNECT_TIMEOUT",
131151
default=None

django_python3_ldap/ldap.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,14 @@ def connection(**kwargs):
176176
"allowed_referral_hosts": [("*", True)],
177177
"get_info": ldap3.NONE,
178178
"connect_timeout": settings.LDAP_AUTH_CONNECT_TIMEOUT,
179+
"use_ssl": settings.LDAP_AUTH_CONNECT_USE_SSL,
180+
**settings.LDAP_AUTH_CONNECT_ARGS
179181
}
180182
if settings.LDAP_AUTH_USE_TLS:
181183
server_args["tls"] = ldap3.Tls(
182-
ciphers="ALL",
184+
ciphers=settings.LDAP_AUTH_TLS_CIPHERS,
183185
version=settings.LDAP_AUTH_TLS_VERSION,
186+
**settings.LDAP_AUTH_TLS_ARGS
184187
)
185188
server_pool.add(
186189
ldap3.Server(

0 commit comments

Comments
 (0)