noirello/bonsai

TLS/ldaps ConnectionError: Can't contact LDAP server. (unknown error code) with Asyncio

Closed this issue · 2 comments

Hello! I really appreciate the work you have put into this library!

I am getting an issue where if I try to enable ldaps/TLS in my code, it fails to connect to the server.

When I was using the ldap3 library it would be able to connect to the server with ldaps so I am unsure why I am having this issue.

For example, when I just have TLS enabled:

#!/usr/bin/env python3

import asyncio
import bonsai

async def do():
    client = bonsai.LDAPClient(f"ldap://{remote}", True)
    client.set_credentials("SIMPLE", user=username, password=passphrase)
    async with client.connect(is_async=True) as conn:
        who = await conn.whoami()
        print(who)

loop = asyncio.get_event_loop()
loop.run_until_complete(do())

It returns this Traceback:

Traceback (most recent call last):
  File "./testing.py", line 15, in <module>
    loop.run_until_complete(do())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "./testing.py", line 10, in do
    async with client.connect(is_async=True) as conn:
  File "/home/testing/.local/lib/python3.8/site-packages/bonsai/asyncio/aioconnection.py", line 25, in __aenter__
    return await self.__open_coro
  File "/home/testing/.local/lib/python3.8/site-packages/bonsai/asyncio/aioconnection.py", line 59, in _poll
    raise exc
  File "/home/testing/.local/lib/python3.8/site-packages/bonsai/asyncio/aioconnection.py", line 54, in _poll
    return await asyncio.wait_for(fut, timeout)
  File "/usr/lib/python3.8/asyncio/tasks.py", line 455, in wait_for
    return await fut
  File "/home/testing/.local/lib/python3.8/site-packages/bonsai/asyncio/aioconnection.py", line 40, in _ready
    res = super().get_result(msg_id)
bonsai.errors.ConnectionError: Connect error. (unknown error code) (0xFFF5 [-11])

It shows the same results when I use ldaps.

Do you have any insight into this issue?

Hi, could you check the debug logs? You can turn it on right after the module import with bonsai.set_debug(True, -1).

Wow! Those debug logs are really nice. The issue was due to the certificate expecting a domain name such as website.com but I was giving it the IP address xxx.xxx.xxx.xxx