Skip to content

Commit 948319e

Browse files
authored
Merge pull request #246 from FlipperPA/bugfix/tls-on-server-not-connection
Bug fix: TLS object must go on the server, not connection.
2 parents 1ed7dd4 + 18d491a commit 948319e

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
django-python3-ldap
22
===================
33

4-
**django-python3-ldap** provides a Django LDAP user authentication backend.
4+
**django-python3-ldap** provides a Django LDAP user authentication backend. Python 3.6+ is required.
55

66

77
Features

django_python3_ldap/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Settings used by django-python3.
33
"""
4+
from ssl import PROTOCOL_TLS
45

56
from django.conf import settings
67

@@ -45,7 +46,7 @@ def __init__(self, settings):
4546

4647
LDAP_AUTH_TLS_VERSION = LazySetting(
4748
name="LDAP_AUTH_TLS_VERSION",
48-
default="SSLv3",
49+
default=PROTOCOL_TLS,
4950
)
5051

5152
LDAP_AUTH_SEARCH_BASE = LazySetting(

django_python3_ldap/ldap.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,29 +156,32 @@ def connection(**kwargs):
156156
if not isinstance(auth_url, list):
157157
auth_url = [auth_url]
158158
for u in auth_url:
159+
# Include SSL / TLS, if requested.
160+
server_args = {
161+
"allowed_referral_hosts": [("*", True)],
162+
"get_info": ldap3.NONE,
163+
"connect_timeout": settings.LDAP_AUTH_CONNECT_TIMEOUT,
164+
}
165+
if settings.LDAP_AUTH_USE_TLS:
166+
server_args["tls"] = ldap3.Tls(
167+
ciphers="ALL",
168+
version=settings.LDAP_AUTH_TLS_VERSION,
169+
)
159170
server_pool.add(
160171
ldap3.Server(
161172
u,
162-
allowed_referral_hosts=[("*", True)],
163-
get_info=ldap3.NONE,
164-
connect_timeout=settings.LDAP_AUTH_CONNECT_TIMEOUT,
173+
**server_args,
165174
)
166175
)
167176
# Connect.
168177
try:
169-
# Include SSL / TLS, if requested.
170178
connection_args = {
171179
"user": username,
172180
"password": password,
173181
"auto_bind": False,
174182
"raise_exceptions": True,
175183
"receive_timeout": settings.LDAP_AUTH_RECEIVE_TIMEOUT,
176184
}
177-
if settings.LDAP_AUTH_USE_TLS:
178-
connection_args["tls"] = ldap3.Tls(
179-
ciphers='ALL',
180-
version=settings.LDAP_AUTH_TLS_VERSION,
181-
)
182185
c = ldap3.Connection(
183186
server_pool,
184187
**connection_args,

0 commit comments

Comments
 (0)