Skip to content

Commit ac8843c

Browse files
committed
docs/library/ussl: Deconditionalize, wipy notes moved to its documentation.
1 parent a0fb360 commit ac8843c

2 files changed

Lines changed: 53 additions & 70 deletions

File tree

docs/library/ussl.rst

Lines changed: 30 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,46 @@
1-
:mod:`ussl` -- ssl module
2-
===============================
1+
:mod:`ussl` -- SSL/TLS module
2+
=============================
33

44
.. module:: ussl
55
:synopsis: TLS/SSL wrapper for socket objects
66

7-
This module provides access to Transport Layer Security (often known as
8-
“Secure Sockets Layer”) encryption and peer authentication facilities for
9-
network sockets, both client-side and server-side.
7+
This module provides access to Transport Layer Security (previously and
8+
widely known as “Secure Sockets Layer”) encryption and peer authentication
9+
facilities for network sockets, both client-side and server-side.
1010

11-
.. only:: not port_wipy
11+
Functions
12+
---------
1213

13-
Functions
14-
---------
14+
.. function:: ssl.wrap_socket(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=CERT_NONE, ca_certs=None)
1515

16-
.. function:: ssl.wrap_socket(sock, server_side=False)
16+
Takes a stream `sock` (usually usocket.socket instance of ``SOCK_STREAM`` type),
17+
and returns an instance of ssl.SSLSocket, which wraps the underlying stream in
18+
an SSL context. Returned object has the usual stream interface methods like
19+
`read()`, `write()`, etc. In MicroPython, the returned object does not expose
20+
socket interface and methods like `recv()`, `send()`. In particular, a
21+
server-side SSL socket should be created from a normal socket returned from
22+
`accept()` on a non-SSL listening server socket.
1723

18-
Takes a stream `sock` (usually usocket.socket instance of ``SOCK_STREAM`` type),
19-
and returns an instance of ssl.SSLSocket, which wraps the underlying stream in
20-
an SSL context. Returned object has the usual stream interface methods like
21-
`read()`, `write()`, etc. In MicroPython, the returned object does not expose
22-
socket interface and methods like `recv()`, `send()`. In particular, a
23-
server-side SSL socket should be created from a normal socket returned from
24-
`accept()` on a non-SSL listening server socket.
24+
Depending on the underlying module implementation for a particular board,
25+
some or all keyword arguments above may be not supported.
2526

26-
.. warning::
27+
.. warning::
2728

28-
Currently, this function does NOT validate server certificates, which makes
29-
an SSL connection established prone to man-in-the-middle attacks.
29+
Some implementations of ``ssl`` module do NOT validate server certificates,
30+
which makes an SSL connection established prone to man-in-the-middle attacks.
3031

32+
Exceptions
33+
----------
3134

32-
.. only:: port_wipy
35+
.. data:: ssl.SSLError
3336

34-
Functions
35-
---------
37+
This exception does NOT exist. Instead its base class, OSError, is used.
3638

37-
.. function:: ssl.wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ca_certs=None)
39+
Constants
40+
---------
3841

39-
Takes an instance sock of socket.socket, and returns an instance of ssl.SSLSocket, a subtype of
40-
``socket.socket``, which wraps the underlying socket in an SSL context. sock must be a ``SOCK_STREAM``
41-
socket and protocol number ``socket.IPPROTO_SEC``; other socket types are unsupported. Example::
42+
.. data:: ssl.CERT_NONE
43+
ssl.CERT_OPTIONAL
44+
ssl.CERT_REQUIRED
4245

43-
import socket
44-
import ssl
45-
s = socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SEC)
46-
ss = ssl.wrap_socket(s)
47-
ss.connect(socket.getaddrinfo('www.google.com', 443)[0][-1])
48-
49-
Certificates must be used in order to validate the other side of the connection, and also to
50-
authenticate ourselves with the other end. Such certificates must be stored as files using the
51-
FTP server, and they must be placed in specific paths with specific names.
52-
53-
- The certificate to validate the other side goes in: **'/flash/cert/ca.pem'**
54-
- The certificate to authenticate ourselves goes in: **'/flash/cert/cert.pem'**
55-
- The key for our own certificate goes in: **'/flash/cert/private.key'**
56-
57-
.. note::
58-
59-
When these files are stored, they are placed inside the internal **hidden** file system
60-
(just like firmware updates), and therefore they are never visible.
61-
62-
For instance to connect to the Blynk servers using certificates, take the file ``ca.pem`` located
63-
in the `blynk examples folder <https://github.com/wipy/wipy/tree/master/examples/blynk>`_
64-
and put it in '/flash/cert/'. Then do::
65-
66-
import socket
67-
import ssl
68-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SEC)
69-
ss = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED, ca_certs='/flash/cert/ca.pem')
70-
ss.connect(socket.getaddrinfo('cloud.blynk.cc', 8441)[0][-1])
71-
72-
SSL sockets inherit all methods and from the standard sockets, see the :mod:`usocket` module.
73-
74-
Exceptions
75-
----------
76-
77-
.. data:: ssl.SSLError
78-
79-
Constants
80-
---------
81-
82-
.. data:: ssl.CERT_NONE
83-
.. data:: ssl.CERT_OPTIONAL
84-
.. data:: ssl.CERT_REQUIRED
85-
86-
supported values in ``cert_reqs``
46+
Supported values for `cert_reqs` parameter.

docs/wipy/general.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,29 @@ SSL sockets need to be created the following way before wrapping them with.
254254
s = socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SEC)
255255
ss = ssl.wrap_socket(s)
256256

257+
Certificates must be used in order to validate the other side of the connection, and also to
258+
authenticate ourselves with the other end. Such certificates must be stored as files using the
259+
FTP server, and they must be placed in specific paths with specific names.
260+
261+
- The certificate to validate the other side goes in: **'/flash/cert/ca.pem'**
262+
- The certificate to authenticate ourselves goes in: **'/flash/cert/cert.pem'**
263+
- The key for our own certificate goes in: **'/flash/cert/private.key'**
264+
265+
.. note::
266+
267+
When these files are stored, they are placed inside the internal **hidden** file system
268+
(just like firmware updates), and therefore they are never visible.
269+
270+
For instance to connect to the Blynk servers using certificates, take the file ``ca.pem`` located
271+
in the `blynk examples folder <https://github.com/wipy/wipy/tree/master/examples/blynk>`_.
272+
and put it in '/flash/cert/'. Then do::
273+
274+
import socket
275+
import ssl
276+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SEC)
277+
ss = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED, ca_certs='/flash/cert/ca.pem')
278+
ss.connect(socket.getaddrinfo('cloud.blynk.cc', 8441)[0][-1])
279+
257280
Incompatibilities in uhashlib module
258281
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259282

0 commit comments

Comments
 (0)