From cc36e1b7d65fdfaf45c8bc468f06ab406374c388 Mon Sep 17 00:00:00 2001 From: Igor Abdrakhimov Date: Fri, 6 Dec 2024 11:26:18 -0800 Subject: [PATCH] Use python ssl --- .builder/actions/main.py | 12 ++++++++++++ .builder/actions/tls_server_setup.py | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 .builder/actions/main.py diff --git a/.builder/actions/main.py b/.builder/actions/main.py new file mode 100644 index 000000000..9daf64194 --- /dev/null +++ b/.builder/actions/main.py @@ -0,0 +1,12 @@ +import socket +import ssl + +context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) +context.load_cert_chain('tls13.pem.crt', 'tls13.key') + +with socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) as sock: + sock.bind(('127.0.0.1', 59443)) + sock.listen(5) + with context.wrap_socket(sock, server_side=True) as ssock: + conn, addr = ssock.accept() + print("accepted new conn: {}".format(addr)) diff --git a/.builder/actions/tls_server_setup.py b/.builder/actions/tls_server_setup.py index 9f7a1ebca..4f87cfe4e 100644 --- a/.builder/actions/tls_server_setup.py +++ b/.builder/actions/tls_server_setup.py @@ -55,14 +55,18 @@ def run(self, env): for c in iter(lambda: p1.stderr.read(1), b""): sys.stdout.buffer.write(c) - p = subprocess.Popen(["openssl.exe", "s_server", - "-accept", "localhost:59443", - "-key", "tls13.key", - "-cert", "tls13.pem.crt", - "-chainCAfile", "tls13_root_ca.pem.crt", - "-alpn", "x-amzn-mqtt-ca", - "-debug", "-state", - ], cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # p = subprocess.Popen(["openssl.exe", "s_server", + # "-accept", "localhost:59443", + # "-key", "tls13.key", + # "-cert", "tls13.pem.crt", + # "-chainCAfile", "tls13_root_ca.pem.crt", + # "-alpn", "x-amzn-mqtt-ca", + # "-debug", "-state", + # ], cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + python_path = sys.executable + p = subprocess.Popen([python_path, "main.py", + ], cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) time.sleep(1) p.poll() print("Return code is {}".format(p.returncode))