1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 10:19:00 +01:00

BTW I'm doing this offline

This commit is contained in:
danogentili 2016-11-17 14:52:33 +03:00
parent 5a22fd0665
commit c307357ebf
7 changed files with 45 additions and 26 deletions

View File

@ -17,7 +17,8 @@ class APIFactory
public $namespace;
public $API;
public function __construct($namespace, $API) {
public function __construct($namespace, $API)
{
$this->namespace = $namespace.'.';
$this->API = $API;
}

View File

@ -95,7 +95,8 @@ class Connection extends Tools
}
}
public function close_and_reopen() {
public function close_and_reopen()
{
$this->__destruct();
$this->__construct($this->ip, $this->port, $this->protocol);
}

View File

@ -136,13 +136,13 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
}
// Switches to a new datacenter and if necessary creates authorization keys, binds them and writes client info
public function switch_dc($new_dc, $allow_nearestdc_switch = false)
public function switch_dc($new_dc, $allow_nearest_dc_switch = false)
{
\danog\MadelineProto\Logger::log('Switching to DC '.$new_dc.'...');
if ($this->datacenter->dc_connect($new_dc)) {
$this->init_authorization();
$this->write_client_info();
$this->bind_temp_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $allow_nearestdc_switch);
$this->bind_temp_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $allow_nearest_dc_switch);
}
}
@ -164,23 +164,23 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
public function write_client_info($allow_switch) {
\danog\MadelineProto\Logger::log('Writing client info...');
$nearestDc = $this->method_call(
$nearest_dc = $this->method_call(
'invokeWithLayer',
[
'layer' => $this->settings['tl_schema']['layer'],
'query' => $this->tl->serialize_method('initConnection',
array_merge(
$this->settings['app_info'],
['query' => $this->tl->serialize_method('help.getNearestDc', [])]
['query' => $this->tl->serialize_method('help.getnearest_dc', [])]
)
),
]
);
\danog\MadelineProto\Logger::log('Current dc is '.$nearestDc['this_dc'].', nearest dc is '.$nearestDc['nearest_dc'].' in '.$nearestDc['country'].'.');
\danog\MadelineProto\Logger::log('Current dc is '.$nearest_dc['this_dc'].', nearest dc is '.$nearest_dc['nearest_dc'].' in '.$nearest_dc['country'].'.');
if ($nearestDc['nearest_dc'] != $nearestDc['this_dc'] && $allow_switch) {
$this->switch_dc($nearestDc['nearest_dc']);
$this->settings['connection_settings']['default_dc'] = $nearestDc['nearest_dc'];
if ($nearest_dc['nearest_dc'] != $nearest_dc['this_dc'] && $allow_switch) {
$this->switch_dc($nearest_dc['nearest_dc']);
$this->settings['connection_settings']['default_dc'] = $nearest_dc['nearest_dc'];
}
}

View File

@ -153,10 +153,10 @@ class AuthKeyHandler extends AckHandler
* string $encrypted_data
* ]
* @return Server_DH_Params [
* int128 $nonce : The value of nonce is selected randomly by the server
* int128 $nonce : The value of nonce is selected randomly by the server
* int128 $server_nonce : The value of server_nonce is selected randomly by the server
* string $new_nonce_hash : Return this value If server responds is server_DH_params_fail
* string $encrypted_answer : Return this value If server responds is server_DH_params_ok
* string $new_nonce_hash : Return this value if server responds with server_DH_params_fail
* string $encrypted_answer : Return this value if server responds with server_DH_params_ok
* ]
*/
//
@ -271,19 +271,31 @@ class AuthKeyHandler extends AckHandler
/*
* ***********************************************************************
* Check validity of dh_prime
* 2^2047 < dh_prime < 2^2048
* Is it a prime?
*/
if (!$dh_prime->isPrime()) {
throw new Exception("dh_prime isn't a safe 2048-bit prime (dh_prime isn't a prime).");
}
/*
* ***********************************************************************
* Check validity of dh_prime
* Is (dh_prime - 1) / 2 a prime?
*
* Almost always fails
*/
/*
// Almost always fails
if (!$dh_prime->subtract($one)->divide($two)[0]->isPrime()) {
throw new Exception("dh_prime isn't a safe 2048-bit prime ((dh_prime - 1) / 2 isn't a prime).");
}
*/
/*
* ***********************************************************************
* Check validity of dh_prime
* 2^2047 < dh_prime < 2^2048
*/
if ($dh_prime->compare($twoe2047) <= 0 // 2^2047 < dh_prime or dh_prime > 2^2047 or ! dh_prime <= 2^2047
|| $dh_prime->compare($twoe2048) >= 0 // dh_prime < 2^2048 or ! dh_prime >= 2^2048
) {
@ -322,7 +334,7 @@ class AuthKeyHandler extends AckHandler
* 1 < g_b < dh_prime - 1
*/
if ($g_b->compare($one) <= 0 // 1 < g_b or g_b > 1 or ! g_b <= 1
|| $g_b->compare($dh_prime->subtract($one)) >= 0 // g_b < dh_prime - 1 or ! g_b >= dh_prime - 1
|| $g_b->compare($dh_prime->subtract($one)) >= 0 // g_b < dh_prime - 1 or ! g_b >= dh_prime - 1
) {
throw new Exception('g_b is invalid (1 < g_b < dh_prime - 1 is false).');
}
@ -340,7 +352,8 @@ class AuthKeyHandler extends AckHandler
* string $g_b : g^b mod dh_prime
* ]
*/
$data = $this->tl->serialize_obj('client_DH_inner_data',
$data = $this->tl->serialize_obj(
'client_DH_inner_data',
[
'nonce' => $nonce,
'server_nonce' => $server_nonce,
@ -369,12 +382,13 @@ class AuthKeyHandler extends AckHandler
* @return Set_client_DH_params_answer [
* string $_ : This value is dh_gen_ok, dh_gen_retry OR dh_gen_fail
* int128 $server_nonce : The value of server_nonce is selected randomly by the server
* int128 $new_nonce_hash1 : Return this value If server responds is dh_gen_ok
* int128 $new_nonce_hash2 : Return this value If server responds is dh_gen_retry
* int128 $new_nonce_hash2 : Return this value If server responds is dh_gen_fail
* int128 $new_nonce_hash1 : Return this value if server responds with dh_gen_ok
* int128 $new_nonce_hash2 : Return this value if server responds with dh_gen_retry
* int128 $new_nonce_hash2 : Return this value if server responds with dh_gen_fail
* ]
*/
$Set_client_DH_params_answer = $this->method_call('set_client_DH_params',
$Set_client_DH_params_answer = $this->method_call(
'set_client_DH_params',
[
'nonce' => $nonce,
'server_nonce' => $server_nonce,

View File

@ -67,11 +67,14 @@ class MsgIdHandler extends MessageHandler
public function generate_message_id()
{
$int_message_id = (int) ((time() + $this->datacenter->time_delta) << 32);
/* $int_message_id = (int) (
/*
$int_message_id = (int) (
((int) ($ms_time / 1000) << 32) |
($this->posmod($ms_time, 1000) << 22) |
rand(0, 524288) << 2
);*/
);
*/
$keys = array_keys($this->outgoing_messages);
asort($keys);
$keys = end($keys);

View File

@ -20,11 +20,11 @@ class SaltHandler extends ResponseHandler
public function add_salts($salts)
{
foreach ($salts as $salt) {
$this->addsalt($salt['valid_since'], $salt['valid_until'], $salt['salt']);
$this->add_salt($salt['valid_since'], $salt['valid_until'], $salt['salt']);
}
}
public function addsalt($valid_since, $valid_until, $salt)
public function add_salt($valid_since, $valid_until, $salt)
{
if (!isset($this->datacenter->temp_auth_key['salts'][$salt])) {
$this->datacenter->temp_auth_key['salts'][$salt] = ['valid_since' => $valid_since, 'valid_until' => $valid_until];

View File

@ -14,7 +14,7 @@ If not, see <http://www.gnu.org/licenses/>.
require_once 'vendor/autoload.php';
$MadelineProto = new \danog\MadelineProto\API();
var_dump(strlen(var_export($MadelineProto,true)));
var_dump(strlen(var_export($MadelineProto, true)));
if (file_exists('number.php')) {
include_once 'number.php';
$sendCode = $MadelineProto->auth->sendCode(