luqasz/librouteros

Connect with valid SSL certificate

Closed this issue · 2 comments

Hi,

I can't connect to ROS without ctx.check_hostname = False. I have trusted certificate authority signed SSL certificate installed.

from librouteros import connect
import ssl

ctx = ssl.create_default_context()
api = connect(
    username='admin',
    password='',
    host='example.com',
    ssl_wrapper=ctx.wrap_socket,
    port=8729,
)

I got error:

Traceback (most recent call last):
  File "~/mikrotik/libros.py", line 12, in <module>
    port=8729
  File "~/mikrotik/venv/lib/python3.7/site-packages/librouteros/__init__.py", line 46, in connect
    transport = create_transport(host, **arguments)
  File "~/mikrotik/venv/lib/python3.7/site-packages/librouteros/__init__.py", line 60, in create_transport
    sock = kwargs['ssl_wrapper'](sock)
  File "/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 423, in wrap_socket
    session=session
  File "/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 827, in _create
    raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname

I am using macOS 10.15.4 with Python 3.7.7
Thanks.

This is out of scope of this library. Refer to python ssl docs as it is pure SSL issue.

Hi,

I think add the server_hostname parameter to this line will fix the problem.
Thanks.