Cast to string to avoid issues with Bytes objects

This commit is contained in:
Daniil Gentili 2019-07-16 15:18:37 +02:00
parent c5f078cc1d
commit 005d762a8f
7 changed files with 15 additions and 14 deletions

2
docs

@ -1 +1 @@
Subproject commit dc05dc5cebfcec90ac7851928c522a4d635dbab6
Subproject commit ddb2e4f76938b69ceac6e4615901c642accae1ef

View File

@ -83,7 +83,7 @@ trait AuthKeyHandler
* ***********************************************************************
* Compute p and q
*/
$pq = new \phpseclib\Math\BigInteger($pq_bytes, 256);
$pq = new \phpseclib\Math\BigInteger((string) $pq_bytes, 256);
$q = new \phpseclib\Math\BigInteger(0);
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::auto_single($pq->__toString()));
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
@ -256,8 +256,8 @@ trait AuthKeyHandler
throw new \danog\MadelineProto\SecurityException('wrong server nonce');
}
$g = new \phpseclib\Math\BigInteger($server_DH_inner_data['g']);
$g_a = new \phpseclib\Math\BigInteger($server_DH_inner_data['g_a'], 256);
$dh_prime = new \phpseclib\Math\BigInteger($server_DH_inner_data['dh_prime'], 256);
$g_a = new \phpseclib\Math\BigInteger((string) $server_DH_inner_data['g_a'], 256);
$dh_prime = new \phpseclib\Math\BigInteger((string) $server_DH_inner_data['dh_prime'], 256);
/*
* ***********************************************************************
* Time delta

View File

@ -49,7 +49,7 @@ class RSA
{
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['rsa_encrypting'], Logger::VERBOSE);
return (new \phpseclib\Math\BigInteger($data, 256))->powMod($this->e, $this->n)->toBytes();
return (new \phpseclib\Math\BigInteger((string) $data, 256))->powMod($this->e, $this->n)->toBytes();
}
/**
* Accesses a private variable from an object

View File

@ -41,7 +41,7 @@ trait AuthKeyHandler
$dh_config = yield $this->get_dh_config_async();
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$b = new \phpseclib\Math\BigInteger($this->random(256), 256);
$params['g_a'] = new \phpseclib\Math\BigInteger($params['g_a'], 256);
$params['g_a'] = new \phpseclib\Math\BigInteger((string) $params['g_a'], 256);
$this->check_G($params['g_a'], $dh_config['p']);
$key = ['auth_key' => str_pad($params['g_a']->powMod($b, $dh_config['p'])->toBytes(), 256, chr(0), \STR_PAD_LEFT)];
//$this->logger->logger($key);
@ -87,7 +87,7 @@ trait AuthKeyHandler
return false;
}
$dh_config = yield $this->get_dh_config_async();
$params['g_a_or_b'] = new \phpseclib\Math\BigInteger($params['g_a_or_b'], 256);
$params['g_a_or_b'] = new \phpseclib\Math\BigInteger((string) $params['g_a_or_b'], 256);
$this->check_G($params['g_a_or_b'], $dh_config['p']);
$key = ['auth_key' => str_pad($params['g_a_or_b']->powMod($this->temp_requested_secret_chats[$params['id']], $dh_config['p'])->toBytes(), 256, chr(0), \STR_PAD_LEFT)];
unset($this->temp_requested_secret_chats[$params['id']]);
@ -139,10 +139,10 @@ trait AuthKeyHandler
$my_exchange_id = new \phpseclib\Math\BigInteger($this->secret_chats[$chat]['rekeying'][1], -256);
$other_exchange_id = new \phpseclib\Math\BigInteger($params['exchange_id'], -256);
//$this->logger->logger($my, $params);
if ($my_exchange_id > $other_exchange_id) {
if ($my_exchange_id->compare($other_exchange_id) > 0) {
return;
}
if ($my_exchange_id === $other_exchange_id) {
if ($my_exchange_id->compare($other_exchange_id) === 0) {
$this->secret_chats[$chat]['rekeying'] = [0];
return;
@ -152,7 +152,7 @@ trait AuthKeyHandler
$dh_config = yield $this->get_dh_config_async();
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$b = new \phpseclib\Math\BigInteger($this->random(256), 256);
$params['g_a'] = new \phpseclib\Math\BigInteger($params['g_a'], 256);
$params['g_a'] = new \phpseclib\Math\BigInteger((string) $params['g_a'], 256);
$this->check_G($params['g_a'], $dh_config['p']);
$key = ['auth_key' => str_pad($params['g_a']->powMod($b, $dh_config['p'])->toBytes(), 256, chr(0), \STR_PAD_LEFT)];
$key['fingerprint'] = substr(sha1($key['auth_key'], true), -8);
@ -175,7 +175,7 @@ trait AuthKeyHandler
}
$this->logger->logger('Committing rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->get_dh_config_async();
$params['g_b'] = new \phpseclib\Math\BigInteger($params['g_b'], 256);
$params['g_b'] = new \phpseclib\Math\BigInteger((string) $params['g_b'], 256);
$this->check_G($params['g_b'], $dh_config['p']);
$key = ['auth_key' => str_pad($params['g_b']->powMod($this->temp_rekeyed_secret_chats[$params['exchange_id']], $dh_config['p'])->toBytes(), 256, chr(0), \STR_PAD_LEFT)];
$key['fingerprint'] = substr(sha1($key['auth_key'], true), -8);

View File

@ -129,7 +129,7 @@ trait Tools
throw new TL\Exception(\danog\MadelineProto\Lang::$current_lang['length_not_8']);
}
$big = new BigInteger($value, -256);
$big = new BigInteger((string) $value, -256);
return (string) $big;
}

View File

@ -138,7 +138,7 @@ trait AuthKeyHandler
}
$this->logger->logger(sprintf(\danog\MadelineProto\Lang::$current_lang['call_confirming'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->get_dh_config_async();
$params['g_b'] = new \phpseclib\Math\BigInteger($params['g_b'], 256);
$params['g_b'] = new \phpseclib\Math\BigInteger((string) $params['g_b'], 256);
$this->check_G($params['g_b'], $dh_config['p']);
$key = str_pad($params['g_b']->powMod($this->calls[$params['id']]->storage['a'], $dh_config['p'])->toBytes(), 256, chr(0), \STR_PAD_LEFT);
$res = (yield $this->method_call_async_read('phone.confirmCall', ['key_fingerprint' => substr(sha1($key, true), -8), 'peer' => ['id' => $params['id'], 'access_hash' => $params['access_hash'], '_' => 'inputPhoneCall'], 'g_a' => $this->calls[$params['id']]->storage['g_a'], 'protocol' => ['_' => 'phoneCallProtocol', 'udp_reflector' => true, 'min_layer' => 65, 'max_layer' => \danog\MadelineProto\VoIP::getConnectionMaxLayer()]], ['datacenter' => $this->datacenter->curdc]))['phone_call'];
@ -178,7 +178,7 @@ trait AuthKeyHandler
if (hash('sha256', $params['g_a_or_b'], true) != $this->calls[$params['id']]->storage['g_a_hash']) {
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['invalid_g_a']);
}
$params['g_a_or_b'] = new \phpseclib\Math\BigInteger($params['g_a_or_b'], 256);
$params['g_a_or_b'] = new \phpseclib\Math\BigInteger((string) $params['g_a_or_b'], 256);
$this->check_G($params['g_a_or_b'], $dh_config['p']);
$key = str_pad($params['g_a_or_b']->powMod($this->calls[$params['id']]->storage['b'], $dh_config['p'])->toBytes(), 256, chr(0), \STR_PAD_LEFT);
if (substr(sha1($key, true), -8) != $params['key_fingerprint']) {

View File

@ -48,6 +48,7 @@ $settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: [];
*/
echo 'Loading MadelineProto...'.PHP_EOL;
$MadelineProto = new \danog\MadelineProto\API(getcwd().'/testing.madeline', $settings);
$MadelineProto->fileGetContents('https://google.com');
$MadelineProto->start();