<div dir="ltr">I really like python3-ldap. Much cleaner than building on top of OpenLDAP :)<div><br></div><div>I can get TLS working on port 636, but I can't figure out how to get Start TLS on port 389. Here's what I have so far (Python 2.7):</div>
<div><br></div><div><div>01 import ldap3</div><div>02 import os</div><div>03 import ssl</div><div>04 </div><div>05 host = "ldap.*************.net"</div><div>06 port = 389</div><div>07 username = "cn=admin,dc=*************,dc=net"</div>
<div>08 password = "*************"</div><div>09 base_path = os.path.dirname(os.path.realpath(__file__))</div><div>10 </div><div>11 tls = ldap3.Tls(validate=ssl.CERT_REQUIRED, ca_certs_file=os.path.join(base_path, "goodca"))</div>
<div>12 ldap_server = ldap3.Server(host, port=port, use_ssl=False, tls=tls)</div><div>13 ldap_handle = ldap3.Connection(ldap_server, user=username, password=password)</div><div>14 ldap_handle.open()</div><div>15 ldap_handle.start_tls()</div>
<div>16 ldap_handle.bind()</div></div><div><br></div><div>I'm ~100% sure that "goodca" is not the problem, because I've validated it with openssl s_client, gnutls-cli, ldapsearch, and python-ldap. It's PEM encoded. When I run this example, I get this exception:</div>
<div><br></div><div><div>mhaase@luci:~/luci/bin$ python test.py</div><div>Traceback (most recent call last):</div><div> File "test.py", line 15, in <module></div><div> ldap_handle.start_tls()</div><div>
File "/usr/local/lib/python2.7/dist-packages/ldap3/core/connection.py", line 535, in start_tls</div><div> if self.server.tls.start_tls(self):</div><div> File "/usr/local/lib/python2.7/dist-packages/ldap3/core/tls.py", line 118, in start_tls</div>
<div> return self._start_tls(connection)</div><div> File "/usr/local/lib/python2.7/dist-packages/ldap3/core/tls.py", line 121, in _start_tls</div><div> connection.socket = self.wrap_socket(connection, False)</div>
<div> File "/usr/local/lib/python2.7/dist-packages/ldap3/core/tls.py", line 91, in wrap_socket</div><div> check_hostname(wrapped_socket, connection.server.host, self.valid_names)</div><div> File "/usr/local/lib/python2.7/dist-packages/ldap3/core/tls.py", line 206, in check_hostname</div>
<div> match_hostname_backport(server_certificate, host_name)</div><div> File "/usr/local/lib/python2.7/dist-packages/ldap3/core/tls.py", line 168, in match_hostname_backport</div><div> raise ValueError("empty or no certificate")</div>
<div>ValueError: empty or no certificate</div></div><div><br></div><div>Any ideas what I'm doing wrong? Any help would be greatly appreciated... I've been struggling with openldap/python-ldap/python3-for 12 hours today!!</div>
</div>