From d25442345e327d8c05dac48083551ae42f85b9a8 Mon Sep 17 00:00:00 2001 From: "Dmitry D. Chernov" Date: Tue, 12 Feb 2019 21:17:08 +1000 Subject: [PATCH] Fix incorrect sending of DC id when connecting to MTProxy --- telethon/network/connection/tcpmtproxy.py | 3 +-- telethon/network/connection/tcpobfuscated.py | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/telethon/network/connection/tcpmtproxy.py b/telethon/network/connection/tcpmtproxy.py index ed437a28..570d4267 100644 --- a/telethon/network/connection/tcpmtproxy.py +++ b/telethon/network/connection/tcpmtproxy.py @@ -36,5 +36,4 @@ class ConnectionTcpMTProxy(ConnectionTcpObfuscated): def _compose_tail(self, data): dc_id_bytes = self._dc_id.to_bytes(2, "little", signed=True) - tail_bytes = super()._compose_tail(data) - return tail_bytes[:4] + dc_id_bytes + tail_bytes[6:] + return super()._compose_tail(data[:60] + dc_id_bytes + data[62:]) diff --git a/telethon/network/connection/tcpobfuscated.py b/telethon/network/connection/tcpobfuscated.py index 6506c982..57f9f878 100644 --- a/telethon/network/connection/tcpobfuscated.py +++ b/telethon/network/connection/tcpobfuscated.py @@ -38,7 +38,6 @@ class ConnectionTcpObfuscated(ConnectionTcpAbridged): break random = bytearray(random) - random[56] = random[57] = random[58] = random[59] = 0xef random_reversed = random[55:7:-1] # Reversed (8, len=48) # Encryption has "continuous buffer" enabled @@ -50,7 +49,9 @@ class ConnectionTcpObfuscated(ConnectionTcpAbridged): self._aes_encrypt = AESModeCTR(encrypt_key, encrypt_iv) self._aes_decrypt = AESModeCTR(decrypt_key, decrypt_iv) + random[56:60] = b'\xef\xef\xef\xef' random[56:64] = self._compose_tail(bytes(random)) + self._writer.write(random) await self._writer.drain()