diff options
Diffstat (limited to 'tests/net_inet/test_tls_sites.py')
-rw-r--r-- | tests/net_inet/test_tls_sites.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/tests/net_inet/test_tls_sites.py b/tests/net_inet/test_tls_sites.py index 4f457b3abc..d60f4872b6 100644 --- a/tests/net_inet/test_tls_sites.py +++ b/tests/net_inet/test_tls_sites.py @@ -1,24 +1,34 @@ +import sys +import select import socket import ssl -# CPython only supports server_hostname with SSLContext -if hasattr(ssl, "SSLContext"): - ssl = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) - def test_one(site, opts): - ai = socket.getaddrinfo(site, 443) + ai = socket.getaddrinfo(site, 443, socket.AF_INET) addr = ai[0][-1] - s = socket.socket() + s = socket.socket(socket.AF_INET) + + # Create SSLContext. + ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + + # CPython compatibility: + # - disable check_hostname + # - load default system certificate chain + # - must wait for socket to be writable before calling wrap_socket + if sys.implementation.name != "micropython": + ssl_context.check_hostname = False + ssl_context.load_default_certs() + select.select([], [s], []) try: s.connect(addr) if "sni" in opts: - s = ssl.wrap_socket(s, server_hostname=opts["host"]) + s = ssl_context.wrap_socket(s, server_hostname=opts["host"]) else: - s = ssl.wrap_socket(s) + s = ssl_context.wrap_socket(s) s.write(b"GET / HTTP/1.0\r\nHost: %s\r\n\r\n" % bytes(site, "latin")) resp = s.read(4096) @@ -31,8 +41,7 @@ def test_one(site, opts): SITES = [ - "google.com", - "www.google.com", + "www.github.com", "micropython.org", "pypi.org", {"host": "api.pushbullet.com", "sni": True}, |