2
votes

Running python3.6
ldap3-python library
Using OpenLDAP on a docker container osixia/docker-openldap
Port 389 and 636 are open. I can see the connection in the console from python; however, i am getting issues.
Running python on jupyter notebooks on host

I cannot seem to get conn.bind() to work. Here is my code:

from ldap3 import Connection, Server, ALL
 server = Server('127.0.0.1')
 conn = Connection(server, user='cn=admin,dc=example,dc=org', 
 password="admin")
 conn.open()
 conn.bind()

Here is the error:

>-------------------------------------------------------------------------->-
>TypeError                                 Traceback (most recent call last)
><ipython-input-3-5c5644694a2b> in <module>()
      2 conn = Connection(server, user='cn=admin,dc=example,dc=org', password="admin")
      3 conn.open()
----> 4 conn.bind()

>~/anaconda3/lib/python3.6/site-packages/ldap3/core/connection.py in bind(self, read_server_info, controls)
    425                     if log_enabled(PROTOCOL):
    426                         log(PROTOCOL, 'simple BIND request <%s> sent via <%s>', bind_request_to_dict(request), self)
--> 427                     response = self.post_send_single_response(self.send('bindRequest', request, controls))
    428                 elif self.authentication == SASL:
    429                     if self.sasl_mechanism in SASL_AVAILABLE_MECHANISMS:

>~/anaconda3/lib/python3.6/site-packages/ldap3/strategy/sync.py in post_send_single_response(self, message_id)
    120         Returns the result message or None
    121         """
--> 122         responses, result = self.get_response(message_id)
    123         self.connection.result = result
    124         if result['type'] == 'intermediateResponse':  # checks that all responses are intermediates (there should be only one)

>~/anaconda3/lib/python3.6/site-packages/ldap3/strategy/base.py in get_response(self, message_id, timeout)
    296         if self._outstanding and message_id in self._outstanding:
    297             while timeout >= 0:  # waiting for completed message to appear in responses
--> 298                 responses = self._get_response(message_id)
    299                 if not responses:
    300                     sleep(RESPONSE_SLEEPTIME)

>~/anaconda3/lib/python3.6/site-packages/ldap3/strategy/sync.py in _get_response(self, message_id)
    166                             log(EXTENDED, 'ldap message received via <%s>:%s', self.connection, format_ldap_message(ldap_resp, '<<'))
    167                         if int(ldap_resp['messageID']) == message_id:
--> 168                             dict_response = self.decode_response(ldap_resp)
    169                             ldap_responses.append(dict_response)
    170                             if dict_response['type'] not in ['searchResEntry', 'searchResRef', 'intermediateResponse']:

>~/anaconda3/lib/python3.6/site-packages/ldap3/strategy/base.py in decode_response(self, ldap_message)
    401         if message_type == 'bindResponse':
    402             if not bytes(component['matchedDN']).startswith(b'NTLM'):  # patch for microsoft ntlm authentication
--> 403                 result = bind_response_to_dict(component)
    404             else:
    405                 result = sicily_bind_response_to_dict(component)

>~/anaconda3/lib/python3.6/site-packages/ldap3/operation/bind.py in bind_response_to_dict(response)
    117             'message': str(response['diagnosticMessage']),
    118             'referrals': referrals_to_list(response['referral']),
--> 119             'saslCreds': bytes(response['serverSaslCreds']) if response['serverSaslCreds'] is not None else None}
    120 
    121 

>~/anaconda3/lib/python3.6/site-packages/pyasn1/type/univ.py in __bytes__(self)
    888 
    889         def __bytes__(self):
--> 890             return bytes(self._value)
    891 
    892         def asOctets(self):

>TypeError: cannot convert 'NoValue' object to bytes

I see the connection happening on my ldap server:

ldap_1 | 5a794f6d conn=1045 fd=15 ACCEPT from IP=172.20.0.1:42060 (IP=0.0.0.0:389) ldap_1 | 5a794f6d conn=1045 op=0 BIND dn="cn=admin,dc=example,dc=org" method=128 ldap_1 | 5a794f6d conn=1045 op=0 BIND dn="cn=admin,dc=example,dc=org" mech=SIMPLE ssf=0
ldap_1 | 5a794f6d conn=1045 op=0 RESULT tag=97 err=0 text=

when I do a local connection i get results back and this is what i see on the server:

ldap_1 | 5a795085 conn=1046 fd=16 ACCEPT from IP=127.0.0.1:48488 (IP=0.0.0.0:389)
ldap_1 | 5a795085 conn=1046 op=0 BIND dn="cn=admin,dc=example,dc=org" method=128
ldap_1 | 5a795085 conn=1046 op=0 BIND dn="cn=admin,dc=example,dc=org" mech=SIMPLE ssf=0
ldap_1 | 5a795085 conn=1046 op=0 RESULT tag=97 err=0 text=
ldap_1 | 5a795085 conn=1046 op=1 SRCH base="dc=example,dc=org" scope=2 deref=0 filter="(objectClass=*)"
ldap_1 | 5a795085 conn=1046 op=1 SEARCH RESULT tag=101 err=0 nentries=8 text=
ldap_1 | 5a795085 conn=1046 op=2 UNBIND ldap_1 | 5a795085 conn=1046 fd=16 closed

I have been searching for a while trying to get the resolution with no luck. I am hoping someone can help me :D

edit: still working on the issue with no luck :(

1

1 Answers

1
votes

Try to update the latest ldap3 and pyasn1 versions.