0

I am trying to follow Telegram's authorization sample but do not get any response from the server:

msg = """

0000 | 00 00 00 00 00 00 00 00 4A 96 70 27 C4 7A E5 51
0010 | 14 00 00 00 78 97 46 60 3E 05 49 82 8C CA 27 E9
0020 | 66 B3 01 A4 8F EC E2 FC

"""

import re
msg = re.sub('\d{4} \| ', '', msg)
msg = re.sub('\s+', '', msg)
msg = bytes.fromhex(msg)

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('149.154.167.40', 443))
s.send(msg)
print(s.recv(1024))  # prints: b''
s.close()

Why?

Andrei
  • 10,918
  • 12
  • 76
  • 110
  • You *really* shouldn't be using hand-crafted packets to talk to Telegram. The first step is to have some code that can translate the TL language into, in your case, Python. There are many existing libraries to interact with the API (for Python too) that you should probably take a look at. – Lonami Oct 24 '17 at 17:01
  • You are trying to make a SSL connection, see [here](https://stackoverflow.com/questions/26851034/opening-a-ssl-socket-connection-in-python) – whenisnever Oct 24 '17 at 17:06
  • @whenisnever nope. telegram is just that bozotic. – habnabit Oct 24 '17 at 17:08
  • @whenisnever Telegram uses their own encryption so I am not sure about SSL. – Andrei Oct 24 '17 at 17:17

1 Answers1

0

Yes, @habnabit, it was the TCP headers that were missing. I thought they were handled by Python since I haven't seen that part in other clients. Found it in Telethon, thanks for the tip.

import struct
import zlib
msg = struct.pack('<ii', len(msg) + 12, counter) + msg
msg += struct.pack('<I', zlib.crc32(msg))
Andrei
  • 10,918
  • 12
  • 76
  • 110