Update phpseclib
This commit is contained in:
parent
d559b1d8b6
commit
c8ed5971d9
@ -17,7 +17,7 @@
|
|||||||
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpseclib\Math;
|
namespace phpseclib3\Math;
|
||||||
|
|
||||||
if (PHP_MAJOR_VERSION < 7 && !(\class_exists(\Phar::class) && \Phar::running())) {
|
if (PHP_MAJOR_VERSION < 7 && !(\class_exists(\Phar::class) && \Phar::running())) {
|
||||||
throw new \Exception('MadelineProto requires php 7 to run natively, use phar.madelineproto.xyz to run on PHP 5.6');
|
throw new \Exception('MadelineProto requires php 7 to run natively, use phar.madelineproto.xyz to run on PHP 5.6');
|
||||||
@ -26,7 +26,7 @@ if (\defined('HHVM_VERSION')) {
|
|||||||
$engines = [['PHP64', ['OpenSSL']], ['BCMath', ['OpenSSL']], ['PHP32', ['OpenSSL']]];
|
$engines = [['PHP64', ['OpenSSL']], ['BCMath', ['OpenSSL']], ['PHP32', ['OpenSSL']]];
|
||||||
foreach ($engines as $engine) {
|
foreach ($engines as $engine) {
|
||||||
try {
|
try {
|
||||||
\phpseclib\Math\BigInteger::setEngine($engine[0], isset($engine[1]) ? $engine[1] : []);
|
\phpseclib3\Math\BigInteger::setEngine($engine[0], isset($engine[1]) ? $engine[1] : []);
|
||||||
break;
|
break;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,10 @@ class API extends InternalDoc
|
|||||||
$tounserialize = \str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $tounserialize);
|
$tounserialize = \str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $tounserialize);
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
|
if (\strpos($tounserialize, 'C:25:"phpseclib\Math\BigInteger') !== false) {
|
||||||
|
$tounserialize = \str_replace('C:25:"phpseclib\Math\BigInteger', 'C:26:"phpseclib3\Math\BigInteger', $tounserialize);
|
||||||
|
$changed = true;
|
||||||
|
}
|
||||||
if (\strpos($e->getMessage(), "Erroneous data format for unserializing 'phpseclib\\Math\\BigInteger'") === 0) {
|
if (\strpos($e->getMessage(), "Erroneous data format for unserializing 'phpseclib\\Math\\BigInteger'") === 0) {
|
||||||
$tounserialize = \str_replace('phpseclib\\Math\\BigInteger', 'phpseclib\\Math\\BigIntegor', $tounserialize);
|
$tounserialize = \str_replace('phpseclib\\Math\\BigInteger', 'phpseclib\\Math\\BigIntegor', $tounserialize);
|
||||||
$changed = true;
|
$changed = true;
|
||||||
|
@ -4323,7 +4323,7 @@ class InternalDoc extends APIFactory
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function checkG(\phpseclib\Math\BigInteger $g_a, \phpseclib\Math\BigInteger $p, array $extra = []): bool
|
public function checkG(\phpseclib3\Math\BigInteger $g_a, \phpseclib3\Math\BigInteger $p, array $extra = []): bool
|
||||||
{
|
{
|
||||||
return $this->__call(__FUNCTION__, [$g_a, $p, $extra]);
|
return $this->__call(__FUNCTION__, [$g_a, $p, $extra]);
|
||||||
}
|
}
|
||||||
@ -4335,7 +4335,7 @@ class InternalDoc extends APIFactory
|
|||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function checkPG(\phpseclib\Math\BigInteger $p, \phpseclib\Math\BigInteger $g, array $extra = []): bool
|
public function checkPG(\phpseclib3\Math\BigInteger $p, \phpseclib3\Math\BigInteger $g, array $extra = []): bool
|
||||||
{
|
{
|
||||||
return $this->__call(__FUNCTION__, [$p, $g, $extra]);
|
return $this->__call(__FUNCTION__, [$p, $g, $extra]);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ class Lang
|
|||||||
'encode_double_error' => 'Non sono riuscito a codificare il numero a virgola mobile fornito',
|
'encode_double_error' => 'Non sono riuscito a codificare il numero a virgola mobile fornito',
|
||||||
'file_not_exist' => 'Il file specificato non esiste',
|
'file_not_exist' => 'Il file specificato non esiste',
|
||||||
'deserialization_error' => 'C\'è stato un errore durante la deserializzazione',
|
'deserialization_error' => 'C\'è stato un errore durante la deserializzazione',
|
||||||
'rsa_init' => 'Istanziamento di \\phpseclib\\Crypt\\RSA in corso...',
|
'rsa_init' => 'Istanziamento di \\phpseclib3\\Crypt\\RSA in corso...',
|
||||||
'loading_key' => 'Caricamento della chiave in corso...',
|
'loading_key' => 'Caricamento della chiave in corso...',
|
||||||
'computing_fingerprint' => 'Calcolo del fingerprint in corso...',
|
'computing_fingerprint' => 'Calcolo del fingerprint in corso...',
|
||||||
'rsa_encrypting' => 'Criptando con chiave RSA...',
|
'rsa_encrypting' => 'Criptando con chiave RSA...',
|
||||||
@ -204,7 +204,7 @@ class Lang
|
|||||||
'encode_double_error' => 'Could not properly encode double',
|
'encode_double_error' => 'Could not properly encode double',
|
||||||
'file_not_exist' => 'File does not exist',
|
'file_not_exist' => 'File does not exist',
|
||||||
'deserialization_error' => 'An error occurred on deserialization',
|
'deserialization_error' => 'An error occurred on deserialization',
|
||||||
'rsa_init' => 'Istantiating \\phpseclib\\Crypt\\RSA...',
|
'rsa_init' => 'Istantiating \\phpseclib3\\Crypt\\RSA...',
|
||||||
'loading_key' => 'Loading key...',
|
'loading_key' => 'Loading key...',
|
||||||
'computing_fingerprint' => 'Computing fingerprint...',
|
'computing_fingerprint' => 'Computing fingerprint...',
|
||||||
'rsa_encrypting' => 'Encrypting with rsa key...',
|
'rsa_encrypting' => 'Encrypting with rsa key...',
|
||||||
@ -5291,7 +5291,7 @@ class Lang
|
|||||||
'encode_double_error' => 'Could not properly encode double',
|
'encode_double_error' => 'Could not properly encode double',
|
||||||
'file_not_exist' => 'File does not exist',
|
'file_not_exist' => 'File does not exist',
|
||||||
'deserialization_error' => 'An error occurred on deserialization',
|
'deserialization_error' => 'An error occurred on deserialization',
|
||||||
'rsa_init' => 'Istantiating \\phpseclib\\Crypt\\RSA...',
|
'rsa_init' => 'Istantiating \\phpseclib3\\Crypt\\RSA...',
|
||||||
'loading_key' => 'Loading key...',
|
'loading_key' => 'Loading key...',
|
||||||
'computing_fingerprint' => 'Computing fingerprint...',
|
'computing_fingerprint' => 'Computing fingerprint...',
|
||||||
'rsa_encrypting' => 'Encrypting with rsa key...',
|
'rsa_encrypting' => 'Encrypting with rsa key...',
|
||||||
|
@ -169,7 +169,7 @@ class Lua
|
|||||||
public static function convertObjects(&$data)
|
public static function convertObjects(&$data)
|
||||||
{
|
{
|
||||||
\array_walk_recursive($data, function (&$value, $key) {
|
\array_walk_recursive($data, function (&$value, $key) {
|
||||||
if (\is_object($value) && !$value instanceof \phpseclib\Math\BigInteger) {
|
if (\is_object($value) && !$value instanceof \phpseclib3\Math\BigInteger) {
|
||||||
$newval = [];
|
$newval = [];
|
||||||
foreach (\get_class_methods($value) as $name) {
|
foreach (\get_class_methods($value) as $name) {
|
||||||
$newval[$name] = [$value, $name];
|
$newval[$name] = [$value, $name];
|
||||||
|
@ -30,13 +30,13 @@ trait MsgIdHandler
|
|||||||
public function checkMessageId($new_message_id, $aargs)
|
public function checkMessageId($new_message_id, $aargs)
|
||||||
{
|
{
|
||||||
if (!\is_object($new_message_id)) {
|
if (!\is_object($new_message_id)) {
|
||||||
$new_message_id = new \phpseclib\Math\BigInteger(\strrev($new_message_id), 256);
|
$new_message_id = new \phpseclib3\Math\BigInteger(\strrev($new_message_id), 256);
|
||||||
}
|
}
|
||||||
$min_message_id = (new \phpseclib\Math\BigInteger(\time() + $this->time_delta - 300))->bitwise_leftShift(32);
|
$min_message_id = (new \phpseclib3\Math\BigInteger(\time() + $this->time_delta - 300))->bitwise_leftShift(32);
|
||||||
if ($min_message_id->compare($new_message_id) > 0) {
|
if ($min_message_id->compare($new_message_id) > 0) {
|
||||||
$this->API->logger->logger('Given message id ('.$new_message_id.') is too old compared to the min value ('.$min_message_id.').', \danog\MadelineProto\Logger::WARNING);
|
$this->API->logger->logger('Given message id ('.$new_message_id.') is too old compared to the min value ('.$min_message_id.').', \danog\MadelineProto\Logger::WARNING);
|
||||||
}
|
}
|
||||||
$max_message_id = (new \phpseclib\Math\BigInteger(\time() + $this->time_delta + 30))->bitwise_leftShift(32);
|
$max_message_id = (new \phpseclib3\Math\BigInteger(\time() + $this->time_delta + 30))->bitwise_leftShift(32);
|
||||||
if ($max_message_id->compare($new_message_id) < 0) {
|
if ($max_message_id->compare($new_message_id) < 0) {
|
||||||
throw new \danog\MadelineProto\Exception('Given message id ('.$new_message_id.') is too new compared to the max value ('.$max_message_id.'). Consider syncing your date.');
|
throw new \danog\MadelineProto\Exception('Given message id ('.$new_message_id.') is too new compared to the max value ('.$max_message_id.'). Consider syncing your date.');
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ trait MsgIdHandler
|
|||||||
|
|
||||||
public function generateMessageId()
|
public function generateMessageId()
|
||||||
{
|
{
|
||||||
$message_id = (new \phpseclib\Math\BigInteger(\time() + $this->time_delta))->bitwise_leftShift(32);
|
$message_id = (new \phpseclib3\Math\BigInteger(\time() + $this->time_delta))->bitwise_leftShift(32);
|
||||||
if ($message_id->compare($key = $this->getMaxId($incoming = false)) <= 0) {
|
if ($message_id->compare($key = $this->getMaxId($incoming = false)) <= 0) {
|
||||||
$message_id = $key->add(\danog\MadelineProto\Magic::$four);
|
$message_id = $key->add(\danog\MadelineProto\Magic::$four);
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,11 @@ trait ResponseHandler
|
|||||||
foreach ($msg_ids as $msg_id) {
|
foreach ($msg_ids as $msg_id) {
|
||||||
$cur_info = 0;
|
$cur_info = 0;
|
||||||
if (!isset($this->incoming_messages[$msg_id])) {
|
if (!isset($this->incoming_messages[$msg_id])) {
|
||||||
$msg_id = new \phpseclib\Math\BigInteger(\strrev($msg_id), 256);
|
$msg_id = new \phpseclib3\Math\BigInteger(\strrev($msg_id), 256);
|
||||||
if ((new \phpseclib\Math\BigInteger(\time() + $this->time_delta + 30))->bitwise_leftShift(32)->compare($msg_id) < 0) {
|
if ((new \phpseclib3\Math\BigInteger(\time() + $this->time_delta + 30))->bitwise_leftShift(32)->compare($msg_id) < 0) {
|
||||||
$this->logger->logger("Do not know anything about $msg_id and it is too small");
|
$this->logger->logger("Do not know anything about $msg_id and it is too small");
|
||||||
$cur_info |= 3;
|
$cur_info |= 3;
|
||||||
} elseif ((new \phpseclib\Math\BigInteger(\time() + $this->time_delta - 300))->bitwise_leftShift(32)->compare($msg_id) > 0) {
|
} elseif ((new \phpseclib3\Math\BigInteger(\time() + $this->time_delta - 300))->bitwise_leftShift(32)->compare($msg_id) > 0) {
|
||||||
$this->logger->logger("Do not know anything about $msg_id and it is too big");
|
$this->logger->logger("Do not know anything about $msg_id and it is too big");
|
||||||
$cur_info |= 1;
|
$cur_info |= 1;
|
||||||
} else {
|
} else {
|
||||||
@ -185,7 +185,7 @@ trait ResponseHandler
|
|||||||
|
|
||||||
foreach ($this->incoming_messages[$current_msg_id]['content']['msg_ids'] as $key => $msg_id) {
|
foreach ($this->incoming_messages[$current_msg_id]['content']['msg_ids'] as $key => $msg_id) {
|
||||||
$info = \ord($this->incoming_messages[$current_msg_id]['content']['info'][$key]);
|
$info = \ord($this->incoming_messages[$current_msg_id]['content']['info'][$key]);
|
||||||
$msg_id = new \phpseclib\Math\BigInteger(\strrev($msg_id), 256);
|
$msg_id = new \phpseclib3\Math\BigInteger(\strrev($msg_id), 256);
|
||||||
$status = 'Status for message id '.$msg_id.': ';
|
$status = 'Status for message id '.$msg_id.': ';
|
||||||
/*if ($info & 4) {
|
/*if ($info & 4) {
|
||||||
*$this->gotResponseForOutgoingMessageId($msg_id);
|
*$this->gotResponseForOutgoingMessageId($msg_id);
|
||||||
@ -551,7 +551,7 @@ trait ResponseHandler
|
|||||||
return;
|
return;
|
||||||
case 16:
|
case 16:
|
||||||
case 17:
|
case 17:
|
||||||
$this->time_delta = (int) (new \phpseclib\Math\BigInteger(\strrev($response_id), 256))->bitwise_rightShift(32)->subtract(new \phpseclib\Math\BigInteger(\time()))->toString();
|
$this->time_delta = (int) (new \phpseclib3\Math\BigInteger(\strrev($response_id), 256))->bitwise_rightShift(32)->subtract(new \phpseclib3\Math\BigInteger(\time()))->toString();
|
||||||
$this->logger->logger('Set time delta to '.$this->time_delta, \danog\MadelineProto\Logger::WARNING);
|
$this->logger->logger('Set time delta to '.$this->time_delta, \danog\MadelineProto\Logger::WARNING);
|
||||||
$this->API->resetMTProtoSession();
|
$this->API->resetMTProtoSession();
|
||||||
$this->shared->setTempAuthKey(null);
|
$this->shared->setTempAuthKey(null);
|
||||||
|
@ -24,7 +24,7 @@ use danog\MadelineProto\DataCenterConnection;
|
|||||||
use danog\MadelineProto\MTProto\AuthKey;
|
use danog\MadelineProto\MTProto\AuthKey;
|
||||||
use danog\MadelineProto\MTProto\PermAuthKey;
|
use danog\MadelineProto\MTProto\PermAuthKey;
|
||||||
use danog\MadelineProto\MTProto\TempAuthKey;
|
use danog\MadelineProto\MTProto\TempAuthKey;
|
||||||
use phpseclib\Math\BigInteger;
|
use phpseclib3\Math\BigInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the creation of the authorization key.
|
* Manages the creation of the authorization key.
|
||||||
@ -108,9 +108,9 @@ trait AuthKeyHandler
|
|||||||
* ***********************************************************************
|
* ***********************************************************************
|
||||||
* Compute p and q
|
* Compute p and q
|
||||||
*/
|
*/
|
||||||
$pq = new \phpseclib\Math\BigInteger((string) $pq_bytes, 256);
|
$pq = new \phpseclib3\Math\BigInteger((string) $pq_bytes, 256);
|
||||||
$q = new \phpseclib\Math\BigInteger(0);
|
$q = new \phpseclib3\Math\BigInteger(0);
|
||||||
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::auto_single($pq->__toString()));
|
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::auto_single($pq->__toString()));
|
||||||
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
||||||
$q = $pq->divide($p)[0];
|
$q = $pq->divide($p)[0];
|
||||||
if ($p->compare($q) > 0) {
|
if ($p->compare($q) > 0) {
|
||||||
@ -119,7 +119,7 @@ trait AuthKeyHandler
|
|||||||
}
|
}
|
||||||
if (!$pq->equals($p->multiply($q))) {
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
$this->logger->logger('Automatic factorization failed, trying native CPP module', \danog\MadelineProto\Logger::ERROR);
|
$this->logger->logger('Automatic factorization failed, trying native CPP module', \danog\MadelineProto\Logger::ERROR);
|
||||||
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::native_single_cpp($pq->__toString()));
|
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::native_single_cpp($pq->__toString()));
|
||||||
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
||||||
$q = $pq->divide($p)[0];
|
$q = $pq->divide($p)[0];
|
||||||
if ($p->compare($q) > 0) {
|
if ($p->compare($q) > 0) {
|
||||||
@ -129,7 +129,7 @@ trait AuthKeyHandler
|
|||||||
|
|
||||||
if (!$pq->equals($p->multiply($q))) {
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
$this->logger->logger('Automatic factorization failed, trying alt py module', \danog\MadelineProto\Logger::ERROR);
|
$this->logger->logger('Automatic factorization failed, trying alt py module', \danog\MadelineProto\Logger::ERROR);
|
||||||
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::python_single_alt($pq->__toString()));
|
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::python_single_alt($pq->__toString()));
|
||||||
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
||||||
$q = $pq->divide($p)[0];
|
$q = $pq->divide($p)[0];
|
||||||
if ($p->compare($q) > 0) {
|
if ($p->compare($q) > 0) {
|
||||||
@ -139,7 +139,7 @@ trait AuthKeyHandler
|
|||||||
|
|
||||||
if (!$pq->equals($p->multiply($q))) {
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
$this->logger->logger('Automatic factorization failed, trying py module', \danog\MadelineProto\Logger::ERROR);
|
$this->logger->logger('Automatic factorization failed, trying py module', \danog\MadelineProto\Logger::ERROR);
|
||||||
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::python_single($pq->__toString()));
|
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::python_single($pq->__toString()));
|
||||||
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
||||||
$q = $pq->divide($p)[0];
|
$q = $pq->divide($p)[0];
|
||||||
if ($p->compare($q) > 0) {
|
if ($p->compare($q) > 0) {
|
||||||
@ -149,7 +149,7 @@ trait AuthKeyHandler
|
|||||||
|
|
||||||
if (!$pq->equals($p->multiply($q))) {
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
$this->logger->logger('Automatic factorization failed, trying native module', \danog\MadelineProto\Logger::ERROR);
|
$this->logger->logger('Automatic factorization failed, trying native module', \danog\MadelineProto\Logger::ERROR);
|
||||||
$p = new \phpseclib\Math\BigInteger(\danog\PrimeModule::native_single($pq->__toString()));
|
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::native_single($pq->__toString()));
|
||||||
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
||||||
$q = $pq->divide($p)[0];
|
$q = $pq->divide($p)[0];
|
||||||
if ($p->compare($q) > 0) {
|
if ($p->compare($q) > 0) {
|
||||||
@ -160,7 +160,7 @@ trait AuthKeyHandler
|
|||||||
if (!$pq->equals($p->multiply($q))) {
|
if (!$pq->equals($p->multiply($q))) {
|
||||||
$this->logger->logger('Automatic factorization failed, trying wolfram module', \danog\MadelineProto\Logger::ERROR);
|
$this->logger->logger('Automatic factorization failed, trying wolfram module', \danog\MadelineProto\Logger::ERROR);
|
||||||
|
|
||||||
$p = new \phpseclib\Math\BigInteger(yield $this->wolframSingle($pq->__toString()));
|
$p = new \phpseclib3\Math\BigInteger(yield $this->wolframSingle($pq->__toString()));
|
||||||
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
|
||||||
$q = $pq->divide($p)[0];
|
$q = $pq->divide($p)[0];
|
||||||
if ($p->compare($q) > 0) {
|
if ($p->compare($q) > 0) {
|
||||||
@ -284,9 +284,9 @@ trait AuthKeyHandler
|
|||||||
if ($server_nonce != $server_DH_inner_data['server_nonce']) {
|
if ($server_nonce != $server_DH_inner_data['server_nonce']) {
|
||||||
throw new \danog\MadelineProto\SecurityException('wrong server nonce');
|
throw new \danog\MadelineProto\SecurityException('wrong server nonce');
|
||||||
}
|
}
|
||||||
$g = new \phpseclib\Math\BigInteger($server_DH_inner_data['g']);
|
$g = new \phpseclib3\Math\BigInteger($server_DH_inner_data['g']);
|
||||||
$g_a = new \phpseclib\Math\BigInteger((string) $server_DH_inner_data['g_a'], 256);
|
$g_a = new \phpseclib3\Math\BigInteger((string) $server_DH_inner_data['g_a'], 256);
|
||||||
$dh_prime = new \phpseclib\Math\BigInteger((string) $server_DH_inner_data['dh_prime'], 256);
|
$dh_prime = new \phpseclib3\Math\BigInteger((string) $server_DH_inner_data['dh_prime'], 256);
|
||||||
/*
|
/*
|
||||||
* ***********************************************************************
|
* ***********************************************************************
|
||||||
* Time delta
|
* Time delta
|
||||||
@ -298,7 +298,7 @@ trait AuthKeyHandler
|
|||||||
$this->checkG($g_a, $dh_prime);
|
$this->checkG($g_a, $dh_prime);
|
||||||
for ($retry_id = 0; $retry_id <= $this->settings['max_tries']['authorization']; $retry_id++) {
|
for ($retry_id = 0; $retry_id <= $this->settings['max_tries']['authorization']; $retry_id++) {
|
||||||
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$b = new \phpseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
$b = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
||||||
$this->logger->logger('Generating g_b...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Generating g_b...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$g_b = $g->powMod($b, $dh_prime);
|
$g_b = $g->powMod($b, $dh_prime);
|
||||||
$this->checkG($g_b, $dh_prime);
|
$this->checkG($g_b, $dh_prime);
|
||||||
@ -526,8 +526,8 @@ trait AuthKeyHandler
|
|||||||
|
|
||||||
return $this->dh_config;
|
return $this->dh_config;
|
||||||
}
|
}
|
||||||
$dh_config['p'] = new \phpseclib\Math\BigInteger((string) $dh_config['p'], 256);
|
$dh_config['p'] = new \phpseclib3\Math\BigInteger((string) $dh_config['p'], 256);
|
||||||
$dh_config['g'] = new \phpseclib\Math\BigInteger($dh_config['g']);
|
$dh_config['g'] = new \phpseclib3\Math\BigInteger($dh_config['g']);
|
||||||
$this->checkPG($dh_config['p'], $dh_config['g']);
|
$this->checkPG($dh_config['p'], $dh_config['g']);
|
||||||
|
|
||||||
return $this->dh_config = $dh_config;
|
return $this->dh_config = $dh_config;
|
||||||
|
@ -47,7 +47,7 @@ trait Crypt
|
|||||||
|
|
||||||
public function ctrEncrypt($message, $key, $iv)
|
public function ctrEncrypt($message, $key, $iv)
|
||||||
{
|
{
|
||||||
$cipher = new \phpseclib\Crypt\AES('ctr');
|
$cipher = new \phpseclib3\Crypt\AES('ctr');
|
||||||
$cipher->setKey($key);
|
$cipher->setKey($key);
|
||||||
$cipher->setIV($iv);
|
$cipher->setIV($iv);
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ trait Crypt
|
|||||||
|
|
||||||
public function igeEncrypt($message, $key, $iv)
|
public function igeEncrypt($message, $key, $iv)
|
||||||
{
|
{
|
||||||
$cipher = new \phpseclib\Crypt\AES('ige');
|
$cipher = new \phpseclib3\Crypt\AES('ige');
|
||||||
$cipher->setKey($key);
|
$cipher->setKey($key);
|
||||||
$cipher->setIV($iv);
|
$cipher->setIV($iv);
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ trait Crypt
|
|||||||
}
|
}
|
||||||
public function igeDecrypt($message, $key, $iv)
|
public function igeDecrypt($message, $key, $iv)
|
||||||
{
|
{
|
||||||
$cipher = new \phpseclib\Crypt\AES('ige');
|
$cipher = new \phpseclib3\Crypt\AES('ige');
|
||||||
$cipher->setKey($key);
|
$cipher->setKey($key);
|
||||||
$cipher->setIV($iv);
|
$cipher->setIV($iv);
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ trait Files
|
|||||||
$iv = \danog\MadelineProto\Tools::random(32);
|
$iv = \danog\MadelineProto\Tools::random(32);
|
||||||
$digest = \hash('md5', $key.$iv, true);
|
$digest = \hash('md5', $key.$iv, true);
|
||||||
$fingerprint = \danog\MadelineProto\Tools::unpackSignedInt(\substr($digest, 0, 4) ^ \substr($digest, 4, 4));
|
$fingerprint = \danog\MadelineProto\Tools::unpackSignedInt(\substr($digest, 0, 4) ^ \substr($digest, 4, 4));
|
||||||
$ige = new \phpseclib\Crypt\AES('ige');
|
$ige = new \phpseclib3\Crypt\AES('ige');
|
||||||
$ige->setIV($iv);
|
$ige->setIV($iv);
|
||||||
$ige->setKey($key);
|
$ige->setKey($key);
|
||||||
$ige->enableContinuousBuffer();
|
$ige->enableContinuousBuffer();
|
||||||
@ -952,7 +952,7 @@ trait Files
|
|||||||
if ($fingerprint !== $message_media['key_fingerprint']) {
|
if ($fingerprint !== $message_media['key_fingerprint']) {
|
||||||
throw new \danog\MadelineProto\Exception('Fingerprint mismatch!');
|
throw new \danog\MadelineProto\Exception('Fingerprint mismatch!');
|
||||||
}
|
}
|
||||||
$ige = new \phpseclib\Crypt\AES('ige');
|
$ige = new \phpseclib3\Crypt\AES('ige');
|
||||||
$ige->setIV($message_media['iv']);
|
$ige->setIV($message_media['iv']);
|
||||||
$ige->setKey($message_media['key']);
|
$ige->setKey($message_media['key']);
|
||||||
$ige->enableContinuousBuffer();
|
$ige->enableContinuousBuffer();
|
||||||
|
@ -22,7 +22,7 @@ use danog\MadelineProto\Exception;
|
|||||||
use danog\MadelineProto\Magic;
|
use danog\MadelineProto\Magic;
|
||||||
use danog\MadelineProto\SecurityException;
|
use danog\MadelineProto\SecurityException;
|
||||||
use danog\MadelineProto\Tools;
|
use danog\MadelineProto\Tools;
|
||||||
use phpseclib\Math\BigInteger;
|
use phpseclib3\Math\BigInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages SRP password calculation.
|
* Manages SRP password calculation.
|
||||||
|
@ -83,7 +83,7 @@ class Magic
|
|||||||
\set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']);
|
\set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']);
|
||||||
\set_exception_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionHandler']);
|
\set_exception_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionHandler']);
|
||||||
if (!self::$inited) {
|
if (!self::$inited) {
|
||||||
if (!\defined('\\phpseclib\\Crypt\\Common\\SymmetricKey::MODE_IGE') || \phpseclib\Crypt\Common\SymmetricKey::MODE_IGE !== 7) {
|
if (!\defined('\\phpseclib3\\Crypt\\Common\\SymmetricKey::MODE_IGE') || \phpseclib3\Crypt\Common\SymmetricKey::MODE_IGE !== 7) {
|
||||||
throw new Exception(\danog\MadelineProto\Lang::$current_lang['phpseclib_fork']);
|
throw new Exception(\danog\MadelineProto\Lang::$current_lang['phpseclib_fork']);
|
||||||
}
|
}
|
||||||
foreach (['xml', 'fileinfo', 'json', 'mbstring'] as $extension) {
|
foreach (['xml', 'fileinfo', 'json', 'mbstring'] as $extension) {
|
||||||
@ -105,16 +105,16 @@ class Magic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
self::$emojis = \json_decode(self::JSON_EMOJIS);
|
self::$emojis = \json_decode(self::JSON_EMOJIS);
|
||||||
self::$zero = new \phpseclib\Math\BigInteger(0);
|
self::$zero = new \phpseclib3\Math\BigInteger(0);
|
||||||
self::$one = new \phpseclib\Math\BigInteger(1);
|
self::$one = new \phpseclib3\Math\BigInteger(1);
|
||||||
self::$two = new \phpseclib\Math\BigInteger(2);
|
self::$two = new \phpseclib3\Math\BigInteger(2);
|
||||||
self::$three = new \phpseclib\Math\BigInteger(3);
|
self::$three = new \phpseclib3\Math\BigInteger(3);
|
||||||
self::$four = new \phpseclib\Math\BigInteger(4);
|
self::$four = new \phpseclib3\Math\BigInteger(4);
|
||||||
self::$twoe1984 = new \phpseclib\Math\BigInteger('1751908409537131537220509645351687597690304110853111572994449976845956819751541616602568796259317428464425605223064365804210081422215355425149431390635151955247955156636234741221447435733643262808668929902091770092492911737768377135426590363166295684370498604708288556044687341394398676292971255828404734517580702346564613427770683056761383955397564338690628093211465848244049196353703022640400205739093118270803778352768276670202698397214556629204420309965547056893233608758387329699097930255380715679250799950923553703740673620901978370802540218870279314810722790539899334271514365444369275682816');
|
self::$twoe1984 = new \phpseclib3\Math\BigInteger('1751908409537131537220509645351687597690304110853111572994449976845956819751541616602568796259317428464425605223064365804210081422215355425149431390635151955247955156636234741221447435733643262808668929902091770092492911737768377135426590363166295684370498604708288556044687341394398676292971255828404734517580702346564613427770683056761383955397564338690628093211465848244049196353703022640400205739093118270803778352768276670202698397214556629204420309965547056893233608758387329699097930255380715679250799950923553703740673620901978370802540218870279314810722790539899334271514365444369275682816');
|
||||||
self::$twoe2047 = new \phpseclib\Math\BigInteger('16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115328');
|
self::$twoe2047 = new \phpseclib3\Math\BigInteger('16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115328');
|
||||||
self::$twoe2048 = new \phpseclib\Math\BigInteger('32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656');
|
self::$twoe2048 = new \phpseclib3\Math\BigInteger('32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656');
|
||||||
self::$twozerotwosixone = new \phpseclib\Math\BigInteger(20261);
|
self::$twozerotwosixone = new \phpseclib3\Math\BigInteger(20261);
|
||||||
self::$zeroeight = new \phpseclib\Math\BigInteger('2147483648');
|
self::$zeroeight = new \phpseclib3\Math\BigInteger('2147483648');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self::$isatty = \defined('STDOUT') && \function_exists('posix_isatty') && \posix_isatty(STDOUT);
|
self::$isatty = \defined('STDOUT') && \function_exists('posix_isatty') && \posix_isatty(STDOUT);
|
||||||
|
@ -30,13 +30,13 @@ class RSA
|
|||||||
/**
|
/**
|
||||||
* Exponent.
|
* Exponent.
|
||||||
*
|
*
|
||||||
* @var \phpseclib\Math\BigInteger
|
* @var \phpseclib3\Math\BigInteger
|
||||||
*/
|
*/
|
||||||
public $e;
|
public $e;
|
||||||
/**
|
/**
|
||||||
* Modulus.
|
* Modulus.
|
||||||
*
|
*
|
||||||
* @var \phpseclib\Math\BigInteger
|
* @var \phpseclib3\Math\BigInteger
|
||||||
*/
|
*/
|
||||||
public $n;
|
public $n;
|
||||||
/**
|
/**
|
||||||
@ -58,7 +58,7 @@ class RSA
|
|||||||
{
|
{
|
||||||
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['rsa_init'], Logger::ULTRA_VERBOSE);
|
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['rsa_init'], Logger::ULTRA_VERBOSE);
|
||||||
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['loading_key'], Logger::ULTRA_VERBOSE);
|
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['loading_key'], Logger::ULTRA_VERBOSE);
|
||||||
$key = \phpseclib\Crypt\RSA::load($rsa_key);
|
$key = \phpseclib3\Crypt\RSA::load($rsa_key);
|
||||||
$this->n = Tools::getVar($key, 'modulus');
|
$this->n = Tools::getVar($key, 'modulus');
|
||||||
$this->e = Tools::getVar($key, 'exponent');
|
$this->e = Tools::getVar($key, 'exponent');
|
||||||
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['computing_fingerprint'], Logger::ULTRA_VERBOSE);
|
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['computing_fingerprint'], Logger::ULTRA_VERBOSE);
|
||||||
@ -88,6 +88,6 @@ class RSA
|
|||||||
{
|
{
|
||||||
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['rsa_encrypting'], Logger::VERBOSE);
|
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['rsa_encrypting'], Logger::VERBOSE);
|
||||||
|
|
||||||
return (new \phpseclib\Math\BigInteger((string) $data, 256))->powMod($this->e, $this->n)->toBytes();
|
return (new \phpseclib3\Math\BigInteger((string) $data, 256))->powMod($this->e, $this->n)->toBytes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,8 @@ trait AuthKeyHandler
|
|||||||
}
|
}
|
||||||
$dh_config = yield $this->getDhConfig();
|
$dh_config = yield $this->getDhConfig();
|
||||||
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$b = new \phpseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
$b = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
||||||
$params['g_a'] = new \phpseclib\Math\BigInteger((string) $params['g_a'], 256);
|
$params['g_a'] = new \phpseclib3\Math\BigInteger((string) $params['g_a'], 256);
|
||||||
$this->checkG($params['g_a'], $dh_config['p']);
|
$this->checkG($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 = ['auth_key' => \str_pad($params['g_a']->powMod($b, $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT)];
|
||||||
//$this->logger->logger($key);
|
//$this->logger->logger($key);
|
||||||
@ -92,7 +92,7 @@ trait AuthKeyHandler
|
|||||||
$this->logger->logger('Creating secret chat with '.$user['user_id'].'...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Creating secret chat with '.$user['user_id'].'...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$dh_config = yield $this->getDhConfig();
|
$dh_config = yield $this->getDhConfig();
|
||||||
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$a = new \phpseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
$a = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
||||||
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
|
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
|
||||||
$this->checkG($g_a, $dh_config['p']);
|
$this->checkG($g_a, $dh_config['p']);
|
||||||
@ -120,7 +120,7 @@ trait AuthKeyHandler
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$dh_config = yield $this->getDhConfig();
|
$dh_config = yield $this->getDhConfig();
|
||||||
$params['g_a_or_b'] = new \phpseclib\Math\BigInteger((string) $params['g_a_or_b'], 256);
|
$params['g_a_or_b'] = new \phpseclib3\Math\BigInteger((string) $params['g_a_or_b'], 256);
|
||||||
$this->checkG($params['g_a_or_b'], $dh_config['p']);
|
$this->checkG($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)];
|
$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']]);
|
unset($this->temp_requested_secret_chats[$params['id']]);
|
||||||
@ -165,7 +165,7 @@ trait AuthKeyHandler
|
|||||||
$this->logger->logger('Rekeying secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Rekeying secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$dh_config = yield $this->getDhConfig();
|
$dh_config = yield $this->getDhConfig();
|
||||||
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Generating a...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$a = new \phpseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
$a = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
||||||
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Generating g_a...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
|
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
|
||||||
$this->checkG($g_a, $dh_config['p']);
|
$this->checkG($g_a, $dh_config['p']);
|
||||||
@ -189,8 +189,8 @@ trait AuthKeyHandler
|
|||||||
private function acceptRekey($chat, array $params): \Generator
|
private function acceptRekey($chat, array $params): \Generator
|
||||||
{
|
{
|
||||||
if ($this->secret_chats[$chat]['rekeying'][0] !== 0) {
|
if ($this->secret_chats[$chat]['rekeying'][0] !== 0) {
|
||||||
$my_exchange_id = new \phpseclib\Math\BigInteger($this->secret_chats[$chat]['rekeying'][1], -256);
|
$my_exchange_id = new \phpseclib3\Math\BigInteger($this->secret_chats[$chat]['rekeying'][1], -256);
|
||||||
$other_exchange_id = new \phpseclib\Math\BigInteger($params['exchange_id'], -256);
|
$other_exchange_id = new \phpseclib3\Math\BigInteger($params['exchange_id'], -256);
|
||||||
//$this->logger->logger($my, $params);
|
//$this->logger->logger($my, $params);
|
||||||
if ($my_exchange_id->compare($other_exchange_id) > 0) {
|
if ($my_exchange_id->compare($other_exchange_id) > 0) {
|
||||||
return;
|
return;
|
||||||
@ -204,8 +204,8 @@ trait AuthKeyHandler
|
|||||||
$this->logger->logger('Accepting rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Accepting rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$dh_config = yield $this->getDhConfig();
|
$dh_config = yield $this->getDhConfig();
|
||||||
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$b = new \phpseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
$b = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
|
||||||
$params['g_a'] = new \phpseclib\Math\BigInteger((string) $params['g_a'], 256);
|
$params['g_a'] = new \phpseclib3\Math\BigInteger((string) $params['g_a'], 256);
|
||||||
$this->checkG($params['g_a'], $dh_config['p']);
|
$this->checkG($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 = ['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);
|
$key['fingerprint'] = \substr(\sha1($key['auth_key'], true), -8);
|
||||||
@ -236,7 +236,7 @@ trait AuthKeyHandler
|
|||||||
}
|
}
|
||||||
$this->logger->logger('Committing rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger('Committing rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$dh_config = yield $this->getDhConfig();
|
$dh_config = yield $this->getDhConfig();
|
||||||
$params['g_b'] = new \phpseclib\Math\BigInteger((string) $params['g_b'], 256);
|
$params['g_b'] = new \phpseclib3\Math\BigInteger((string) $params['g_b'], 256);
|
||||||
$this->checkG($params['g_b'], $dh_config['p']);
|
$this->checkG($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 = ['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);
|
$key['fingerprint'] = \substr(\sha1($key['auth_key'], true), -8);
|
||||||
|
@ -80,12 +80,12 @@ class ObfuscatedStream implements BufferedProxyStreamInterface
|
|||||||
$keyRev = \hash('sha256', $keyRev.$this->extra['secret'], true);
|
$keyRev = \hash('sha256', $keyRev.$this->extra['secret'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->encrypt = new \phpseclib\Crypt\AES('ctr');
|
$this->encrypt = new \phpseclib3\Crypt\AES('ctr');
|
||||||
$this->encrypt->enableContinuousBuffer();
|
$this->encrypt->enableContinuousBuffer();
|
||||||
$this->encrypt->setKey($key);
|
$this->encrypt->setKey($key);
|
||||||
$this->encrypt->setIV(\substr($random, 40, 16));
|
$this->encrypt->setIV(\substr($random, 40, 16));
|
||||||
|
|
||||||
$this->decrypt = new \phpseclib\Crypt\AES('ctr');
|
$this->decrypt = new \phpseclib3\Crypt\AES('ctr');
|
||||||
$this->decrypt->enableContinuousBuffer();
|
$this->decrypt->enableContinuousBuffer();
|
||||||
$this->decrypt->setKey($keyRev);
|
$this->decrypt->setKey($keyRev);
|
||||||
$this->decrypt->setIV(\substr($reversed, 40, 16));
|
$this->decrypt->setIV(\substr($reversed, 40, 16));
|
||||||
|
@ -113,8 +113,6 @@ class DefaultStream extends Socket implements
|
|||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
\danog\MadelineProto\Logger::log('Got exception while closing stream: '.$e->getMessage());
|
\danog\MadelineProto\Logger::log('Got exception while closing stream: '.$e->getMessage());
|
||||||
} catch (\Exception $e) {
|
|
||||||
\danog\MadelineProto\Logger::log('Got exception while closing stream: '.$e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,8 +102,6 @@ class PremadeStream extends Socket implements RawStreamInterface, ProxyStreamInt
|
|||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
\danog\MadelineProto\Logger::log('Got exception while closing stream: '.$e->getMessage());
|
\danog\MadelineProto\Logger::log('Got exception while closing stream: '.$e->getMessage());
|
||||||
} catch (\Exception $e) {
|
|
||||||
\danog\MadelineProto\Logger::log('Got exception while closing stream: '.$e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ use Amp\File\StatCache;
|
|||||||
use Amp\Loop;
|
use Amp\Loop;
|
||||||
use Amp\Promise;
|
use Amp\Promise;
|
||||||
use Amp\Success;
|
use Amp\Success;
|
||||||
use phpseclib\Math\BigInteger;
|
use phpseclib3\Math\BigInteger;
|
||||||
|
|
||||||
use function Amp\ByteStream\getOutputBufferStream;
|
use function Amp\ByteStream\getOutputBufferStream;
|
||||||
use function Amp\ByteStream\getStdin;
|
use function Amp\ByteStream\getStdin;
|
||||||
@ -53,9 +53,9 @@ trait Tools
|
|||||||
{
|
{
|
||||||
//sort($ints, SORT_NUMERIC);
|
//sort($ints, SORT_NUMERIC);
|
||||||
if (\danog\MadelineProto\Magic::$bigint) {
|
if (\danog\MadelineProto\Magic::$bigint) {
|
||||||
$hash = new \phpseclib\Math\BigInteger(0);
|
$hash = new \phpseclib3\Math\BigInteger(0);
|
||||||
foreach ($ints as $int) {
|
foreach ($ints as $int) {
|
||||||
$hash = $hash->multiply(\danog\MadelineProto\Magic::$twozerotwosixone)->add(\danog\MadelineProto\Magic::$zeroeight)->add(new \phpseclib\Math\BigInteger($int))->divide(\danog\MadelineProto\Magic::$zeroeight)[1];
|
$hash = $hash->multiply(\danog\MadelineProto\Magic::$twozerotwosixone)->add(\danog\MadelineProto\Magic::$zeroeight)->add(new \phpseclib3\Math\BigInteger($int))->divide(\danog\MadelineProto\Magic::$zeroeight)[1];
|
||||||
}
|
}
|
||||||
$hash = self::unpackSignedInt(\strrev(\str_pad($hash->toBytes(), 4, "\0", STR_PAD_LEFT)));
|
$hash = self::unpackSignedInt(\strrev(\str_pad($hash->toBytes(), 4, "\0", STR_PAD_LEFT)));
|
||||||
} else {
|
} else {
|
||||||
@ -112,7 +112,7 @@ trait Tools
|
|||||||
*/
|
*/
|
||||||
public static function random(int $length): string
|
public static function random(int $length): string
|
||||||
{
|
{
|
||||||
return $length === 0 ? '' : \phpseclib\Crypt\Random::string($length);
|
return $length === 0 ? '' : \phpseclib3\Crypt\Random::string($length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +57,7 @@ trait AuthKeyHandler
|
|||||||
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['calling_user'], $user['user_id']), \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['calling_user'], $user['user_id']), \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$dh_config = yield $this->getDhConfig();
|
$dh_config = yield $this->getDhConfig();
|
||||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_a'], \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_a'], \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$a = \phpseclib\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
|
$a = \phpseclib3\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
|
||||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_g_a'], \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_g_a'], \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
|
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
|
||||||
$this->checkG($g_a, $dh_config['p']);
|
$this->checkG($g_a, $dh_config['p']);
|
||||||
@ -84,7 +84,7 @@ trait AuthKeyHandler
|
|||||||
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['accepting_call'], $this->calls[$call['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['accepting_call'], $this->calls[$call['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$dh_config = yield $this->getDhConfig();
|
$dh_config = yield $this->getDhConfig();
|
||||||
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_b'], \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger(\danog\MadelineProto\Lang::$current_lang['generating_b'], \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$b = \phpseclib\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
|
$b = \phpseclib3\Math\BigInteger::randomRange(\danog\MadelineProto\Magic::$two, $dh_config['p']->subtract(\danog\MadelineProto\Magic::$two));
|
||||||
$g_b = $dh_config['g']->powMod($b, $dh_config['p']);
|
$g_b = $dh_config['g']->powMod($b, $dh_config['p']);
|
||||||
$this->checkG($g_b, $dh_config['p']);
|
$this->checkG($g_b, $dh_config['p']);
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ trait AuthKeyHandler
|
|||||||
}
|
}
|
||||||
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['call_confirming'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
|
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['call_confirming'], $this->calls[$params['id']]->getOtherID()), \danog\MadelineProto\Logger::VERBOSE);
|
||||||
$dh_config = yield $this->getDhConfig();
|
$dh_config = yield $this->getDhConfig();
|
||||||
$params['g_b'] = new \phpseclib\Math\BigInteger((string) $params['g_b'], 256);
|
$params['g_b'] = new \phpseclib3\Math\BigInteger((string) $params['g_b'], 256);
|
||||||
$this->checkG($params['g_b'], $dh_config['p']);
|
$this->checkG($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);
|
$key = \str_pad($params['g_b']->powMod($this->calls[$params['id']]->storage['a'], $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT);
|
||||||
try {
|
try {
|
||||||
@ -145,10 +145,10 @@ trait AuthKeyHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$visualization = [];
|
$visualization = [];
|
||||||
$length = new \phpseclib\Math\BigInteger(\count(\danog\MadelineProto\Magic::$emojis));
|
$length = new \phpseclib3\Math\BigInteger(\count(\danog\MadelineProto\Magic::$emojis));
|
||||||
foreach (\str_split(\hash('sha256', $key.\str_pad($this->calls[$params['id']]->storage['g_a'], 256, \chr(0), \STR_PAD_LEFT), true), 8) as $number) {
|
foreach (\str_split(\hash('sha256', $key.\str_pad($this->calls[$params['id']]->storage['g_a'], 256, \chr(0), \STR_PAD_LEFT), true), 8) as $number) {
|
||||||
$number[0] = \chr(\ord($number[0]) & 0x7f);
|
$number[0] = \chr(\ord($number[0]) & 0x7f);
|
||||||
$visualization[] = \danog\MadelineProto\Magic::$emojis[(int) (new \phpseclib\Math\BigInteger($number, 256))->divide($length)[1]->toString()];
|
$visualization[] = \danog\MadelineProto\Magic::$emojis[(int) (new \phpseclib3\Math\BigInteger($number, 256))->divide($length)[1]->toString()];
|
||||||
}
|
}
|
||||||
$this->calls[$params['id']]->setVisualization($visualization);
|
$this->calls[$params['id']]->setVisualization($visualization);
|
||||||
|
|
||||||
@ -175,17 +175,17 @@ trait AuthKeyHandler
|
|||||||
if (\hash('sha256', $params['g_a_or_b'], true) != $this->calls[$params['id']]->storage['g_a_hash']) {
|
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']);
|
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['invalid_g_a']);
|
||||||
}
|
}
|
||||||
$params['g_a_or_b'] = new \phpseclib\Math\BigInteger((string) $params['g_a_or_b'], 256);
|
$params['g_a_or_b'] = new \phpseclib3\Math\BigInteger((string) $params['g_a_or_b'], 256);
|
||||||
$this->checkG($params['g_a_or_b'], $dh_config['p']);
|
$this->checkG($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);
|
$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']) {
|
if (\substr(\sha1($key, true), -8) != $params['key_fingerprint']) {
|
||||||
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['fingerprint_invalid']);
|
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['fingerprint_invalid']);
|
||||||
}
|
}
|
||||||
$visualization = [];
|
$visualization = [];
|
||||||
$length = new \phpseclib\Math\BigInteger(\count(\danog\MadelineProto\Magic::$emojis));
|
$length = new \phpseclib3\Math\BigInteger(\count(\danog\MadelineProto\Magic::$emojis));
|
||||||
foreach (\str_split(\hash('sha256', $key.\str_pad($params['g_a_or_b']->toBytes(), 256, \chr(0), \STR_PAD_LEFT), true), 8) as $number) {
|
foreach (\str_split(\hash('sha256', $key.\str_pad($params['g_a_or_b']->toBytes(), 256, \chr(0), \STR_PAD_LEFT), true), 8) as $number) {
|
||||||
$number[0] = \chr(\ord($number[0]) & 0x7f);
|
$number[0] = \chr(\ord($number[0]) & 0x7f);
|
||||||
$visualization[] = \danog\MadelineProto\Magic::$emojis[(int) (new \phpseclib\Math\BigInteger($number, 256))->divide($length)[1]->toString()];
|
$visualization[] = \danog\MadelineProto\Magic::$emojis[(int) (new \phpseclib3\Math\BigInteger($number, 256))->divide($length)[1]->toString()];
|
||||||
}
|
}
|
||||||
$this->calls[$params['id']]->setVisualization($visualization);
|
$this->calls[$params['id']]->setVisualization($visualization);
|
||||||
$this->calls[$params['id']]->configuration['endpoints'] = \array_merge($params['connections'], $this->calls[$params['id']]->configuration['endpoints']);
|
$this->calls[$params['id']]->configuration['endpoints'] = \array_merge($params['connections'], $this->calls[$params['id']]->configuration['endpoints']);
|
||||||
|
Loading…
Reference in New Issue
Block a user