Now deserialized answer is an object.

name = tl_elem.predicate
It can help us  avoid keys collision in case of TL element has parameter "name"
This commit is contained in:
Anton Grigoryev 2015-04-11 09:43:13 +03:00
parent 26fe19a228
commit 308b76fce1
2 changed files with 10 additions and 7 deletions

9
TL.py
View File

@ -34,6 +34,10 @@ class TlMethod:
self.params = json_dict['params'] self.params = json_dict['params']
class TLObject(dict):
def __init__(self, tl_elem):
self.name = tl_elem.predicate
class TL: class TL:
def __init__(self, filename): def __init__(self, filename):
with open(filename, 'r') as f: with open(filename, 'r') as f:
@ -157,8 +161,9 @@ def deserialize(bytes_io, type_=None, subtype=None):
if tl_elem.type in base_boxed_types: if tl_elem.type in base_boxed_types:
x = deserialize(bytes_io, type_=tl_elem.predicate, subtype=subtype) x = deserialize(bytes_io, type_=tl_elem.predicate, subtype=subtype)
else: # other types else: # other types
x = {} x = TLObject(tl_elem)
x[u'name'] = tl_elem.predicate
for arg in tl_elem.params: for arg in tl_elem.params:
x[arg['name']] = deserialize(bytes_io, type_=arg['type'], subtype=arg['subtype']) x[arg['name']] = deserialize(bytes_io, type_=arg['type'], subtype=arg['subtype'])
return x return x

View File

@ -115,12 +115,10 @@ class Session:
(message_id, message_length) = struct.unpack("<8sI", packet[12:24]) (message_id, message_length) = struct.unpack("<8sI", packet[12:24])
data = packet[24:24+message_length] data = packet[24:24+message_length]
elif auth_key_id == self.auth_key_id: elif auth_key_id == self.auth_key_id:
print("WOW! Encrypted data!")
message_key = packet[12:28] message_key = packet[12:28]
encrypted_data = packet[28:-4] encrypted_data = packet[28:-4]
aes_key, aes_iv = self.aes_calculate(message_key, direction="from server") aes_key, aes_iv = self.aes_calculate(message_key, direction="from server")
decrypted_data = crypt.ige_decrypt(encrypted_data, aes_key, aes_iv) decrypted_data = crypt.ige_decrypt(encrypted_data, aes_key, aes_iv)
vis(decrypted_data)
assert decrypted_data[0:8] == self.server_salt assert decrypted_data[0:8] == self.server_salt
assert decrypted_data[8:16] == self.session_id assert decrypted_data[8:16] == self.session_id
message_id = decrypted_data[16:24] message_id = decrypted_data[16:24]
@ -250,7 +248,7 @@ class Session:
assert Set_client_DH_params_answer['nonce'] == nonce assert Set_client_DH_params_answer['nonce'] == nonce
assert Set_client_DH_params_answer['server_nonce'] == server_nonce assert Set_client_DH_params_answer['server_nonce'] == server_nonce
if Set_client_DH_params_answer['name'] == 'dh_gen_ok': if Set_client_DH_params_answer.name == 'dh_gen_ok':
assert Set_client_DH_params_answer['new_nonce_hash1'] == new_nonce_hash1 assert Set_client_DH_params_answer['new_nonce_hash1'] == new_nonce_hash1
print("Diffie Hellman key exchange processed successfully") print("Diffie Hellman key exchange processed successfully")
@ -259,10 +257,10 @@ class Session:
self.auth_key_id = auth_key_sha[-8:] self.auth_key_id = auth_key_sha[-8:]
print("Auth key generated") print("Auth key generated")
return "Auth Ok" return "Auth Ok"
elif Set_client_DH_params_answer['name'] == 'dh_gen_retry': elif Set_client_DH_params_answer.name == 'dh_gen_retry':
assert Set_client_DH_params_answer['new_nonce_hash2'] == new_nonce_hash2 assert Set_client_DH_params_answer['new_nonce_hash2'] == new_nonce_hash2
print ("Retry Auth") print ("Retry Auth")
elif Set_client_DH_params_answer['name'] == 'dh_gen_fail': elif Set_client_DH_params_answer.name == 'dh_gen_fail':
assert Set_client_DH_params_answer['new_nonce_hash3'] == new_nonce_hash3 assert Set_client_DH_params_answer['new_nonce_hash3'] == new_nonce_hash3
print("Auth Failed") print("Auth Failed")
raise Exception("Auth Failed") raise Exception("Auth Failed")