Skip to content

Commit

Permalink
Use python ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Dec 6, 2024
1 parent 87b1643 commit cc36e1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 12 additions & 0 deletions .builder/actions/main.py
Original file line number Diff line number Diff line change
@@ -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))
20 changes: 12 additions & 8 deletions .builder/actions/tls_server_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit cc36e1b

Please sign in to comment.