import ssl from app import config def server_context() -> ssl.SSLContext | None: """Trust store for outbound TLS. None means the dependency is still plaintext.""" if not config.TLS_CA_FILE: return None context = ssl.create_default_context(cafile=config.TLS_CA_FILE) context.check_hostname = True context.verify_mode = ssl.CERT_REQUIRED context.minimum_version = ssl.TLSVersion.TLSv1_2 if config.TLS_CERT_FILE and config.TLS_KEY_FILE: context.load_cert_chain(config.TLS_CERT_FILE, config.TLS_KEY_FILE) return context def https_verify(endpoint: str): if endpoint.startswith("https://") and config.TLS_CA_FILE: return config.TLS_CA_FILE return True