diff --git a/backend/whatsapp.py b/backend/whatsapp.py index 04cad84..293e157 100644 --- a/backend/whatsapp.py +++ b/backend/whatsapp.py @@ -5,6 +5,7 @@ Handles sending WhatsApp messages via Meta's API import os import httpx import certifi +import ssl import re import logging from typing import Optional @@ -17,10 +18,16 @@ logger = logging.getLogger(__name__) async def create_http_client() -> httpx.AsyncClient: """ Create an httpx client with proper certificate verification. - Uses certifi for CA bundle - simple and reliable. + Uses certifi for CA bundle and creates proper SSL context for handshake. """ + # Create SSL context with proper certificate verification + ssl_context = ssl.create_default_context(cafile=certifi.where()) + ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2 + ssl_context.maximum_version = ssl.TLSVersion.TLSv1_3 + ssl_context.options |= ssl.OP_NO_COMPRESSION + return httpx.AsyncClient( - verify=certifi.where(), + verify=ssl_context, timeout=httpx.Timeout(30.0, connect=10.0), http2=False, limits=httpx.Limits(max_keepalive_connections=5, max_connections=10)