Skip to content
This repository was archived by the owner on Apr 5, 2026. It is now read-only.

Commit 052f718

Browse files
committed
fix: propagate client transport tag to DC in direct mode (#64)
The proxy always sent 0xeeeeeeee (intermediate, no padding) in the obfuscated2 init to Telegram DCs, regardless of what the client used. When clients use 0xdddddddd (random padding) — which ALL clients do (both dd-prefix and ee-prefix modes) — the DC received padded messages but expected non-padded, causing parse errors and silent failures. Fix: store the client's transport tag in extra_int3 and propagate it through direct_connect_to_dc to tcp_direct_dc_connected, which now uses it in the DC-bound init instead of the hardcoded 0xeeeeeeee. Closes #64
1 parent e69983a commit 052f718

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ jobs:
173173
174174
# Obfuscated2 direct-mode proxy (no proxy-secret/proxy-multi.conf needed)
175175
./mtproto-proxy -u nobody -p 8888 -H 8443 -S $SECRET \
176-
--http-stats --direct -M 0 -v 2>obfs2.log &
176+
--http-stats --direct -M 0 -v -v -v 2>obfs2.log &
177177
echo "Started obfs2 direct-mode proxy on port 8443"
178178
179179
# Fake-TLS direct-mode proxy
180180
./mtproto-proxy -u nobody -p 9888 -H 9443 -S $SECRET \
181-
--http-stats --direct -D ya.ru -M 0 -v 2>faketls.log &
181+
--http-stats --direct -D ya.ru -M 0 -v -v -v 2>faketls.log &
182182
echo "Started fake-TLS direct-mode proxy on port 9443"
183183
184184
# Wait for both proxies to be ready

net/net-tcp-rpc-ext-server.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,12 @@ static int tcp_direct_dc_connected (connection_job_t C) {
319319
*(unsigned *)(init + 4) == 0x00000000
320320
);
321321

322-
/* Set protocol tag (intermediate transport) and target DC */
323-
*(unsigned *)(init + 56) = 0xeeeeeeee;
322+
/* Set protocol tag matching the client's transport and target DC */
323+
unsigned client_tag = (unsigned)D->extra_int3;
324+
if (!client_tag) {
325+
client_tag = 0xeeeeeeee; /* fallback: intermediate */
326+
}
327+
*(unsigned *)(init + 56) = client_tag;
324328
*(short *)(init + 60) = (short)target_dc;
325329

326330
/* Derive AES keys -- NO secret mixing (DCs don't know proxy secret).
@@ -415,8 +419,9 @@ static int direct_connect_to_dc (connection_job_t C, int target_dc) {
415419
return 0;
416420
}
417421

418-
/* Store target DC in the DC connection for the connected callback */
422+
/* Store target DC and client transport tag for the connected callback */
419423
TCP_RPC_DATA(EJ)->extra_int4 = target_dc;
424+
TCP_RPC_DATA(EJ)->extra_int3 = TCP_RPC_DATA(C)->extra_int3; /* client transport tag */
420425

421426
/* Switch client to direct relay mode (keeps existing AES crypto) */
422427
if (c->flags & C_IS_TLS) {
@@ -1608,6 +1613,7 @@ int tcp_rpcs_compact_parse_execute (connection_job_t C) {
16081613
int target = *(short *)(random_header + 60);
16091614
D->extra_int4 = target;
16101615
D->extra_int2 = secret_id + 1;
1616+
D->extra_int3 = (int)tag; /* client transport tag for direct mode */
16111617
vkprintf (1, "tcp opportunistic encryption mode detected, tag = %08x, target=%d, secret [%s]\n", tag, target, ext_secret_label[secret_id]);
16121618
ok = 1;
16131619
break;

0 commit comments

Comments
 (0)