This commit is contained in:
danogentili 2016-08-08 19:08:35 +02:00
parent 1eb730d281
commit bf93251ee6
2 changed files with 15 additions and 3 deletions

View File

@ -132,6 +132,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
} }
$packet_length = $this->struct->unpack('<I', $packet_length_data)[0]; $packet_length = $this->struct->unpack('<I', $packet_length_data)[0];
$packet = $this->sock->read($packet_length - 4); $packet = $this->sock->read($packet_length - 4);
if ($packet_length == 4) {
throw new Exception("Server response error: " . $this->struct->unpack('<I', $packet)[0]);
}
if (!($this->newcrc32($packet_length_data.substr($packet, 0, -4)) == $this->struct->unpack('<I', substr($packet, -4))[0])) { if (!($this->newcrc32($packet_length_data.substr($packet, 0, -4)) == $this->struct->unpack('<I', substr($packet, -4))[0])) {
throw new Exception('CRC32 was not correct!'); throw new Exception('CRC32 was not correct!');
} }
@ -156,6 +159,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$message_data_length = $this->struct->unpack('<I', substr($decrypted_data, 28, 32 - 28)) [0]; $message_data_length = $this->struct->unpack('<I', substr($decrypted_data, 28, 32 - 28)) [0];
$data = substr($decrypted_data, 32, (32 + $message_data_length) - 32); $data = substr($decrypted_data, 32, (32 + $message_data_length) - 32);
} else { } else {
DebugFunctions::hex_dump($packet);
throw new Exception('Got unknown auth_key id'); throw new Exception('Got unknown auth_key id');
} }
@ -233,7 +237,9 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
// req_DH_params // req_DH_params
$this->log->log('Starting Diffie Hellman key exchange'); $this->log->log('Starting Diffie Hellman key exchange');
$server_dh_params = $this->method_call('req_DH_params', ['nonce' => $nonce, 'server_nonce' => $server_nonce, 'p' => $p_bytes, 'q' => $q_bytes, 'public_key_fingerprint' => $public_key_fingerprint, 'encrypted_data' => $encrypted_data]); $server_dh_params = $this->method_call('req_DH_params', ['nonce' => $nonce, 'server_nonce' => $server_nonce, 'p' => $p_bytes, 'q' => $q_bytes, 'public_key_fingerprint' => $public_key_fingerprint, 'encrypted_data' => $encrypted_data]);
if ($nonce != $server_dh_params['nonce']) { if ($nonce != $server_dh_params['nonce']) {
throw new Exception('Handshake: wrong nonce.'); throw new Exception('Handshake: wrong nonce.');
} }

View File

@ -60,10 +60,16 @@ class TL
throw new Exception('Could not extract type: '.$type_); throw new Exception('Could not extract type: '.$type_);
} }
$bytes_io .= \danog\PHP\Struct::pack('<i', $tl_method->id); $bytes_io .= \danog\PHP\Struct::pack('<i', $tl_method->id);
foreach ($tl_method->params as $arg) { if (count(array_filter(array_keys($kwargs), 'is_string')) > 0) {
$bytes_io .= $this->serialize_param($arg['type'], $kwargs[$arg['name']]); foreach ($tl_method->params as $arg) {
$bytes_io .= $this->serialize_param($arg['type'], $kwargs[$arg['name']]);
}
} else {
$argcount = 0;
foreach ($tl_method->params as $arg) {
$bytes_io .= $this->serialize_param($arg['type'], $kwargs[$argcount++]);
}
} }
return $bytes_io; return $bytes_io;
} }