feat(telegram): make MTProto usage indistinguishable from Telegram Desktop#1774
Merged
Conversation
…sktop Align gotd's MTProto usage with Telegram Desktop so a connection looks the same from the server's perspective, across three independent areas. Transport (opt-in): add PlainOptions.Obfuscated, wrapping every direct connection in Obfuscated2 with the configured codec's tag, mirroring tdesktop which always obfuscates direct connections. Combined with transport.Abridged this matches tdesktop on the wire from the first byte, instead of gotd's plain unobfuscated intermediate. Encrypted-message padding: port tdesktop's CountPaddingPrimesCount so encrypted messages get a random number of extra 16-byte padding blocks in addition to block alignment. Removes the deterministic encrypted-message length that would otherwise fingerprint the client. MTProto 2.0 compliant (12..1024 bytes, 16-byte aligned); applied globally as a strict improvement. initConnection identity (opt-in): add telegram.DeviceTDesktopWindows (device model, system/app version, lang_pack "tdesktop", tz_offset params), telegram.TimezoneParams, and telegram.TDesktopResolver to wire the transport and identity presets together. Add the tdesktop-mimic example demonstrating a login-free connectivity check using both presets. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1774 +/- ##
==========================================
+ Coverage 71.06% 71.20% +0.14%
==========================================
Files 501 502 +1
Lines 23502 23547 +45
==========================================
+ Hits 16702 16767 +65
+ Misses 5574 5552 -22
- Partials 1226 1228 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Aligns gotd's MTProto usage with Telegram Desktop so a connection is indistinguishable from tdesktop on the server side. Three independent areas, derived from the bundled tdesktop reference (
connection_tcp.cpp,session_private.cpp,mtproto_serialized_request.cpp).1. Transport: obfuscated abridged (opt-in)
tdesktop always wraps direct connections in Obfuscated2 and uses the abridged codec (
0xefefefef); gotd's default sent plain, unobfuscated intermediate (0xeeeeeeee) — different from the first byte on the wire.dcs.PlainOptions.Obfuscated: when set, all connections (not justTCPObfuscatedOnlyDCs) are wrapped in Obfuscated2 using the configured codec's tag (carried inside the obfuscation header).2. Encrypted-message padding jitter (global)
tdesktop's
CountPaddingPrimesCountaligns to 16 bytes, guarantees ≥12, then adds a random number of extra 16-byte blocks. gotd used a fixed16 + (16 - len%16), giving a deterministic encrypted length — itself a fingerprint.crypto.countPaddingnow matches tdesktop. Applied globally since it's MTProto-2.0-compliant (12..1024 bytes, 16-byte aligned) and a strict privacy improvement, not impersonation. The grammers golden vector still passes (with zero rand the jitter is 0 and padding coincides).3. initConnection identity — Windows tdesktop (opt-in)
telegram.DeviceTDesktopWindows()— device model, system/app version,lang_pack="tdesktop",tz_offsetparams.telegram.TimezoneParams()— ports tdesktop's 900s-rounded, clamped tz offset.telegram.TDesktopResolver()— the matching obfuscated abridged resolver, so the two layers can't be misconfigured.Usage
Example
examples/tdesktop-mimic— a login-free connectivity check (help.getNearestDC) using both presets, modeled onmtproxy-connect.Tests
crypto/cipher_padding_test.go— padding bounds (12..1024), 16-byte alignment, jitter, low-4-bits-only.telegram/dcs/plain_obfuscated_test.go— end-to-end: a real listener decodes the Obfuscated2 header viaobfuscated2.Acceptand confirms the abridged tag + DC id.telegram/device_test.go— tz_offset value/rounding, device fields, resolver wiring.All affected packages pass with
-race; build clean,go vetclean, gofmt clean, no generated/schema files touched.🤖 Generated with Claude Code