-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add interface to save and resume SSL sessions (PR390) #234
base: publish
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,9 @@ This module provides access to Transport Layer Security (often known as "Secure | |
|
||
## Methods | ||
|
||
#### ssl.wrap\_socket(sock, keyfile=None, certfile=None, server\_side=False, cert\_reqs=CERT\_NONE, ca\_certs=None\, timeout=10sec) | ||
#### 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) | ||
|
||
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: | ||
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: | ||
|
||
```python | ||
|
||
|
@@ -38,13 +38,31 @@ ss.connect(socket.getaddrinfo('cloud.blynk.cc', 8441)[0][-1]) | |
|
||
SSL sockets inherit all methods and from the standard sockets, see the `usocket` module. | ||
|
||
`saved_session` : Takes a saved session instance of `ssl.SSLSocket`, and retrieve an already established TLS connection. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2nd: : Takes a saved session instance of |
||
|
||
`timeout` : specify a Timeout in Seconds for the SSL handshake operation between client and server, default is 10 seconds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3rd: specifies a Timeout in Seconds for the SSL handshake operation between client and server. The default is 10 seconds. |
||
|
||
#### ssl.save\_session(ssl_sock) | ||
|
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4th: Takes an instance |
||
|
||
```python | ||
|
||
import socket | ||
import ssl | ||
s = socket.socket() | ||
ss = ssl.wrap_socket(s) | ||
ss.connect(socket.getaddrinfo('www.google.com', 443)[0][-1]) | ||
ses = ssl.save_session(ss) | ||
ss.close() | ||
ss = ssl.wrap_socket(s, saved_session=ses) | ||
ss.connect(socket.getaddrinfo('www.google.com', 443)[0][-1]) | ||
``` | ||
|
||
## Exceptions | ||
|
||
* `ssl.SSLError` | ||
|
||
## Constants | ||
|
||
* `ssl.CERT_NONE`, `ssl.CERT_OPTIONAL`, `ssl.CERT_REQUIRED`: Supported values in `cert_reqs` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1st: SSL sockets inherit all methods from the standard sockets, see the
usocket
module.