MicroWebSrv2 icon indicating copy to clipboard operation
MicroWebSrv2 copied to clipboard

Having another look at SSL in Micropython

Open DracoTomes opened this issue 1 year ago • 3 comments

I just tried enabling SSL on my MicroPython project and had a pretty bad time. I only afterwards stumbled on this Issue, basically stating HTTPS is not supported on MicroPython.

Given that MicroPython has recently started redoing a lot of the ssl Implementation how willing are you to have a look at what it would take to implement this into the XAsyncSockets library?

DracoTomes avatar Feb 18 '24 12:02 DracoTomes

Hello @DracoTomes, That's a good question indeed ☺️ I don't have much time at the moment, but it would be interesting to review how SSL (TLS) works in MicroPython. I know that SSLContext was required for this to work. (The server works very well in SSL on a Unix market (it does asynchronous and concurrent concurrency)).

I use it in production!

Is this really urgent for you? 🚀

jczic avatar Feb 18 '24 19:02 jczic

No this is not urgent.

Originally I also failed here

https://github.com/jczic/MicroWebSrv2/blob/2f1e982cad28be776d124bfeaae34e01f82fe177/MicroWebSrv2/microWebSrv2.py#L312C9-L314C63

I then tried replacing the create_default_context with something like this

ctx = new ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
try:
    load_verify_locations(caFile)
except :
    raise ValueError('"caFile" must indicate a valid PEM file.')

but then had the issue that the new SSLContext does not implement .fileno() and this failed:

https://github.com/jczic/MicroWebSrv2/blob/2f1e982cad28be776d124bfeaae34e01f82fe177/MicroWebSrv2/libs/XAsyncSockets.py#L61C5-L63C39

and I gave up.

I guess the first interesting thing is how much work you roughly estimate this would take, if feasible at all?

DracoTomes avatar Feb 18 '24 21:02 DracoTomes

I don't know how long it would take with MicroPython because it would be important for me to get the ESP32 boards out and have a bit of time (I'm setting up a business at the moment and I've got a lot of work to do). However, I see that SSLContext now seems to exist in MicroPython and fileno() exists in socket objects normally.

https://docs.micropython.org/en/latest/library/ssl.html#class-sslcontext

jczic avatar Feb 18 '24 22:02 jczic