← index #7735PR #5815
Related · medium · value 2.502
QUERY · ISSUE

How to add ALPN parameter when opening socket or ssl wrapping a socket?

openby Molaireopened 2021-08-31updated 2021-09-01

It seems like FreeRTOS/mbedTLS support this, is there a way of directly accessing this?

CANDIDATE · PULL REQUEST

extmod/uasyncio: add SSL support and fix SSL errors (esp32 primarily)

closedby tveopened 2020-03-27updated 2020-03-28

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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied