MtProtoKit: align FakeTLS ClientHello with current Chrome (JA3/JA4) + per-connection extension shuffle#168
Open
Lawliet2012 wants to merge 4 commits into
Open
Conversation
… per-connection extension shuffle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since 2026-06-05 RKN started dropping Telegram FakeTLS (
ee-secret / SNI-fronted MTProxy) flows by ClientHello fingerprint (JA3 / JA4). The greeting is built insubmodules/MtProtoKit/Sources/MTTcpConnection.m→executeGenerationCode()(the byte-code template at line ~481) and sent atMTTcpConnection.m:1086-1111.Two problems with the current template:
< … >choice points (cipher list ×2, ALPN ×2), so the whole client base collapses to ~2 normalized fingerprints. One blocklist entry kills everyone.Measured (from real packet captures)
Ground-truth ClientHellos taken from the reference captures in
telemt/tdlib-obf(docs/Samples/Traffic dumps/Linux, desktop/clienthello-*.pcapng), normalized JA4:t13d1516h2_8daaf6152771_d8a2da3f94cd59e2ca82423690f86226a98c2ac63c51t13d1516h2_8daaf6152771_d8a2da3f94cd6e6c9a8e99cf26cda448839203451bdet13d1717h2_5b57614c22b0_3cbfd9057e0d6f7889b9fb1a62a9577e685c1fcfa919t13d1313h1_f57a46bbacb6_7f0f34a4126d8527da8b8a640065e72ec6b6f99764f3t13d2013h2_a09f3c656075_7f0f34a4126decdf4f49dd59effc439639da29186671Note Telegram Desktop already produces the exact Chrome 144 JA4 (it shuffles extension order per connection, so its JA3 differs from Chrome while JA4 is identical). This PR brings the iOS / MtProtoKit greeting to the same parity. Variant B above advertises 20 cipher suites mixing TLS 1.3 with legacy RSA/3DES (
0x009d,0x009c,0x0035,0x002f,0xc008,0xc012,0x000a) — no shipping browser sends that; it is a fingerprint on its own.What changes on the wire
Cipher suites (GREASE excluded):
Extensions (types, GREASE excluded):
Added to match Chrome:
session_ticket(0x0023),encrypted_client_hello(0xfe0d),application_settings(0x44cd);supported_groupstrimmed to Chrome's{X25519MLKEM768, x25519, secp256r1, secp384r1};signature_algorithmsset to Chrome's 8; ALPN keepsh2,http/1.1.Diff (two changes,
MTTcpConnection.monly)Shuffleop. Add{ (item) (item) … }: collect the items (reusing the existing(…)alternative parsing), then emit them in a per-connection random order (Fisher–Yates overarc4random_uniform). Two new single-char opcodes{/}; existing opcodes untouched. ~25 lines, modeled on the existingBeginChoicecase.executeGenerationCodetemplate. Cipher list + extension set above, with the extension block wrapped in{ … }so order — hence JA3 — varies per connection like BoringSSL/Chrome.Net effect: JA4 =
t13d1516h2_8daaf6152771_d8a2da3f94cd(Chrome 144) on every connection; JA3 different on every connection.Verification (reproducible)
1. Fingerprint — the greeting interpreter from this file compiles standalone; ran the patched template 400×:
2. Protocol — fed the generated greetings to a live MTProto proxy (telemt) over TCP, validating the FakeTLS contract end to end:
This is safe by construction: the server authenticates the greeting via HMAC-SHA256 over the record with the 32-byte ClientHello random zeroed (
MTTcpConnection.m:1099,1109), so ClientHello content (ciphers/extensions/order) is fingerprint-only and never part of authentication. HMAC injection at offset 11 and the>= 513-byte guard (:1087) are unchanged; the new greeting is 1550 bytes.Every JA4 above is reproducible from those captures with the public FoxIO
ja4tool; the patched greeting's bytes are produced by the interpreter in this file (re-implemented as a stdlib-only Python script and cross-checked against the in-file C interpreter compiled standalone with clang). Harness available on request.3. Not done: running inside a full on-device app build. A test build / on-device confirmation would be very welcome — happy to help.
Scope
emulate_tlspath). No effect on direct connections.encrypted_client_hello (0xfe0d)is included as a minimal GREASE-shaped extension (type present, which is what JA3/JA4 key on). Making its inner bytes byte-faithful to Chrome's GREASE ECH is a sensible follow-up for deep-DPI realism.