Преглед на файлове

add pre-flight check for required TLS config options

cert chain may be optional, but the other three elements need to be
present.
Daniel Gruno преди 1 година
родител
ревизия
00a2813a48
променени са 1 файла, в които са добавени 4 реда и са изтрити 1 реда
  1. 4 1
      pypubsub.py

+ 4 - 1
pypubsub.py

@@ -90,7 +90,10 @@ class Configuration:
         server_payload_limit = int(yml['server'].get('max_payload_size', PUBSUB_DEFAULT_MAX_PAYLOAD_SIZE))
         tls_port = 0
         tls_ctx = None
-        if 'tls' in yml['server']:
+        # TLS support, if configured
+        if 'tls' in yml['server'] and isinstance(yml['server']['tls'], dict):
+            for required_element in ("port", "cert", "key", ):
+                assert yml['server']['tls'].get(required_element), f"TLS: configuration option '{required_element}' is missing or invalid, cannot enable TLS!"
             import ssl
             tls_port = int(yml['server']['tls']['port'])
             # Create TLS context and load cert+key