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:
@@ -1,13 +1,17 @@
|
||||
# test that modtls produces a text error message
|
||||
|
||||
import socket, ssl, sys
|
||||
import socket, ssl
|
||||
|
||||
|
||||
def test(addr):
|
||||
s = socket.socket()
|
||||
s.connect(addr)
|
||||
try:
|
||||
s = ssl.wrap_socket(s)
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
||||
if hasattr(ssl_context, "check_hostname"):
|
||||
# Disable hostname check on CPython.
|
||||
ssl_context.check_hostname = False
|
||||
s = ssl_context.wrap_socket(s)
|
||||
print("wrap: no exception")
|
||||
except OSError as e:
|
||||
# mbedtls produces "mbedtls -0x7200: SSL - An invalid SSL record was received"
|
||||
|
||||
Reference in New Issue
Block a user