mirror of
https://github.com/Flowseal/tg-ws-proxy.git
synced 2026-10-31 21:01:50 +03:00
Fake TLS: mirror client key share and profile the masking site (#1473)
This commit is contained in:
+22
-2
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import random
|
||||
import struct
|
||||
import asyncio
|
||||
import hashlib
|
||||
@@ -24,7 +25,11 @@ from .stats import stats
|
||||
from .config import proxy_config, parse_dc_ip_list, start_cfproxy_domain_refresh, coerce_domain_list
|
||||
from .bridge import MsgSplitter, CryptoCtx, do_fallback, bridge_ws_reencrypt, reset_tcp_backoff
|
||||
from .raw_websocket import set_sock_opts
|
||||
from .fake_tls import proxy_to_masking_domain, verify_client_hello, build_server_hello, FakeTlsStream, TLS_RECORD_HANDSHAKE
|
||||
from .fake_tls import (
|
||||
proxy_to_masking_domain, verify_client_hello, parse_client_hello, build_server_hello,
|
||||
probe_appdata_len, set_profiled_appdata_len, FakeTlsStream, TLS_RECORD_HANDSHAKE,
|
||||
SERVER_HELLO_DELAY,
|
||||
)
|
||||
from .balancer import balancer
|
||||
from .pool import ws_pool, cf_worker_pool
|
||||
from .cf_h2 import CfH2Pool
|
||||
@@ -162,7 +167,9 @@ async def _read_client_init(reader, writer, secret, label, masking):
|
||||
client_random, session_id, ts = tls_result
|
||||
log.debug("[%s] Fake TLS handshake ok (ts=%d)", label, ts)
|
||||
|
||||
server_hello = build_server_hello(secret, client_random, session_id)
|
||||
server_hello = build_server_hello(
|
||||
secret, client_random, session_id, parse_client_hello(client_hello))
|
||||
await asyncio.sleep(random.uniform(*SERVER_HELLO_DELAY))
|
||||
writer.write(server_hello)
|
||||
await writer.drain()
|
||||
|
||||
@@ -379,6 +386,19 @@ async def _run(stop_event: Optional[asyncio.Event] = None):
|
||||
secret_bytes = bytes.fromhex(proxy_config.secret)
|
||||
stopping = False
|
||||
|
||||
# Probe before listening so a domain that resolves to this proxy fails
|
||||
# fast instead of answering itself
|
||||
set_profiled_appdata_len(None)
|
||||
if proxy_config.fake_tls_domain:
|
||||
appdata_len = await probe_appdata_len(proxy_config.fake_tls_domain)
|
||||
set_profiled_appdata_len(appdata_len)
|
||||
if appdata_len is None:
|
||||
log.warning("Fake TLS profile unavailable, ServerHello uses "
|
||||
"random record sizes")
|
||||
else:
|
||||
log.info("Fake TLS profile: first encrypted record %d bytes",
|
||||
appdata_len)
|
||||
|
||||
def client_cb(r, w):
|
||||
if stopping:
|
||||
w.close()
|
||||
|
||||
Reference in New Issue
Block a user