← index #408PR #7315
Related · medium · value 2.146
QUERY · ISSUE

No Example for uasyncio SSL webserver

openby Asanga-Virajopened 2021-01-12updated 2021-01-12

No example for uasyncio SSL webserver. Also couldn't find any on the internet. Looking for support.

CANDIDATE · PULL REQUEST

extmod/uasyncio: Add ssl support to start_server.

closedby nniroopened 2021-05-25updated 2023-12-12
extmod

here's example code starting a server with ssl.

(N.B. This code assumes the private key and certificate were previously created)

import ussl as ssl

basePath = "./"

with open(basePath + b"cert.key", "rb") as fd:
    sslKey = fd.read()
with open(basePath + b"cert.cert", "rb") as fd:
    sslCert = fd.read()

context = lambda sock: ssl.wrap_socket(sock, server_side=1, key=sslKey, cert=sslCert)

server = await asyncio.start_server(lambda r, w: handler(r, w)
	, '0.0.0.0', 1965
	, ssl=context)

I noticed there is a much more complete open PR to solve this issue in #5840 . My PR is just an attempt to solve the same issue just from a different angle.

@tve please review this.

This PR works in the unix port but it needs further changes for the esp32 port. In the esp32 port, I noticed that mbedtls wasn't working correctly (esp-idf seems to require a specific (older) micropython version. Or was it the reverse?) and thus decided to try axtls. I had a lot more success with axtls but it still required some code changes to make it work.

edit : I fixed the pasted example code formatting.

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