extmod/uasyncio: add SSL support and fix SSL errors (esp32 primarily) #5815
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm in the process of breaking this PR into multiple smaller ones: #5819, #5825
This PR adds SSL support to uasyncio's open_connection(). open_connection takes an ssl parameter, defaulted to None. When set to True, SSL is used with default settings. When set to a dict SSL is used by wrapping the socket and passing the dict to wrap_socket. In CPython the values None and True function the same, but instead of a dict one would have to pass an SSLContext, which is something MP doesn't have. At least by using a dict nothing prevents an SSLContext from being introduced in the future.
In order not to loose my sanity while trying to work on SSL I also fixed the errors. First, I fixed the return values or raises of send/write/recv/read on non-blocking sockets and ssl sockets on the esp32. The connect_nonblocking.py is significantly expanded to test the various combinations and ensure EINPROGRESS doesn't get returned by a send/write/read/recv and that they all return EINTR/None when they "would block". Along the way I also added send/recv to SSL sockets for overall consistency.
Second, I fixed the mbedtls module to return a proper text error when the connection handshake fails.
I tested against unix micropython, some against CPython, and esp32 MP. Since mbedtls is shared other platforms I don't have need to be tested as well. I suspect this will bring up issues to fix there...
The tests aren't exactly right yet in that they print exception strings which don't work well for the pass/fail checks. I left that in so reviewers can see what's happening. I can remove the printing of the strings when the rest is ready for merge. There are also some additional tests that I need to write.
Before I proceed much further, I'd like to get some feedback so I don't waste my time.