This commit is contained in:
Andrew Pimenov 2026-08-26 17:25:31 +03:00 • committed by GitHub
commit 52d4155338
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,6 +4,7 @@ import asyncio
import hashlib
import ssl
import time
import warnings
from datetime import UTC, datetime
from netsleuth.models import TlsResult
@ -28,6 +29,11 @@ def cpu_bound_ratio(tls_handshake_ms: float | None, tcp_rtt_ms: float | None) ->
def tls_context(verify: bool = True) -> ssl.SSLContext:
ctx = ssl.create_default_context()
if not verify:
warnings.warn(
"TLS certificate validation is disabled. This is inherently risky and exposes the connection to MITM attacks.",
RuntimeWarning,
stacklevel=2,
)
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
ctx.set_alpn_protocols(["h2", "http/1.1"])