summaryrefslogtreecommitdiff
path: root/tests/multi_net/sslcontext_getpeercert.py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-12-12 17:15:24 +1100
committerDamien George <damien@micropython.org>2023-12-12 21:21:54 +1100
commitef996d15b9cbadee591a185f27fb16e90a5d4f5d (patch)
tree595af344ea1e59e1c0813897df3152680acc662b /tests/multi_net/sslcontext_getpeercert.py
parentc9eb6bc6016a7f13cc624b6a4160599ab6b166ff (diff)
extmod/modssl_mbedtls: Make SSLSocket.getpeercert() optional.
And only enable this method when the relevant feature is available in mbedtls. Otherwise, if mbedtls doesn't support getting the peer certificate, this method always returns None and it's confusing why it does that. It's better to remove the method altogether, so the error trying to use it is more obvious. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/multi_net/sslcontext_getpeercert.py')
-rw-r--r--tests/multi_net/sslcontext_getpeercert.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/tests/multi_net/sslcontext_getpeercert.py b/tests/multi_net/sslcontext_getpeercert.py
index b95b13f0f..c75a37952 100644
--- a/tests/multi_net/sslcontext_getpeercert.py
+++ b/tests/multi_net/sslcontext_getpeercert.py
@@ -1,6 +1,7 @@
# Test creating an SSL connection and getting the peer certificate.
try:
+ import io
import os
import socket
import ssl
@@ -42,6 +43,12 @@ def instance0():
# Client
def instance1():
+ s_test = ssl.wrap_socket(io.BytesIO(), server_side=True, do_handshake=False)
+ s_test.close()
+ if not hasattr(s_test, "getpeercert"):
+ print("SKIP")
+ raise SystemExit
+
multitest.next()
s = socket.socket()
s.connect(socket.getaddrinfo(IP, PORT)[0][-1])
@@ -49,7 +56,7 @@ def instance1():
client_ctx.verify_mode = ssl.CERT_REQUIRED
client_ctx.load_verify_locations(cafile=cafile)
s = client_ctx.wrap_socket(s, server_hostname="micropython.local")
- print(s.getpeercert(True))
+ print(s.getpeercert(True).hex())
s.write(b"client to server")
print(s.read(16))
s.close()