mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
tests: Update SSL network tests to use SSLContext, and work on CPython.
Changes are: - use ssl.SSLContext.wrap_socket instead of ssl.wrap_socket - disable check_hostname and call load_default_certs() where appropriate, to get CPython to run the tests correctly - pass socket.AF_INET to getaddrinfo and socket.socket(), to force IPv4 - change tests to use github.com instead of google.com, because certificate validation was failing with google.com Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -27,11 +27,12 @@ def do_connect(peer_addr, tls, handshake):
|
||||
print(" got", er.errno)
|
||||
# wrap with ssl/tls if desired
|
||||
if tls:
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
||||
if hasattr(ssl_context, "check_hostname"):
|
||||
ssl_context.check_hostname = False
|
||||
|
||||
try:
|
||||
if sys.implementation.name == "micropython":
|
||||
s = ssl.wrap_socket(s, do_handshake=handshake)
|
||||
else:
|
||||
s = ssl.wrap_socket(s, do_handshake_on_connect=handshake)
|
||||
s = ssl_context.wrap_socket(s, do_handshake_on_connect=handshake)
|
||||
print("wrap: True")
|
||||
except Exception as e:
|
||||
dp(e)
|
||||
|
||||
Reference in New Issue
Block a user