Update phpseclib

This commit is contained in:
Daniil Gentili 2019-12-13 13:38:56 +01:00
parent d559b1d8b6
commit c8ed5971d9
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
19 changed files with 81 additions and 81 deletions

View File

@ -17,7 +17,7 @@
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace phpseclib\Math;
namespace phpseclib3\Math;
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');
@ -26,7 +26,7 @@ if (\defined('HHVM_VERSION')) {
$engines = [['PHP64', ['OpenSSL']], ['BCMath', ['OpenSSL']], ['PHP32', ['OpenSSL']]];
foreach ($engines as $engine) {
try {
\phpseclib\Math\BigInteger::setEngine($engine[0], isset($engine[1]) ? $engine[1] : []);
\phpseclib3\Math\BigInteger::setEngine($engine[0], isset($engine[1]) ? $engine[1] : []);
break;
} catch (\Exception $e) {
}

View File

@ -108,6 +108,10 @@ class API extends InternalDoc
$tounserialize = \str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $tounserialize);
$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) {
$tounserialize = \str_replace('phpseclib\\Math\\BigInteger', 'phpseclib\\Math\\BigIntegor', $tounserialize);
$changed = true;

View File

@ -4323,7 +4323,7 @@ class InternalDoc extends APIFactory
*
* @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]);
}
@ -4335,7 +4335,7 @@ class InternalDoc extends APIFactory
*
* @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]);
}

View File

@ -57,7 +57,7 @@ class Lang
'encode_double_error' => 'Non sono riuscito a codificare il numero a virgola mobile fornito',
'file_not_exist' => 'Il file specificato non esiste',
'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...',
'computing_fingerprint' => 'Calcolo del fingerprint in corso...',
'rsa_encrypting' => 'Criptando con chiave RSA...',
@ -204,7 +204,7 @@ class Lang
'encode_double_error' => 'Could not properly encode double',
'file_not_exist' => 'File does not exist',
'deserialization_error' => 'An error occurred on deserialization',
'rsa_init' => 'Istantiating \\phpseclib\\Crypt\\RSA...',
'rsa_init' => 'Istantiating \\phpseclib3\\Crypt\\RSA...',
'loading_key' => 'Loading key...',
'computing_fingerprint' => 'Computing fingerprint...',
'rsa_encrypting' => 'Encrypting with rsa key...',
@ -5291,7 +5291,7 @@ class Lang
'encode_double_error' => 'Could not properly encode double',
'file_not_exist' => 'File does not exist',
'deserialization_error' => 'An error occurred on deserialization',
'rsa_init' => 'Istantiating \\phpseclib\\Crypt\\RSA...',
'rsa_init' => 'Istantiating \\phpseclib3\\Crypt\\RSA...',
'loading_key' => 'Loading key...',
'computing_fingerprint' => 'Computing fingerprint...',
'rsa_encrypting' => 'Encrypting with rsa key...',

View File

@ -169,7 +169,7 @@ class Lua
public static function convertObjects(&$data)
{
\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 = [];
foreach (\get_class_methods($value) as $name) {
$newval[$name] = [$value, $name];

View File

@ -30,13 +30,13 @@ trait MsgIdHandler
public function checkMessageId($new_message_id, $aargs)
{
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) {
$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) {
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()
{
$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) {
$message_id = $key->add(\danog\MadelineProto\Magic::$four);
}

View File

@ -34,11 +34,11 @@ trait ResponseHandler
foreach ($msg_ids as $msg_id) {
$cur_info = 0;
if (!isset($this->incoming_messages[$msg_id])) {
$msg_id = new \phpseclib\Math\BigInteger(\strrev($msg_id), 256);
if ((new \phpseclib\Math\BigInteger(\time() + $this->time_delta + 30))->bitwise_leftShift(32)->compare($msg_id) < 0) {
$msg_id = new \phpseclib3\Math\BigInteger(\strrev($msg_id), 256);
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");
$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");
$cur_info |= 1;
} else {
@ -185,7 +185,7 @@ trait ResponseHandler
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]);
$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.': ';
/*if ($info & 4) {
*$this->gotResponseForOutgoingMessageId($msg_id);
@ -551,7 +551,7 @@ trait ResponseHandler
return;
case 16:
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->API->resetMTProtoSession();
$this->shared->setTempAuthKey(null);

View File

@ -24,7 +24,7 @@ use danog\MadelineProto\DataCenterConnection;
use danog\MadelineProto\MTProto\AuthKey;
use danog\MadelineProto\MTProto\PermAuthKey;
use danog\MadelineProto\MTProto\TempAuthKey;
use phpseclib\Math\BigInteger;
use phpseclib3\Math\BigInteger;
/**
* Manages the creation of the authorization key.
@ -108,9 +108,9 @@ trait AuthKeyHandler
* ***********************************************************************
* Compute p and q
*/
$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()));
$pq = new \phpseclib3\Math\BigInteger((string) $pq_bytes, 256);
$q = new \phpseclib3\Math\BigInteger(0);
$p = new \phpseclib3\Math\BigInteger(\danog\PrimeModule::auto_single($pq->__toString()));
if (!$p->equals(\danog\MadelineProto\Magic::$zero)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -119,7 +119,7 @@ trait AuthKeyHandler
}
if (!$pq->equals($p->multiply($q))) {
$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)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -129,7 +129,7 @@ trait AuthKeyHandler
if (!$pq->equals($p->multiply($q))) {
$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)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -139,7 +139,7 @@ trait AuthKeyHandler
if (!$pq->equals($p->multiply($q))) {
$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)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -149,7 +149,7 @@ trait AuthKeyHandler
if (!$pq->equals($p->multiply($q))) {
$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)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -160,7 +160,7 @@ trait AuthKeyHandler
if (!$pq->equals($p->multiply($q))) {
$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)) {
$q = $pq->divide($p)[0];
if ($p->compare($q) > 0) {
@ -284,9 +284,9 @@ trait AuthKeyHandler
if ($server_nonce != $server_DH_inner_data['server_nonce']) {
throw new \danog\MadelineProto\SecurityException('wrong server nonce');
}
$g = new \phpseclib\Math\BigInteger($server_DH_inner_data['g']);
$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);
$g = new \phpseclib3\Math\BigInteger($server_DH_inner_data['g']);
$g_a = new \phpseclib3\Math\BigInteger((string) $server_DH_inner_data['g_a'], 256);
$dh_prime = new \phpseclib3\Math\BigInteger((string) $server_DH_inner_data['dh_prime'], 256);
/*
* ***********************************************************************
* Time delta
@ -298,7 +298,7 @@ trait AuthKeyHandler
$this->checkG($g_a, $dh_prime);
for ($retry_id = 0; $retry_id <= $this->settings['max_tries']['authorization']; $retry_id++) {
$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);
$g_b = $g->powMod($b, $dh_prime);
$this->checkG($g_b, $dh_prime);
@ -526,8 +526,8 @@ trait AuthKeyHandler
return $this->dh_config;
}
$dh_config['p'] = new \phpseclib\Math\BigInteger((string) $dh_config['p'], 256);
$dh_config['g'] = new \phpseclib\Math\BigInteger($dh_config['g']);
$dh_config['p'] = new \phpseclib3\Math\BigInteger((string) $dh_config['p'], 256);
$dh_config['g'] = new \phpseclib3\Math\BigInteger($dh_config['g']);
$this->checkPG($dh_config['p'], $dh_config['g']);
return $this->dh_config = $dh_config;

View File

@ -47,7 +47,7 @@ trait Crypt
public function ctrEncrypt($message, $key, $iv)
{
$cipher = new \phpseclib\Crypt\AES('ctr');
$cipher = new \phpseclib3\Crypt\AES('ctr');
$cipher->setKey($key);
$cipher->setIV($iv);
@ -56,7 +56,7 @@ trait Crypt
public function igeEncrypt($message, $key, $iv)
{
$cipher = new \phpseclib\Crypt\AES('ige');
$cipher = new \phpseclib3\Crypt\AES('ige');
$cipher->setKey($key);
$cipher->setIV($iv);
@ -64,7 +64,7 @@ trait Crypt
}
public function igeDecrypt($message, $key, $iv)
{
$cipher = new \phpseclib\Crypt\AES('ige');
$cipher = new \phpseclib3\Crypt\AES('ige');
$cipher->setKey($key);
$cipher->setIV($iv);

View File

@ -213,7 +213,7 @@ trait Files
$iv = \danog\MadelineProto\Tools::random(32);
$digest = \hash('md5', $key.$iv, true);
$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->setKey($key);
$ige->enableContinuousBuffer();
@ -952,7 +952,7 @@ trait Files
if ($fingerprint !== $message_media['key_fingerprint']) {
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->setKey($message_media['key']);
$ige->enableContinuousBuffer();

View File

@ -22,7 +22,7 @@ use danog\MadelineProto\Exception;
use danog\MadelineProto\Magic;
use danog\MadelineProto\SecurityException;
use danog\MadelineProto\Tools;
use phpseclib\Math\BigInteger;
use phpseclib3\Math\BigInteger;
/**
* Manages SRP password calculation.

View File

@ -83,7 +83,7 @@ class Magic
\set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']);
\set_exception_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionHandler']);
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']);
}
foreach (['xml', 'fileinfo', 'json', 'mbstring'] as $extension) {
@ -105,16 +105,16 @@ class Magic
}
}
self::$emojis = \json_decode(self::JSON_EMOJIS);
self::$zero = new \phpseclib\Math\BigInteger(0);
self::$one = new \phpseclib\Math\BigInteger(1);
self::$two = new \phpseclib\Math\BigInteger(2);
self::$three = new \phpseclib\Math\BigInteger(3);
self::$four = new \phpseclib\Math\BigInteger(4);
self::$twoe1984 = new \phpseclib\Math\BigInteger('1751908409537131537220509645351687597690304110853111572994449976845956819751541616602568796259317428464425605223064365804210081422215355425149431390635151955247955156636234741221447435733643262808668929902091770092492911737768377135426590363166295684370498604708288556044687341394398676292971255828404734517580702346564613427770683056761383955397564338690628093211465848244049196353703022640400205739093118270803778352768276670202698397214556629204420309965547056893233608758387329699097930255380715679250799950923553703740673620901978370802540218870279314810722790539899334271514365444369275682816');
self::$twoe2047 = new \phpseclib\Math\BigInteger('16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115328');
self::$twoe2048 = new \phpseclib\Math\BigInteger('32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656');
self::$twozerotwosixone = new \phpseclib\Math\BigInteger(20261);
self::$zeroeight = new \phpseclib\Math\BigInteger('2147483648');
self::$zero = new \phpseclib3\Math\BigInteger(0);
self::$one = new \phpseclib3\Math\BigInteger(1);
self::$two = new \phpseclib3\Math\BigInteger(2);
self::$three = new \phpseclib3\Math\BigInteger(3);
self::$four = new \phpseclib3\Math\BigInteger(4);
self::$twoe1984 = new \phpseclib3\Math\BigInteger('1751908409537131537220509645351687597690304110853111572994449976845956819751541616602568796259317428464425605223064365804210081422215355425149431390635151955247955156636234741221447435733643262808668929902091770092492911737768377135426590363166295684370498604708288556044687341394398676292971255828404734517580702346564613427770683056761383955397564338690628093211465848244049196353703022640400205739093118270803778352768276670202698397214556629204420309965547056893233608758387329699097930255380715679250799950923553703740673620901978370802540218870279314810722790539899334271514365444369275682816');
self::$twoe2047 = new \phpseclib3\Math\BigInteger('16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115328');
self::$twoe2048 = new \phpseclib3\Math\BigInteger('32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656');
self::$twozerotwosixone = new \phpseclib3\Math\BigInteger(20261);
self::$zeroeight = new \phpseclib3\Math\BigInteger('2147483648');
try {
self::$isatty = \defined('STDOUT') && \function_exists('posix_isatty') && \posix_isatty(STDOUT);

View File

@ -30,13 +30,13 @@ class RSA
/**
* Exponent.
*
* @var \phpseclib\Math\BigInteger
* @var \phpseclib3\Math\BigInteger
*/
public $e;
/**
* Modulus.
*
* @var \phpseclib\Math\BigInteger
* @var \phpseclib3\Math\BigInteger
*/
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['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->e = Tools::getVar($key, 'exponent');
\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);
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();
}
}

View File

@ -59,8 +59,8 @@ trait AuthKeyHandler
}
$dh_config = yield $this->getDhConfig();
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$b = new \phpseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$params['g_a'] = new \phpseclib\Math\BigInteger((string) $params['g_a'], 256);
$b = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$params['g_a'] = new \phpseclib3\Math\BigInteger((string) $params['g_a'], 256);
$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)];
//$this->logger->logger($key);
@ -92,7 +92,7 @@ trait AuthKeyHandler
$this->logger->logger('Creating secret chat with '.$user['user_id'].'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$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);
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
$this->checkG($g_a, $dh_config['p']);
@ -120,7 +120,7 @@ trait AuthKeyHandler
return false;
}
$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']);
$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']]);
@ -165,7 +165,7 @@ trait AuthKeyHandler
$this->logger->logger('Rekeying secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$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);
$g_a = $dh_config['g']->powMod($a, $dh_config['p']);
$this->checkG($g_a, $dh_config['p']);
@ -189,8 +189,8 @@ trait AuthKeyHandler
private function acceptRekey($chat, array $params): \Generator
{
if ($this->secret_chats[$chat]['rekeying'][0] !== 0) {
$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);
$my_exchange_id = new \phpseclib3\Math\BigInteger($this->secret_chats[$chat]['rekeying'][1], -256);
$other_exchange_id = new \phpseclib3\Math\BigInteger($params['exchange_id'], -256);
//$this->logger->logger($my, $params);
if ($my_exchange_id->compare($other_exchange_id) > 0) {
return;
@ -204,8 +204,8 @@ trait AuthKeyHandler
$this->logger->logger('Accepting rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$this->logger->logger('Generating b...', \danog\MadelineProto\Logger::VERBOSE);
$b = new \phpseclib\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$params['g_a'] = new \phpseclib\Math\BigInteger((string) $params['g_a'], 256);
$b = new \phpseclib3\Math\BigInteger(\danog\MadelineProto\Tools::random(256), 256);
$params['g_a'] = new \phpseclib3\Math\BigInteger((string) $params['g_a'], 256);
$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['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);
$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']);
$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

@ -80,12 +80,12 @@ class ObfuscatedStream implements BufferedProxyStreamInterface
$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->setKey($key);
$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->setKey($keyRev);
$this->decrypt->setIV(\substr($reversed, 40, 16));

View File

@ -113,8 +113,6 @@ class DefaultStream extends Socket implements
}
} catch (\Throwable $e) {
\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());
}
}

View File

@ -102,8 +102,6 @@ class PremadeStream extends Socket implements RawStreamInterface, ProxyStreamInt
}
} catch (\Throwable $e) {
\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());
}
}

View File

@ -24,7 +24,7 @@ use Amp\File\StatCache;
use Amp\Loop;
use Amp\Promise;
use Amp\Success;
use phpseclib\Math\BigInteger;
use phpseclib3\Math\BigInteger;
use function Amp\ByteStream\getOutputBufferStream;
use function Amp\ByteStream\getStdin;
@ -53,9 +53,9 @@ trait Tools
{
//sort($ints, SORT_NUMERIC);
if (\danog\MadelineProto\Magic::$bigint) {
$hash = new \phpseclib\Math\BigInteger(0);
$hash = new \phpseclib3\Math\BigInteger(0);
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)));
} else {
@ -112,7 +112,7 @@ trait Tools
*/
public static function random(int $length): string
{
return $length === 0 ? '' : \phpseclib\Crypt\Random::string($length);
return $length === 0 ? '' : \phpseclib3\Crypt\Random::string($length);
}
/**

View File

@ -57,7 +57,7 @@ trait AuthKeyHandler
$this->logger->logger(\sprintf(\danog\MadelineProto\Lang::$current_lang['calling_user'], $user['user_id']), \danog\MadelineProto\Logger::VERBOSE);
$dh_config = yield $this->getDhConfig();
$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);
$g_a = $dh_config['g']->powMod($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);
$dh_config = yield $this->getDhConfig();
$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']);
$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);
$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']);
$key = \str_pad($params['g_b']->powMod($this->calls[$params['id']]->storage['a'], $dh_config['p'])->toBytes(), 256, \chr(0), \STR_PAD_LEFT);
try {
@ -145,10 +145,10 @@ trait AuthKeyHandler
}
$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) {
$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);
@ -175,17 +175,17 @@ 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((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']);
$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']) {
throw new \danog\MadelineProto\SecurityException(\danog\MadelineProto\Lang::$current_lang['fingerprint_invalid']);
}
$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) {
$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']]->configuration['endpoints'] = \array_merge($params['connections'], $this->calls[$params['id']]->configuration['endpoints']);