jacobschaer / python-doipclient

Pure Python ISO 13400 Client
MIT License
151 stars 50 forks source link

Use SSL context for wrapping socket #30

Closed sfaiss closed 1 year ago

sfaiss commented 1 year ago

This PR adds fine-grained control over the SSL/TLS-settings. It includes the following changes:

  1. SSL sockets behave slightly different than regular sockets in non-blocking mode. They raise SSLWantWriteError / SSLWantReadError instead of BlockingIOError. (see documentation). _tcp_socket_check() handles those exceptions now as well.
  2. As per the documentation, the old wrap_socket() function is deprecated. Instead, a context with secure default settings is created.
  3. If more control is needed, a preconfigured context can be passed to use_secure (instead of the default context when use_secure=True).

Alternative to 3.: Instead of the option to pass a SSL context directly to use_secure, a new optional keyword-argument could be used as well.

This implementation is working on my side, but I still left "untested" in the docstring until someone else can confirm.

jacobschaer commented 1 year ago

Can you add a blurb/example to the documentation about how you setup with use_secure since you said you had it working on your setup?

Thanks for adding this.

sfaiss commented 1 year ago

Sure, no problem. I just added a new section at the bottom of the main page.

jacobschaer commented 1 year ago

Merged! Thanks for the help and documentation :)