diff --git a/proxy/fake_tls.py b/proxy/fake_tls.py index 389bb59..96261db 100644 --- a/proxy/fake_tls.py +++ b/proxy/fake_tls.py @@ -12,6 +12,7 @@ import logging from typing import Dict, FrozenSet, NamedTuple, Optional, Tuple from .stats import stats +from .utils import set_x25519 try: from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey @@ -272,7 +273,7 @@ async def probe_appdata_len(domain: str, port: int = 443, writer = None try: ctx = ssl.create_default_context() - ctx.set_ecdh_curve('X25519') + set_x25519(ctx) ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE ctx.minimum_version = ssl.TLSVersion.TLSv1_3 diff --git a/proxy/utils.py b/proxy/utils.py index 4e6369d..6e703b9 100644 --- a/proxy/utils.py +++ b/proxy/utils.py @@ -143,13 +143,20 @@ class _PinnedHTTPSHandler(urllib.request.HTTPSHandler): return super().https_open(req) +def set_x25519(context: ssl.SSLContext) -> None: + try: + context.set_ecdh_curve('X25519') + except Exception: + pass + + def create_ssl_context(*, check_hostname: bool = True) -> ssl.SSLContext: bundle_dir = getattr(sys, '_MEIPASS', None) cafile = (os.path.join(bundle_dir, 'certifi', 'cacert.pem') if bundle_dir else certifi.where()) context = ssl.create_default_context(cafile=cafile) context.load_default_certs() - context.set_ecdh_curve('X25519') + set_x25519(context) context.check_hostname = check_hostname return context