socket ssl

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
ke528
Posts: 2
Joined: Thu May 09, 2019 3:11 am

socket ssl

Post by ke528 » Fri Feb 14, 2020 1:48 pm

import ussl
import socket
import network
import time
import io
import zs
wifi=network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect("Kejiank528-TP-2.4G","kejiank5282.4")
while True:
if wifi.isconnected():
break
time.sleep(0.2)
print("WiFi已连接")
#https=io.BytesIO()
https=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
https.bind(("0.0.0.0",528))
https.listen(1)
print("listen")
f=open('ke528_key.key',"r")
key=f.read()
f.close()
f=open("ke528_cert.pem",'r')
cert=f.read()
f.close()
while True:
a,b=https.accept()
print("accept")
c=ussl.wrap_socket(a,server_side=True,key=key,cert=cert)
print("ok")
print(c.read(512))
#########################################################
I (3731) wifi: state: init -> auth (b0)
I (3741) wifi: state: auth -> assoc (0)
I (3741) wifi: state: assoc -> run (10)
I (3761) wifi: connected with Kejiank528-TP-2.4G, channel 1, 40U, bssid = 88:25:93:83:e8:9f
I (3761) wifi: pm start, type: 1

I (3761) network: CONNECTED
I (4571) tcpip_adapter: sta ip: 192.168.1.119, mask: 255.255.255.0, gw: 192.168.1.1
I (4571) network: GOT_IP
WiFi������
listen
accept
mbedtls_ssl_handshake error: -4310
Traceback (most recent call last):
File "<stdin>", line 29, in <module>
OSError: [Errno 5] EIO
>>>
###############################################
ke528_key.key
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAoatv3x5UQlOSTA8lWSdCX6YQyPY4WPYwuNNd3alfY4/IkY2+
1k1R990sYWS5AtS8F8ZXYXVxSp3WsUfyVOLBMtYt7FN7Ct3yyqAuGG1+W9/dviBy
MzO8zE6Epuflx0v1cMgNUlwwgSCfK+7DulnJzLKPq/Ix87qPcEUt9MewZxtSBq3Z
FrLooInmJKUyVu2ilOSPDI6cSJXeDoVxQEXhjQ3XTFGJFvaGboTcthM3rrvIvgn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R0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1UdEwEB/wQIMAYBAf8C
AQAwNAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdp
Y2VydC5jb20wQgYDVR0fBDswOTA3oDWgM4YxaHR0cDovL2NybDMuZGlnaWNlcnQu
Y29tL0RpZ2lDZXJ0R2xvYmFsUm9vdENBLmNybDBMBgNVHSAERTBDMDcGCWCGSAGG
/WwBAjAqMCgGCCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BT
MAgGBmeBDAECATANBgkqhkiG9w0BAQsFAAOCAQEAK3Gp6/aGq7aBZsxf/oQ+TD/B
SwW3AU4ETK+GQf2kFzYZkby5SFrHdPomunx2HBzViUchGoofGgg7gHW0W3MlQAXW
M0r5LUvStcr82QDWYNPaUy4taCQmyaJ+VB+6wxHstSigOlSNF2a6vg4rgexixeiV
4YSB03Yqp2t3TeZHM9ESfkus74nQyW7pRGezj+TC44xCagCQQOzzNmzEAP2SnCrJ
sNE2DpRVMnL8J6xBRdjmOsC3N6cQuKuRXbzByVBjCqAA8t1L0I+9wXJerLPyErjy
rMKWaBFLmfK/AHNF4ZihwPGOc7w6UHczBZXH5RFzJNnww+WnKuTPI0HfnVH8lg==
-----END CERTIFICATE-----
############################################################
I want to be an HTTPS server
But SSL can't run. It always reports an error
Solution ()
I'm Chinese, please write the answer clearly
Thank you
我想做一个 https 服务器
可是ssl 运行不起来 一直报错
求解 ()
我是中国人 请把答案写的清晰点
谢谢

cgglzpy
Posts: 31
Joined: Thu Jul 18, 2019 4:20 pm

Re: socket ssl

Post by cgglzpy » Fri Feb 14, 2020 6:08 pm

Hi, ke528

Look at this issue in MicroPython repo: https://github.com/micropython/micropython/issues/5543

MicroPython v1.12 stable release should work, so rolling back to last stable version resolves the issue.

Post Reply