ZaStoGram/TMessagesProj/jni/tgnet/FakeTlsClientHello.h
loop-uh a918b73f48
Some checks failed
Build three ZaStoGram APKs / build (armeabi-v7a, ZaStoGram-standalone-armeabi-v7a, Armv7, armv7) (push) Failing after 49s
Build three ZaStoGram APKs / build (arm64-v8a, ZaStoGram-standalone-arm64-v8a, Arm64, arm64) (push) Failing after 51s
ZaStoGram source guards / guards (push) Failing after 40s
Build three ZaStoGram APKs / build (x86, ZaStoGram-standalone-x86, X86, x86) (push) Failing after 1m8s
Check connection: a path test that runs the real client code and writes one log
New module (jni/tgnet/pathtest, org.telegram.zastogram.pathtest): for every proxy of the list, the official WSS route
and two control hosts it makes 12 attempts 1.5 s apart through the REAL client code and writes one text log with a
JSONL twin into the logs folder (so the logs screen and its zip export carry it): per-attempt lines (server_hello,
alert, rst, fin, silent, connect_failed with time to first byte, DNS and TCP times), a summary table and a plain
verdict per host and profile.

The probe is not a second client: Naive entries go through naive::CreateFor, the WSS route through the real
wss::Socket (setDiagnosticProbe switches off route-health writes), FakeTLS profiles through composeFakeTlsClientHello,
now the single place ConnectionSocket also builds its hello. The probe peeks the first server bytes to classify the
answer. Secrets are never read (random FakeTLS key, throw-away Naive credentials, only the cover domain of a secret),
hosts are ep-<8 hex of sha256(host:port)> unless real names are ticked, every log field is a closed-vocabulary token.

UI: a row in the proxy settings, an offer after a failed proxy check, share button. Tests: JVM tests of the pure
logic, a native host test against the real WssSocket.cpp and local servers (silent, fin, rst, alert, http, overloaded),
guards updated for the shared hello composer. Verified on an x86_64 emulator against lab shapes and the real relay.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-29 12:36:51 +00:00

22 lines
1.2 KiB
C++

#ifndef TGNET_FAKE_TLS_CLIENT_HELLO_H
#define TGNET_FAKE_TLS_CLIENT_HELLO_H
#include <stdint.h>
#include <string>
// The single place where the FakeTLS ClientHello of an MTProxy connection is composed (defined in
// ConnectionSocket.cpp next to the profile templates). ConnectionSocket calls it for every real connection and the
// "Check connection" probe (tgnet/pathtest) calls it for every profile, so the diagnostic cannot send anything the
// client would not.
//
// Fills |buffer| with the hello of |profile| for |sni|, checks it against the relay contract (|secretDomain|), and
// mixes the 16-byte |secret| and |currentTime| into the random field (HMAC-SHA256, timestamp XOR). |buffer| must
// hold MT_PROXY_SERVER_FLIGHT_MAX_BYTES + 32 bytes (the digest is staged after the hello). The probe passes a
// random 16-byte key: it never reads the user's secret.
bool composeFakeTlsClientHello(int32_t profile, const std::string &sni, const std::string &secretDomain,
const std::string &secret, int32_t currentTime, uint8_t *buffer, uint32_t *size);
// Name of the profile the way the client logs it ("yandex", "chrome_modern", ...).
const char *fakeTlsProfileName(int32_t profile);
#endif