1- from amtproxy .encryption .crypto import Encryptor , Decryptor
2- from amtproxy .config import secret , telegram_ips , mtproto_footprint , obf_footprint
3- from amtproxy .exceptions import WrongServerID
4- from amtproxy .protocols .telegram import TelegramProtocol
1+ from .encryption .crypto import Encryptor , Decryptor
2+ from .config import telegram_ips , mtproto_footprint , obf_footprint
3+ from .exceptions import WrongSecret
4+ from .protocols .telegram import TelegramProtocol
55
66
77class Dispatcher :
8- def __init__ (self , loop , real_protocol ):
8+ def __init__ (self , loop , real_protocol , secret ):
99 self .loop = loop
10+ self .secret = secret
1011 self .real_protocol = real_protocol
1112 self .telegram_protocol = None
1213 self .telegram_transport = None
@@ -15,14 +16,20 @@ def __init__(self, loop, real_protocol):
1516
1617 async def handle (self , raw_data : bytes ):
1718 if not self .encryptor or not self .decryptor :
18- self .decryptor = Decryptor (raw_data , secret )
19- self .encryptor = Encryptor (raw_data , secret )
19+ self .decryptor = Decryptor (raw_data , self . secret )
20+ self .encryptor = Encryptor (raw_data , self . secret )
2021 self .decoded_data = await self .decryptor (raw_data )
2122 server_id = int .from_bytes (self .decoded_data [60 :62 ], 'little' ) - 1
2223 if server_id < 0 or server_id > len (telegram_ips ):
23- raise WrongServerID (f'Got id { server_id } ' )
24+ raise WrongSecret (f'Got id { server_id } ' )
2425 self .telegram_server_ip = telegram_ips [server_id ]
25- assert self .decoded_data [56 :60 ] == mtproto_footprint or self .decoded_data [56 :60 ] == obf_footprint , self .decoded_data [56 :60 ]
26+ if self .decoded_data [56 :60 ] == mtproto_footprint :
27+ pass
28+ elif self .decoded_data [56 :60 ] == obf_footprint :
29+ # TODO dd prefix (padding)
30+ pass
31+ else :
32+ raise Exception ('Unknown Protocol' )
2633 if not self .telegram_protocol or not self .telegram_transport :
2734 self .telegram_transport , self .telegram_protocol = await self .loop .create_connection (lambda : TelegramProtocol (self .loop , self ),
2835 self .telegram_server_ip , 443 )
0 commit comments