I try to query an Active Directory Server with python which works fine. But now I don't want to send my credentials unencrypted on the wire, so I'd like to use LDAPs. Is there an easy way to do this? All I found till now was that I had to add this option:
l.set_option(ldap.OPT_X_TLS_CACERTFILE,'/path/to/my/Ca.pem')
But I actually don't want to get the CA cert or a correct cert and verify that as well. Sure, from a security perspective I should verify that my communication partner is the correct one, but I don't care on my internal network and want this just easier to handle. If I just change the LDAP URL from ldap to ldaps I get this error:
Traceback (most recent call last):
File "./ldap-to-sql.py", line 21, in <module>
bind = l.simple_bind_s(USERNAME, PASS)
File "/usr/local/lib/python2.7/site-packages/ldap/ldapobject.py", line 214, in simple_bind_s
msgid = self.simple_bind(who,cred,serverctrls,clientctrls)
File "/usr/local/lib/python2.7/site-packages/ldap/ldapobject.py", line 208, in simple_bind
return self._ldap_call(self._l.simple_bind,who,cred,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
File "/usr/local/lib/python2.7/site-packages/ldap/ldapobject.py", line 106, in _ldap_call
result = func(*args,**kwargs)
ldap.SERVER_DOWN: {'info': 'SSLHandshake() failed: misc. bad certificate (-9825)', 'desc': "Can't contact LDAP server"}
2 years ago, hm.... ok, may be too late.
however, try below codes. works for me for python/ldap/active directory/TLS.
i was doing some tests with a Samba4 DC and python ldap module and i've done this example:
The certificate needs the FQDN in CN and be signed by the CA cert to avoid Certs error. Was working until I've added a second DC to same FQDN but if you only have one DC it should work. I don't know how it works on a Windows LDAP, but seems to be similar.
Greetings!!