Skip to content

Commit 42962fd

Browse files
committed
Check connection properties in LDAPSession.authenticate
If the LDAP server requires TLS stuff, it must be also used when establishing connections for user credentials check
1 parent 4a296cf commit 42962fd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/node/ext/ldap/session.py

+11
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ def authenticate(self, dn, pw):
6868
# Let's bypass connector/communicator until they are sorted out
6969
if self._props.ignore_cert: # pragma: no cover
7070
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
71+
elif self._props.tls_cacertfile: # pragma: no cover
72+
ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, self._props.tls_cacertfile)
73+
elif self._props.tls_cacertdir: # pragma: no cover
74+
ldap.set_option(ldap.OPT_X_TLS_CACERTDIR, self._props.tls_cacertdir)
75+
if self._props.tls_clcertfile and self._props.tls_clkeyfile: # pragma: no cover
76+
ldap.set_option(ldap.OPT_X_TLS_CERTFILE, self._props.tls_clcertfile)
77+
ldap.set_option(ldap.OPT_X_TLS_KEYFILE, self._props.tls_clkeyfile)
78+
elif self._props.tls_clcertfile or self._props.tls_clkeyfile: # pragma: no cover
79+
logger.exception("Only client certificate or key have been provided.")
7180
con = ldap.initialize(
7281
self._props.uri,
7382
bytes_mode=False,
@@ -77,6 +86,8 @@ def authenticate(self, dn, pw):
7786
# Directory More info: https://www.python-ldap.org/faq.html#usage
7887
con.set_option(ldap.OPT_REFERRALS, 0)
7988
try:
89+
if self._props.start_tls:
90+
con.start_tls_s()
8091
con.simple_bind_s(dn, pw)
8192
except (ldap.INVALID_CREDENTIALS, ldap.UNWILLING_TO_PERFORM):
8293
# The UNWILLING_TO_PERFORM event might be thrown, if you query a

0 commit comments

Comments
 (0)