jczic / MicroWebSrv2

The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
https://github.com/jczic/MicroWebSrv2
MIT License
662 stars 97 forks source link

Having another look at SSL in Micropython #102

Open DracoTomes opened 9 months ago

DracoTomes commented 9 months ago

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?

jczic commented 9 months ago

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? 🚀

DracoTomes commented 9 months ago

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?

jczic commented 9 months ago

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