Skip to content

Commit f741b8a

Browse files
authored
Documentation of PR: "Added interface to save and resume SSL sessions #390"
1 parent 1cda3b8 commit f741b8a

File tree

1 file changed

+21
-3
lines changed
  • content/firmwareapi/micropython

1 file changed

+21
-3
lines changed

content/firmwareapi/micropython/ussl.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ This module provides access to Transport Layer Security (often known as "Secure
1010

1111
## Methods
1212

13-
#### ssl.wrap\_socket(sock, keyfile=None, certfile=None, server\_side=False, cert\_reqs=CERT\_NONE, ca\_certs=None\, timeout=10sec)
13+
#### ssl.wrap\_socket(sock, keyfile=None, certfile=None, server\_side=False, cert\_reqs=CERT\_NONE, ssl\_version=0, ca\_certs=None, server\_hostname=None, saved_session=None, timeout=10sec)
1414

15-
Takes an instance `sock` of `socket.socket`, and returns an instance of ssl.SSLSocket, a subtype of `socket.socket`, which wraps the underlying socket in an SSL context. Example:
15+
Takes an instance `sock` of `socket.socket`, and returns an instance of `ssl.SSLSocket`, a subtype of `socket.socket`, which wraps the underlying socket in an SSL context. Example:
1616

1717
```python
1818

@@ -38,13 +38,31 @@ ss.connect(socket.getaddrinfo('cloud.blynk.cc', 8441)[0][-1])
3838

3939
SSL sockets inherit all methods and from the standard sockets, see the `usocket` module.
4040

41+
`saved_session` : Takes a saved session instance of `ssl.SSLSocket`, and retrieve an already established TLS connection.
42+
4143
`timeout` : specify a Timeout in Seconds for the SSL handshake operation between client and server, default is 10 seconds
4244

45+
#### ssl.save\_session(ssl_sock)
46+
47+
Takes an instance `ssl_sock` of `ssl.SSLSocket`, and returns an instance of `ssl.SSLSession`. Saved session can be resumed later, thereby reducing mobile data and time required. Example:
48+
49+
```python
50+
51+
import socket
52+
import ssl
53+
s = socket.socket()
54+
ss = ssl.wrap_socket(s)
55+
ss.connect(socket.getaddrinfo('www.google.com', 443)[0][-1])
56+
ses = ssl.save_session(ss)
57+
ss.close()
58+
ss = ssl.wrap_socket(s, saved_session=ses)
59+
ss.connect(socket.getaddrinfo('www.google.com', 443)[0][-1])
60+
```
61+
4362
## Exceptions
4463

4564
* `ssl.SSLError`
4665

4766
## Constants
4867

4968
* `ssl.CERT_NONE`, `ssl.CERT_OPTIONAL`, `ssl.CERT_REQUIRED`: Supported values in `cert_reqs`
50-

0 commit comments

Comments
 (0)