ssl

The ssl module provides SSL contexts to wrap sockets in.

Available on these boards
  • ATMegaZero ESP32-S2
  • Adafruit FunHouse
  • Adafruit MagTag
  • Adafruit Metro ESP32S2
  • Artisense Reference Design RD00
  • BastWiFi
  • CrumpS2
  • ESP 12k NodeMCU
  • Feather ESP32S2 without PSRAM
  • FeatherS2
  • FeatherS2 Neo
  • FeatherS2 PreRelease
  • Franzininho WIFI w/Wroom
  • Franzininho WIFI w/Wrover
  • Gravitech Cucumber M
  • Gravitech Cucumber MS
  • Gravitech Cucumber R
  • Gravitech Cucumber RS
  • HMI-DevKit-1.1
  • Kaluga 1
  • LILYGO TTGO T8 ESP32-S2 w/Display
  • MORPHEANS MorphESP-240
  • Oak Dev Tech PixelWing ESP32S2
  • S2Mini
  • Saola 1 w/Wroom
  • Saola 1 w/Wrover
  • Targett Module Clip w/Wroom
  • Targett Module Clip w/Wrover
  • TinyS2
  • microS2
  • nanoESP32-S2 w/Wrover
  • nanoESP32-S2 w/Wroom

ssl.create_default_context()SSLContext

Return the default SSLContext.

class ssl.SSLContext

Settings related to SSL that can be applied to a socket by wrapping it. This is useful to provide SSL certificates to specific connections rather than all of them.

ssl.wrap_socket(sock: socketpool.Socket, *, server_side: bool = False, server_hostname: Optional[str] = None)SSLSocket

Wraps the socket into a socket-compatible class that handles SSL negotiation. The socket must be of type SOCK_STREAM.

class ssl.SSLSocket

Implements TLS security on a subset of socketpool.Socket functions. Cannot be created directly. Instead, call wrap_socket on an existing socket object.

Provides a subset of CPython’s ssl.SSLSocket API. It only implements the versions of recv that do not allocate bytes objects.

__enter__(self)SSLSocket

No-op used by Context Managers.

__exit__(self)None

Automatically closes the Socket when exiting a context. See Lifetime and ContextManagers for more info.

accept(self)Tuple[SSLSocket, Tuple[str, int]]

Accept a connection on a listening socket of type SOCK_STREAM, creating a new socket of type SOCK_STREAM. Returns a tuple of (new_socket, remote_address)

bind(self, address: Tuple[str, int])None

Bind a socket to an address

Parameters

address (~tuple) – tuple of (remote_address, remote_port)

close(self)None

Closes this Socket

connect(self, address: Tuple[str, int])None

Connect a socket to a remote address

Parameters

address (~tuple) – tuple of (remote_address, remote_port)

listen(self, backlog: int)None

Set socket to listen for incoming connections

Parameters

backlog (~int) – length of backlog queue for waiting connetions

recv_into(self, buffer: _typing.WriteableBuffer, bufsize: int)int

Reads some bytes from the connected remote address, writing into the provided buffer. If bufsize <= len(buffer) is given, a maximum of bufsize bytes will be read into the buffer. If no valid value is given for bufsize, the default is the length of the given buffer.

Suits sockets of type SOCK_STREAM Returns an int of number of bytes read.

Parameters
  • buffer (bytearray) – buffer to receive into

  • bufsize (int) – optionally, a maximum number of bytes to read.

send(self, bytes: _typing.ReadableBuffer)int

Send some bytes to the connected remote address. Suits sockets of type SOCK_STREAM

Parameters

bytes (~bytes) – some bytes to send

settimeout(self, value: int)None

Set the timeout value for this socket.

Parameters

value (~int) – timeout in seconds. 0 means non-blocking. None means block indefinitely.

setblocking(self, flag: bool)Optional[int]

Set the blocking behaviour of this socket.

Parameters

flag (~bool) – False means non-blocking, True means block indefinitely.

__hash__(self)int

Returns a hash for the Socket.