Skip to content

Commit ff72bb5

Browse files
committed
Fix for breaking change in phpseclib
1 parent 192526f commit ff72bb5

4 files changed

Lines changed: 32 additions & 22 deletions

File tree

psalm-baseline.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="dev-master@cdceda044f0255e4eb1da0557ff1479e6d317e01">
2+
<files psalm-version="dev-master@0df8d6882bef149abbe640774a1c4097cc97ba8c">
33
<file src="src/API.php">
44
<ArgumentTypeCoercion>
55
<code><![CDATA[$settings]]></code>
@@ -186,7 +186,6 @@
186186
<file src="src/Broadcast/Broadcast.php">
187187
<DocblockTypeContradiction>
188188
<code><![CDATA[$this->broadcasts[$id]]]></code>
189-
<code><![CDATA[$this->broadcasts[$id]]]></code>
190189
</DocblockTypeContradiction>
191190
<MixedArrayAccess>
192191
<code><![CDATA[$message['media']['_']]]></code>
@@ -197,7 +196,6 @@
197196
</MixedAssignment>
198197
<RedundantConditionGivenDocblockType>
199198
<code><![CDATA[$this->broadcasts[$id]?->cancel()]]></code>
200-
<code><![CDATA[$this->broadcasts[$id]?->getProgress()]]></code>
201199
</RedundantConditionGivenDocblockType>
202200
</file>
203201
<file src="src/Broadcast/InternalState.php">
@@ -615,9 +613,6 @@
615613
<code><![CDATA[$this->periodicLoops]]></code>
616614
<code><![CDATA[array<string, PeriodicLoop>]]></code>
617615
</MixedReturnTypeCoercion>
618-
<PossiblyNullArgument>
619-
<code><![CDATA[$methodRefl->getParameters()[0]->getType()]]></code>
620-
</PossiblyNullArgument>
621616
<PossiblyNullReference>
622617
<code><![CDATA[getDbSettings]]></code>
623618
<code><![CDATA[rethrowInner]]></code>
@@ -7610,6 +7605,9 @@
76107605
<TaintedFile>
76117606
<code><![CDATA[Tools::absolute($file)]]></code>
76127607
</TaintedFile>
7608+
<TaintedSSRF>
7609+
<code><![CDATA[Tools::absolute($file)]]></code>
7610+
</TaintedSSRF>
76137611
</file>
76147612
<file src="src/TL/TLConstructors.php">
76157613
<MissingReturnType>

src/API.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ final class API extends AbstractAPI
5151
*
5252
* @var string
5353
*/
54-
public const RELEASE = '8.6.1';
54+
public const RELEASE = '8.6.2';
5555
/**
5656
* We're not logged in.
5757
*

src/MTProto.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,19 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter
231231
*
232232
* @var array<RSA>
233233
*/
234-
private array $rsa_keys = [];
234+
private array $rsaKeys = [];
235235
/**
236236
* RSA keys.
237237
*
238238
* @var array<RSA>
239239
*/
240-
private array $test_rsa_keys = [];
240+
private array $testRsaKeys = [];
241241
/**
242242
* CDN RSA keys.
243243
*
244244
* @var array<RSA>
245245
*/
246-
private array $cdn_rsa_keys = [];
246+
private array $cdnRsaKeys = [];
247247
/**
248248
* Diffie-hellman config.
249249
*
@@ -489,11 +489,11 @@ public function serializeSession(object $data)
489489
public function findRsaKey(array $fps, bool $test, bool $cdn): ?RSA
490490
{
491491
if ($cdn) {
492-
$list = $this->cdn_rsa_keys;
492+
$list = $this->cdnRsaKeys;
493493
} elseif ($test) {
494-
$list = $this->test_rsa_keys;
494+
$list = $this->testRsaKeys;
495495
} else {
496-
$list = $this->rsa_keys;
496+
$list = $this->rsaKeys;
497497
}
498498

499499
foreach ($list as $curkey) {
@@ -673,15 +673,15 @@ private function initialize(Settings|SettingsEmpty $settings): void
673673
// Actually instantiate needed classes like a boss
674674
$this->cleanupProperties();
675675
// Load rsa keys
676-
$this->rsa_keys = [];
676+
$this->rsaKeys = [];
677677
foreach ($this->settings->getConnection()->getRSAKeys() as $key) {
678678
$key = RSA::load($this->TL, $key);
679-
$this->rsa_keys[$key->fp] = $key;
679+
$this->rsaKeys[$key->fp] = $key;
680680
}
681-
$this->test_rsa_keys = [];
681+
$this->testRsaKeys = [];
682682
foreach ($this->settings->getConnection()->getTestRSAKeys() as $key) {
683683
$key = RSA::load($this->TL, $key);
684-
$this->test_rsa_keys[$key->fp] = $key;
684+
$this->testRsaKeys[$key->fp] = $key;
685685
}
686686
// (re)-initialize TL
687687
$callbacks = [$this, $this->peerDatabase];
@@ -795,8 +795,9 @@ public function __sleep(): array
795795
'loginState',
796796

797797
// Authorization cache
798-
'rsa_keys',
799-
'test_rsa_keys',
798+
'rsaKeys',
799+
'testRsaKeys',
800+
'cdnRsaKeys',
800801
'dh_config',
801802

802803
// Update state
@@ -1519,7 +1520,7 @@ public function getCdnConfig(): void
15191520
try {
15201521
foreach (($this->methodCallAsyncRead('help.getCdnConfig', [], $this->loginState->getState()->authorizedDc))['public_keys'] as $curkey) {
15211522
$curkey = RSA::load($this->TL, $curkey['public_key']);
1522-
$this->cdn_rsa_keys[$curkey->fp] = $curkey;
1523+
$this->cdnRsaKeys[$curkey->fp] = $curkey;
15231524
}
15241525
} catch (\danog\MadelineProto\TL\Exception $e) {
15251526
$this->logger->logger($e->getMessage(), Logger::FATAL_ERROR);

src/MTProtoSession/AuthKeyHandler.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,24 @@ public function createAuthKey(bool $temp): void
166166
}
167167
$data_with_padding = $p_q_inner_data.Tools::random(192 - \strlen($p_q_inner_data));
168168
$data_pad_reversed = strrev($data_with_padding);
169-
do {
169+
170+
for ($tryInner = 0; $tryInner < 10; $tryInner++) {
170171
$temp_key = Tools::random(32);
171172
$data_with_hash = $data_pad_reversed.hash('sha256', $temp_key.$data_with_padding, true);
172173
$aes_encrypted = Crypt::igeEncrypt($data_with_hash, $temp_key, str_repeat("\0", 32));
173174
$temp_key_xor = $temp_key ^ hash('sha256', $aes_encrypted, true);
174175
$key_aes_encrypted_bigint = new BigInteger($temp_key_xor.$aes_encrypted, 256);
175-
} while ($key_aes_encrypted_bigint->compare($key->n) >= 0);
176+
177+
$ok = $key_aes_encrypted_bigint->compare($key->n) < 0;
178+
if ($ok) {
179+
break;
180+
}
181+
}
182+
183+
if (!$ok) {
184+
throw new SecurityException('Failed to generate a valid payload within 10 attempts.');
185+
}
186+
176187
$encrypted_data = $key->encrypt($key_aes_encrypted_bigint);
177188
$this->API->logger('Starting Diffie Hellman key exchange', Logger::VERBOSE);
178189
/*

0 commit comments

Comments
 (0)