My fingers are typing some good stuff while my head is thinking about ponies

This commit is contained in:
Daniil Gentili 2016-09-14 23:44:12 +02:00
parent 607c966462
commit 669b6950a8
4 changed files with 6 additions and 5 deletions

View File

@ -22,7 +22,7 @@ class API
$this->session = new MTProto($params);
$future_salts = $this->get_future_salts(3);
var_dump($future_salts);
$future_salts = $this->get_future_salts(3);
$future_salts = $this->ping(3);
var_dump($future_salts);
}

View File

@ -213,7 +213,7 @@ class AuthKeyHandler extends AckHandler
}
$this->log->log('Diffie Hellman key exchange processed successfully');
$res_authorization = ['server_salt' => substr($new_nonce, 0, 8 - 0) ^ substr($server_nonce, 0, 8 - 0)];
$res_authorization = ['server_salt' => $this->struct->unpack('<Q', substr($new_nonce, 0, 8 - 0) ^ substr($server_nonce, 0, 8 - 0))[0]];
$res_authorization['auth_key'] = $auth_key_str;
$res_authorization['id'] = substr($auth_key_sha, -8);
if ($expires_in < 0) {

View File

@ -30,7 +30,7 @@ class MessageHandler extends Crypt
$message = \danog\MadelineProto\Tools::string2bin('\x00\x00\x00\x00\x00\x00\x00\x00').$message_id.$this->struct->pack('<I', strlen($message_data)).$message_data;
} else {
$seq_no = $this->generate_seq_no($content_related);
$encrypted_data = $this->settings['authorization']['temp_auth_key']['server_salt'].$this->settings['authorization']['session_id'].$message_id.$this->struct->pack('<II', $seq_no, strlen($message_data)).$message_data;
$encrypted_data = $this->struct->pack('<Q', $this->settings['authorization']['temp_auth_key']['server_salt']).$this->settings['authorization']['session_id'].$message_id.$this->struct->pack('<II', $seq_no, strlen($message_data)).$message_data;
$message_key = substr(sha1($encrypted_data, true), -16);
$padding = \phpseclib\Crypt\Random::string(\danog\MadelineProto\Tools::posmod(-strlen($encrypted_data), 16));
list($aes_key, $aes_iv) = $this->aes_calculate($message_key);
@ -62,9 +62,9 @@ class MessageHandler extends Crypt
list($aes_key, $aes_iv) = $this->aes_calculate($message_key, 'from server');
$decrypted_data = $this->ige_decrypt($encrypted_data, $aes_key, $aes_iv);
$server_salt = substr($decrypted_data, 0, 8);
$server_salt = $this->struct->unpack('<Q', substr($decrypted_data, 0, 8))[0];
if ($server_salt != $this->settings['authorization']['temp_auth_key']['server_salt']) {
throw new Exception('Server salt mismatch.');
throw new Exception('Server salt mismatch (my server salt '.$this->settings['authorization']['temp_auth_key']['server_salt'].' is not equal to server server salt '.$server_salt.').');
}
$session_id = substr($decrypted_data, 8, 8);

View File

@ -57,6 +57,7 @@ class ResponseHandler extends MsgIdHandler
}
break;
case 'new_session_created':
$this->settings['authorization']['temp_auth_key']['server_salt'] = $response['server_salt'];
$this->ack_incoming_message_id($last_received); // Acknowledge that I received the server's response
$this->log->log('new session created');
$this->log->log($response);