-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
extmod/modssl_mbedtls: Implement SSLSession support. #12780
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
base: master
Are you sure you want to change the base?
Conversation
57c5d78 to
43824ae
Compare
|
Code size report: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12780 +/- ##
==========================================
- Coverage 98.38% 98.36% -0.02%
==========================================
Files 171 171
Lines 22300 22353 +53
==========================================
+ Hits 21939 21987 +48
- Misses 361 366 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
43824ae to
53bb552
Compare
53bb552 to
e529117
Compare
|
This is an automated heads-up that we've just merged a Pull Request See #13763 A search suggests this PR might apply the STATIC macro to some C code. If it Although this is an automated message, feel free to @-reply to me directly if |
f014564 to
6c50ae1
Compare
6c50ae1 to
9a48098
Compare
|
Updated on latest master branch, added server-side support for TLS tickets to the Unix port, and added a test that checks (a) that SSLSession works and (b) that session resumption actually results in decreased data usage. I've been using various versions of this patch for almost a year now to resume HTTPS connections without any trouble (though that might just be because I didn't try with many different configurations). Marked as ready for review. EDIT: And re-pushed because I forgot to add the documentation commit. |
caeb380 to
feae3a7
Compare
feae3a7 to
a7c1dc6
Compare
|
Hi Daniël, Do you plan to update the asyncio implementation to use this functionality? If that was done it would be a minor effort to add SSL session support to many micropython web libraries. Currently, we session set up times in the order of 5 seconds on the PICO W, the lack of SSL session reuse is a showstopper for web apps using asyncio's new SSL support. Cheers, Charlie |
|
Hi Daniël, |
|
I didn't look into how to use this with asyncio before. It appears that in CPython there is no interface to use SSLSessions with asyncio. For the core support we'd need to for example add a For that reason I might prefer to split this into a separate follow-up PR, since it doesn't impact the changes proposed here and thus does not need to block considering / reviewing / merging this PR. |
|
@DvdGiessen Hi Daniël, I agree that the change is best handled as a separate PR as it requires changing the asyncio implementation to add session to the wrap_socket call. Cheers, Charlie |
a7c1dc6 to
06c5929
Compare
06c5929 to
30ce6ac
Compare
30ce6ac to
95e5585
Compare
95e5585 to
4f91e1c
Compare
4f91e1c to
2e1b344
Compare
2e1b344 to
16223e9
Compare
16223e9 to
4f8529d
Compare
4f8529d to
3eca373
Compare
3eca373 to
70df1af
Compare
Signed-off-by: Daniël van de Giessen <[email protected]>
Signed-off-by: Daniël van de Giessen <[email protected]>
Signed-off-by: Daniël van de Giessen <[email protected]>
Signed-off-by: Daniël van de Giessen <[email protected]>
Signed-off-by: Daniël van de Giessen <[email protected]>
70df1af to
88c4c9c
Compare
Summary
This implements support for the
SSLSessionclass, introduced in CPython in 3.6 (see #2415). It allows saving session data from an active TLS client-side connection and then creating a new connection re-using this session data. Benefits include a faster handshake and reduced data usage for short connections.Implementation details
This PR adds the
SSLSessionclass, thesession=parameter for theSSLContext.wrap_socket()method, and thesessionattribute for anSSLSocketobject.Additionally, I've added a non-standard part: The
SSLSession.serialize()function that converts the session to a bytes object (also available via the buffer protocol, so perhaps exposing this function is redundant); so that it can be stored by the user, and a constructor for the SSLSession object that accepts a bytes-like object to reconstruct the session object (CPython doesn't allow direct construction). This allows storing the session somewhere and use it after a deep sleep or reboot.The second commit adds server-side support for TLS tickets in the Unix port, so that we can meaningfully test the session resumption in tests. The third commit adds a test which tests session resumption using the
SSLSessionobject, checking that the resumption worked by checking that a resuming consumes less data.micropython/micropython-lib#829 is a companion MR that implements support in the
sslmodule wrapper. It is required for the tests to pass.Usage example
A small example test, using a wrapper class around the TCP socket so we can count how many bytes of data we're sending/receiving:
Testing
I've deployed this in production and been running it for a number of years on a large number of devices.