2020-03-27 06:17:35 +00:00
|
|
|
# test that modtls produces a text error message
|
|
|
|
|
2022-08-18 07:57:45 +01:00
|
|
|
import socket, ssl, sys
|
2020-03-27 06:17:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test(addr):
|
|
|
|
s = socket.socket()
|
|
|
|
s.connect(addr)
|
|
|
|
try:
|
|
|
|
s = ssl.wrap_socket(s)
|
|
|
|
print("wrap: no exception")
|
|
|
|
except OSError as e:
|
|
|
|
# mbedtls produces "mbedtls -0x7200: SSL - An invalid SSL record was received"
|
2020-07-02 20:34:36 +01:00
|
|
|
# axtls produces "RECORD_OVERFLOW" but also prints "TLS buffer overflow,..."
|
2020-03-27 06:17:35 +00:00
|
|
|
# CPython produces "[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1108)"
|
|
|
|
ok = (
|
2020-07-02 20:34:36 +01:00
|
|
|
"SSL_INVALID_RECORD" in str(e)
|
2020-03-27 06:17:35 +00:00
|
|
|
or "RECORD_OVERFLOW" in str(e)
|
|
|
|
or "wrong version" in str(e)
|
|
|
|
)
|
|
|
|
print("wrap:", ok)
|
|
|
|
if not ok:
|
|
|
|
print("got exception:", e)
|
|
|
|
s.close()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# connect to plain HTTP port, oops!
|
|
|
|
addr = socket.getaddrinfo("micropython.org", 80)[0][-1]
|
|
|
|
test(addr)
|