fix(auth): honor SSL CA env vars across httpx + requests callsites

- hermes_cli/auth.py: add _default_verify() with macOS Homebrew certifi
  fallback (mirrors weixin 3a0ec1d93). Extend env var chain to include
  REQUESTS_CA_BUNDLE so one env var works across httpx + requests paths.
- agent/model_metadata.py: add _resolve_requests_verify() reading
  HERMES_CA_BUNDLE / REQUESTS_CA_BUNDLE / SSL_CERT_FILE in priority
  order. Apply explicit verify= to all 6 requests.get callsites.
- Tests: 18 new unit tests + autouse platform pin on existing
  TestResolveVerifyFallback to keep its "returns True" assertions
  platform-independent.

Empirically verified against self-signed HTTPS server: requests honors
REQUESTS_CA_BUNDLE only; httpx honors SSL_CERT_FILE only. Hermes now
honors all three everywhere.

Triggered by Discord reports — Nous OAuth SSL failure on macOS
Homebrew Python; custom provider self-signed cert ignored despite
REQUESTS_CA_BUNDLE set in env.
This commit is contained in:
0xbyt4 2026-04-23 14:59:26 +03:00 committed by Teknium
parent b0cb81a089
commit 8aa37a0cf9
5 changed files with 260 additions and 7 deletions

View file

@ -22,6 +22,7 @@ import shutil
import shlex
import ssl
import stat
import sys
import base64
import hashlib
import subprocess
@ -1708,6 +1709,24 @@ def resolve_codex_runtime_credentials(
# TLS verification helper
# =============================================================================
def _default_verify() -> bool | ssl.SSLContext:
"""Platform-aware default SSL verify for httpx clients.
On macOS with Homebrew Python, the system OpenSSL cannot locate the
system trust store and valid public certs fail verification. When
certifi is importable we pin its bundle explicitly; elsewhere we
defer to httpx's built-in default (certifi via its own dependency).
Mirrors the weixin fix in 3a0ec1d93.
"""
if sys.platform == "darwin":
try:
import certifi
return ssl.create_default_context(cafile=certifi.where())
except ImportError:
pass
return True
def _resolve_verify(
*,
insecure: Optional[bool] = None,
@ -1726,6 +1745,7 @@ def _resolve_verify(
or tls_state.get("ca_bundle")
or os.getenv("HERMES_CA_BUNDLE")
or os.getenv("SSL_CERT_FILE")
or os.getenv("REQUESTS_CA_BUNDLE")
)
if effective_insecure:
@ -1737,9 +1757,9 @@ def _resolve_verify(
"CA bundle path does not exist: %s — falling back to default certificates",
ca_path,
)
return True
return _default_verify()
return ssl.create_default_context(cafile=ca_path)
return True
return _default_verify()
# =============================================================================