diff --git a/src/aare/daq/tellupdater.py b/src/aare/daq/tellupdater.py index 1023ad76..c87e1059 100644 --- a/src/aare/daq/tellupdater.py +++ b/src/aare/daq/tellupdater.py @@ -170,6 +170,19 @@ def main(): # Main thread runs websocket client loop while True: try: + import ssl + # 1. Create a proper SSL Context + context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + + # 2. Load the CA to trust the server + context.load_verify_locations(cafile="/etc/ssl/certs/secrets/mx-aaredb-dmz-01_Full_Chain_CA.pem") + + # 3. Load the Client Certificate (mTLS) + context.load_cert_chain( + certfile="/etc/ssl/certs/secrets/mx-x10sa-queue-01_from_dmz-01.crt", + keyfile="/etc/ssl/certs/secrets/mx-x10sa-queue-01_from_dmz-01.key" + ) + ws = websocket.WebSocketApp( WS_URL, header=WS_HEADERS, @@ -179,16 +192,9 @@ def main(): on_open=on_open, ) - # --- mTLS CERTIFICATES ADDED HERE -- - import ssl - ssl_settings = { - "certfile": "/etc/ssl/certs/secrets/mx-x10sa-queue-01_from_db-01.crt", - "keyfile": "/etc/ssl/certs/secrets/mx-x10sa-queue-01_from_db-01.key", - "ca_certs": "/etc/ssl/certs/secrets/mx-db-01_Full_Chain_CA.pem", - "cert_reqs": ssl.CERT_REQUIRED - } + # 4. Pass the context object to run_forever + ws.run_forever(sslopt={"context": context}) - ws.run_forever(sslopt=ssl_settings) except Exception as e: print(f"[MAIN][ERROR] ws.run_forever() crashed with: {e}")