ussl.rst 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. :mod:`ussl` -- SSL/TLS module
  2. =============================
  3. .. module:: ussl
  4. :synopsis: TLS/SSL wrapper for socket objects
  5. |see_cpython_module| :mod:`python:ssl`.
  6. This module provides access to Transport Layer Security (previously and
  7. widely known as “Secure Sockets Layer”) encryption and peer authentication
  8. facilities for network sockets, both client-side and server-side.
  9. Functions
  10. ---------
  11. .. function:: ussl.wrap_socket(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=CERT_NONE, ca_certs=None)
  12. Takes a `stream` *sock* (usually usocket.socket instance of ``SOCK_STREAM`` type),
  13. and returns an instance of ssl.SSLSocket, which wraps the underlying stream in
  14. an SSL context. Returned object has the usual `stream` interface methods like
  15. ``read()``, ``write()``, etc. In MicroPython, the returned object does not expose
  16. socket interface and methods like ``recv()``, ``send()``. In particular, a
  17. server-side SSL socket should be created from a normal socket returned from
  18. :meth:`~usocket.socket.accept()` on a non-SSL listening server socket.
  19. Depending on the underlying module implementation in a particular
  20. `MicroPython port`, some or all keyword arguments above may be not supported.
  21. .. warning::
  22. Some implementations of ``ussl`` module do NOT validate server certificates,
  23. which makes an SSL connection established prone to man-in-the-middle attacks.
  24. Exceptions
  25. ----------
  26. .. data:: ssl.SSLError
  27. This exception does NOT exist. Instead its base class, OSError, is used.
  28. Constants
  29. ---------
  30. .. data:: ussl.CERT_NONE
  31. ussl.CERT_OPTIONAL
  32. ussl.CERT_REQUIRED
  33. Supported values for *cert_reqs* parameter.