8000 extmod/ssl: Enable backwards compatibility. · micropython/micropython@bd4f703 · GitHub
[go: up one dir, main page]

Skip to content

Commit bd4f703

Browse files
committed
extmod/ssl: Enable backwards compatibility.
This adds wrap_socket to extmod/ssl.py module to mantain backwards compatibility even after ussl.wrap_socket is deprecated. Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
1 parent 04c3cbb commit bd4f703

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

extmod/ssl/ssl.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55
PROTOCOL_TLS_CLIENT = const(0)
66
PROTOCOL_TLS_SERVER = const(1)
77

8+
# backwards compatibility even after C code is deprecated
9+
def wrap_socket(
10+
sock,
11+
server_side=False,
12+
key=None,
13+
cert=None,
14+
cert_reqs=CERT_NONE,
15+
cadata=None,
16+
server_hostname=None,
17+
do_handshake=True,
18+
):
19+
ctx = _ussl.ctx_init()
20+
if (key is not None) and (cert is not None):
21+
ctx.load_certchain(key=key, cert=cert)
22+
if cadata:
23+
ctx.load_cadata(cadata)
24+
return ctx.wrap_socket(
25+
sock,
26+
server_side=server_side,
27+
cert_reqs=cert_reqs,
28+
server_hostname=server_hostname,
29+
do_handshake=do_handshake,
30+
)
31+
832

933
class SSLContext:
1034
def __init__(self, protocol):

0 commit comments

Comments
 (0)
0