mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-10-26 17:41:58 -06:00
fix: align socket.io tls verification
This commit is contained in:
@@ -533,21 +533,22 @@ class AgentHttpClient:
|
|||||||
return {"Authorization": f"Bearer {self.access_token}"}
|
return {"Authorization": f"Bearer {self.access_token}"}
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def websocket_kwargs(self) -> Dict[str, Any]:
|
def configure_socketio(self, client: "socketio.AsyncClient") -> None:
|
||||||
kwargs: Dict[str, Any] = {}
|
"""Align the Socket.IO engine's TLS verification with the REST client."""
|
||||||
verify = getattr(self.session, "verify", True)
|
try:
|
||||||
if isinstance(verify, str) and os.path.isfile(verify):
|
verify = getattr(self.session, "verify", True)
|
||||||
try:
|
engine = getattr(client, "eio", None)
|
||||||
ctx = ssl.create_default_context(cafile=verify)
|
if engine is None:
|
||||||
kwargs["ssl"] = ctx
|
return
|
||||||
except Exception:
|
# python-engineio accepts bool, path, or ssl.SSLContext for ssl_verify
|
||||||
pass
|
if isinstance(verify, str) and os.path.isfile(verify):
|
||||||
elif verify is False:
|
engine.ssl_verify = verify
|
||||||
try:
|
elif verify is False:
|
||||||
kwargs["ssl"] = ssl._create_unverified_context()
|
engine.ssl_verify = False
|
||||||
except Exception:
|
else:
|
||||||
pass
|
engine.ssl_verify = True
|
||||||
return kwargs
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Enrollment & token management
|
# Enrollment & token management
|
||||||
@@ -2036,15 +2037,14 @@ async def connect_loop():
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
client.ensure_authenticated()
|
client.ensure_authenticated()
|
||||||
|
client.configure_socketio(sio)
|
||||||
url = client.websocket_base_url()
|
url = client.websocket_base_url()
|
||||||
print(f"[INFO] Connecting Agent to {url}...")
|
print(f"[INFO] Connecting Agent to {url}...")
|
||||||
_log_agent(f'Connecting to {url}...')
|
_log_agent(f'Connecting to {url}...')
|
||||||
ws_kwargs = client.websocket_kwargs()
|
|
||||||
await sio.connect(
|
await sio.connect(
|
||||||
url,
|
url,
|
||||||
transports=['websocket'],
|
transports=['websocket'],
|
||||||
headers=client.auth_headers(),
|
headers=client.auth_headers(),
|
||||||
**ws_kwargs,
|
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user