1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-26 21:34:41 +01:00
This commit is contained in:
Daniil Gentili 2023-09-19 21:20:41 +02:00
parent b0ab083367
commit d6b0926c71
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
7 changed files with 29 additions and 65 deletions

View File

@ -583,8 +583,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* <a href="https://docs.madelineproto.xyz/API_docs/methods/payments.getSavedInfo.html" name="payments.getSavedInfo">Get saved payment information: payments.getSavedInfo</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getScheduledHistory.html" name="messages.getScheduledHistory">Get scheduled messages: messages.getScheduledHistory</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getScheduledMessages.html" name="messages.getScheduledMessages">Get scheduled messages: messages.getScheduledMessages</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#secretchatstatus-int-chat-int-one-of-danog-madelineproto-api-secret_empty-danog-madelineproto-api-secret_requested-danog-madelineproto-api-secret_ready" name="secretChatStatus">Get secret chat status: secretChatStatus</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getsecretchat-array-int-chat-array" name="getSecretChat">Get secret chat: getSecretChat</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getsecretchat-array-int-chat-danog-madelineproto-secretchats-secretchat" name="getSecretChat">Get secret chat: getSecretChat</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#random-int-length-string" name="random">Get secure random string of specified length: random</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.getContentSettings.html" name="account.getContentSettings">Get sensitive content settings: account.getContentSettings</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getsponsoredmessages-int-string-array-peer-array" name="getSponsoredMessages">Get sponsored messages for channel: getSponsoredMessages</a>
@ -731,7 +730,6 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#refreshfullpeercache-mixed-id-void" name="refreshFullPeerCache">Refresh full peer cache for a certain peer: refreshFullPeerCache</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#refreshpeercache-mixed-ids-void" name="refreshPeerCache">Refresh peer cache for a certain peer: refreshPeerCache</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.registerDevice.html" name="account.registerDevice">Register device to receive PUSH notifications: account.registerDevice</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#rekey-int-chat-string" name="rekey">Rekey secret chat: rekey</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/stickers.removeStickerFromSet.html" name="stickers.removeStickerFromSet">Remove a sticker from the set where it belongs, bots only. The sticker set must have been created by the bot: stickers.removeStickerFromSet</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/stickers.renameStickerSet.html" name="stickers.renameStickerSet">Renames a stickerset, bots only: stickers.renameStickerSet</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.reorderUsernames.html" name="channels.reorderUsernames">Reorder active usernames: channels.reorderUsernames</a>

View File

@ -382,6 +382,9 @@
<PossiblyNullArgument>
<code><![CDATA[$methodRefl->getParameters()[0]->getType()]]></code>
</PossiblyNullArgument>
<PossiblyNullReference>
<code>getDbPrefix</code>
</PossiblyNullReference>
<PropertyTypeCoercion>
<code>self::$pluginCache</code>
</PropertyTypeCoercion>
@ -1060,8 +1063,7 @@
<code><![CDATA[$message->getSerializedBody()]]></code>
</PossiblyNullArgument>
<PossiblyNullArrayOffset>
<code><![CDATA[$this->connection->call_queue]]></code>
<code><![CDATA[$this->connection->call_queue]]></code>
<code><![CDATA[$this->connection->callQueue]]></code>
</PossiblyNullArrayOffset>
<PossiblyNullReference>
<code>getWriteBuffer</code>
@ -1100,11 +1102,6 @@
<code>FeedLoop</code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Loop/Update/SecretFeedLoop.php">
<PropertyNotSetInConstructor>
<code>SecretFeedLoop</code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Loop/Update/SeqLoop.php">
<PossiblyNullReference>
<code>checkSeq</code>
@ -1355,6 +1352,7 @@
<code><![CDATA[$request->getMsgId()]]></code>
<code><![CDATA[$request->getMsgId()]]></code>
<code><![CDATA[$request->getMsgId()]]></code>
<code><![CDATA[$request->getMsgId()]]></code>
</PossiblyNullArgument>
<PossiblyNullReference>
<code>resume</code>
@ -1814,9 +1812,6 @@
</PropertyNotSetInConstructor>
</file>
<file src="src/SecretChats/AuthKeyHandler.php">
<MissingParamType>
<code>$chat</code>
</MissingParamType>
<MissingReturnType>
<code>completeSecretChat</code>
</MissingReturnType>
@ -1824,33 +1819,11 @@
<code><![CDATA[$user['user_id']]]></code>
</PossiblyUndefinedArrayOffset>
</file>
<file src="src/SecretChats/MessageHandler.php">
<MissingParamType>
<code>$chat_id</code>
<code>$chat_id</code>
<code>$encrypted_data</code>
<code>$encrypted_data</code>
<code>$message_key</code>
<code>$message_key</code>
<code>$old</code>
<code>$old</code>
</MissingParamType>
</file>
<file src="src/SecretChats/SeqNoHandler.php">
<MissingParamType>
<code>$chat</code>
<code>$chat</code>
<code>$chat_id</code>
<code>$chat_id</code>
<code>$seqno</code>
<code>$seqno</code>
</MissingParamType>
<MissingReturnType>
<code>checkSecretInSeqNo</code>
<code>checkSecretOutSeqNo</code>
<code>generateSecretInSeqNo</code>
<code>generateSecretOutSeqNo</code>
</MissingReturnType>
<file src="src/SecretChats/SecretChatController.php">
<PropertyNotSetInConstructor>
<code>$incoming</code>
<code>$outgoing</code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Serialization.php">
<LessSpecificReturnStatement>
@ -2202,9 +2175,6 @@
<code>\is_resource($stream)</code>
<code>\is_resource($stream)</code>
</DocblockTypeContradiction>
<InvalidArrayOffset>
<code><![CDATA[($this->API->getInfo($arguments[$current_argument['name']]))['InputEncryptedChat']]]></code>
</InvalidArrayOffset>
<MissingClosureParamType>
<code>$arg</code>
</MissingClosureParamType>
@ -2215,30 +2185,18 @@
<code>serializeParams</code>
</MissingReturnType>
<PossiblyInvalidArgument>
<code><![CDATA[$arguments[$current_argument['name']]]]></code>
<code><![CDATA[$arguments[$current_argument['name']]]]></code>
<code><![CDATA[$arguments['id']]]></code>
<code><![CDATA[$arguments['id']]]></code>
<code><![CDATA[$arguments['message']]]></code>
<code><![CDATA[$arguments['queuePromise']]]></code>
<code>$value</code>
<code>$value</code>
<code><![CDATA[$x['result']]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidIterator>
<code><![CDATA[$x['value']]]></code>
</PossiblyInvalidIterator>
<PossiblyNullArgument>
<code><![CDATA[$arguments[$current_argument['name']]]]></code>
<code><![CDATA[$arguments[$current_argument['name']]]]></code>
<code><![CDATA[$arguments[$current_argument['name']]['_']]]></code>
<code><![CDATA[$arguments[$current_argument['name']]['_']]]></code>
<code><![CDATA[$arguments['peer']['chat_id']]]></code>
<code>$value</code>
</PossiblyNullArgument>
<PossiblyNullArrayAccess>
<code><![CDATA[$arguments[$current_argument['name']]['_']]]></code>
<code><![CDATA[$arguments[$current_argument['name']]['_']]]></code>
<code><![CDATA[$arguments['file']['mime_type']]]></code>
<code><![CDATA[$arguments['peer']['chat_id']]]></code>
</PossiblyNullArrayAccess>
<PossiblyNullPropertyFetch>
<code><![CDATA[$this->API->logger]]></code>
</PossiblyNullPropertyFetch>

View File

@ -879,6 +879,9 @@ abstract class InternalDoc
/**
* Get info about peer, returns an Info object.
*
* If passed a secret chat ID, returns information about the user, not about the secret chat.
* Use getSecretChat to return information about the secret chat.
*
* @param mixed $id Peer
* @param \danog\MadelineProto\API::INFO_TYPE_* $type Whether to generate an Input*, an InputPeer or the full set of constructors
* @see https://docs.madelineproto.xyz/Info.html

View File

@ -28,7 +28,6 @@ use danog\MadelineProto\Exception;
use danog\MadelineProto\Logger;
use danog\MadelineProto\PeerNotInDbException;
use danog\MadelineProto\RPCErrorException;
use danog\MadelineProto\SecretPeerNotInDbException;
use danog\MadelineProto\Settings;
use danog\MadelineProto\Tools;
use Throwable;
@ -360,7 +359,7 @@ trait PeerHandler
/**
* Get info about peer, returns an Info object.
*
*
* If passed a secret chat ID, returns information about the user, not about the secret chat.
* Use getSecretChat to return information about the secret chat.
*

View File

@ -20,12 +20,14 @@ declare(strict_types=1);
namespace danog\MadelineProto\SecretChats;
use AssertionError;
use danog\MadelineProto\Logger;
use danog\MadelineProto\Loop\Update\UpdateLoop;
use danog\MadelineProto\MTProtoTools\Crypt;
use danog\MadelineProto\MTProtoTools\DialogId;
use danog\MadelineProto\PeerNotInDbException;
use danog\MadelineProto\RPCErrorException;
use danog\MadelineProto\SecretPeerNotInDbException;
use danog\MadelineProto\SecurityException;
use danog\MadelineProto\Tools;
use phpseclib3\Math\BigInteger;
@ -181,10 +183,15 @@ trait AuthKeyHandler
case 'encryptedMessageService':
$chat = $chat['chat_id'];
break;
default:
throw new AssertionError("Unknown update type {$chat['_']} provided!");
}
} elseif (DialogId::isSecretChat($chat)) {
$chat = DialogId::toSecretChatId($chat);
}
if (!isset($this->secretChats[$chat])) {
throw new SecretPeerNotInDbException;
}
return $this->secretChats[$chat];
}
/**

View File

@ -256,7 +256,7 @@ final class SecretChatController implements Stringable
$dh_config = ($this->API->getDhConfig());
$params['g_b'] = new BigInteger((string) $params['g_b'], 256);
Crypt::checkG($params['g_b'], $dh_config['p']);
assert($this->rekeyParam !== null);
\assert($this->rekeyParam !== null);
$key = ['auth_key' => \str_pad($params['g_b']->powMod($this->rekeyParam, $dh_config['p'])->toBytes(), 256, \chr(0), STR_PAD_LEFT)];
$key['fingerprint'] = \substr(\sha1($key['auth_key'], true), -8);
$key['visualization_orig'] = $this->key['visualization_orig'];
@ -288,7 +288,7 @@ final class SecretChatController implements Stringable
if ($this->rekeyState !== RekeyState::ACCEPTED || $this->rekeyExchangeId !== $params['exchange_id']) {
return;
}
assert($this->rekeyKey !== null);
\assert($this->rekeyKey !== null);
if ($this->rekeyKey['fingerprint'] !== $params['key_fingerprint']) {
$this->API->methodCallAsyncRead('messages.sendEncryptedService', ['peer' => $this->id, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionAbortKey', 'exchange_id' => $params['exchange_id']]]]);
throw new SecurityException('Invalid key fingerprint!');
@ -496,7 +496,7 @@ final class SecretChatController implements Stringable
private function tryMTProtoV1Decrypt(string $message_key, bool $old, string $encrypted_data): string
{
$key = $old ? $this->oldKey : $this->key;
assert($key !== null);
\assert($key !== null);
[$aes_key, $aes_iv] = Crypt::oldKdf($message_key, $key['auth_key'], true);
$decrypted_data = Crypt::igeDecrypt($encrypted_data, $aes_key, $aes_iv);
$message_data_length = \unpack('V', \substr($decrypted_data, 0, 4))[1];
@ -519,7 +519,7 @@ final class SecretChatController implements Stringable
private function tryMTProtoV2Decrypt(string $message_key, bool $old, string $encrypted_data): string
{
$key = $old ? $this->oldKey : $this->key;
assert($key !== null);
\assert($key !== null);
$key = $key['auth_key'];
[$aes_key, $aes_iv] = Crypt::kdf($message_key, $key, !$this->public->creator);
$decrypted_data = Crypt::igeDecrypt($encrypted_data, $aes_key, $aes_iv);

View File

@ -24,7 +24,6 @@ use danog\MadelineProto\Lang;
use danog\MadelineProto\Logger;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\MTProto\MTProtoOutgoingMessage;
use danog\MadelineProto\SecretPeerNotInDbException;
use danog\MadelineProto\SecurityException;
use danog\MadelineProto\Settings\TLSchema;
use danog\MadelineProto\TL\Types\Button;