Apply fixes from StyleCI
This commit is contained in:
parent
b19bfa0592
commit
6e02d23f6c
@ -287,7 +287,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
'mtproto' => __DIR__.'/TL_mtproto_v1.json', // mtproto TL scheme
|
||||
'telegram' => __DIR__.'/TL_telegram_v65.tl', // telegram TL scheme
|
||||
'secret' => __DIR__.'/TL_secret.tl', // secret chats TL scheme
|
||||
'calls' => __DIR__.'/TL_calls.tl', // calls TL scheme
|
||||
'calls' => __DIR__.'/TL_calls.tl', // calls TL scheme
|
||||
'td' => __DIR__.'/TL_td.tl', // telegram-cli TL scheme
|
||||
'botAPI' => __DIR__.'/TL_botAPI.tl', // bot API TL scheme for file ids
|
||||
],
|
||||
|
@ -192,7 +192,9 @@ trait PeerHandler
|
||||
}
|
||||
|
||||
if (is_numeric($id)) {
|
||||
if (is_string($id)) $id = $this->bigint ? ((float) $id) : ((int) $id);
|
||||
if (is_string($id)) {
|
||||
$id = $this->bigint ? ((float) $id) : ((int) $id);
|
||||
}
|
||||
if (isset($this->chats[$id])) {
|
||||
return $this->gen_all($this->chats[$id]);
|
||||
}
|
||||
@ -505,7 +507,9 @@ trait PeerHandler
|
||||
}
|
||||
throw new \danog\MadelineProto\Exception('resolve_username returned an unexpected constructor: '.var_export($res, true));
|
||||
}
|
||||
public function to_supergroup($id) {
|
||||
return -($id + pow(10, (int) floor(log($id, 10)+3)));
|
||||
|
||||
public function to_supergroup($id)
|
||||
{
|
||||
return -($id + pow(10, (int) floor(log($id, 10) + 3)));
|
||||
}
|
||||
}
|
||||
|
@ -513,6 +513,7 @@ trait UpdateHandler
|
||||
if ($update['qts'] > $cur_state['qts'] + 1) {
|
||||
\danog\MadelineProto\Logger::log(['Qts hole. update qts: '.$update['qts'].' > current qts '.$cur_state['qts'].'+1, chat id: '.$update['message']['chat_id']], \danog\MadelineProto\Logger::ERROR);
|
||||
$this->get_updates_difference();
|
||||
|
||||
return false;
|
||||
}
|
||||
\danog\MadelineProto\Logger::log(['Applying qts: '.$update['qts'].' over current qts '.$cur_state['qts'].', chat id: '.$update['message']['chat_id']], \danog\MadelineProto\Logger::VERBOSE);
|
||||
|
@ -43,6 +43,7 @@ trait MessageHandler
|
||||
$this->secret_chats[$chat_id]['out_seq_no']++;
|
||||
|
||||
$message = $this->secret_chats[$chat_id]['key']['fingerprint'].$message_key.$this->ige_encrypt($message, $aes_key, $aes_iv);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
@ -57,10 +58,13 @@ trait MessageHandler
|
||||
$old = false;
|
||||
if ($auth_key_id !== $this->secret_chats[$message['message']['chat_id']]['key']['fingerprint']) {
|
||||
if (isset($this->secret_chats[$message['message']['chat_id']]['old_key']['fingerprint'])) {
|
||||
if ($auth_key_id !== $this->secret_chats[$message['message']['chat_id']]['old_key']['fingerprint']) throw new \danog\MadelineProto\SecurityException('Key fingerprint mismatch');
|
||||
if ($auth_key_id !== $this->secret_chats[$message['message']['chat_id']]['old_key']['fingerprint']) {
|
||||
throw new \danog\MadelineProto\SecurityException('Key fingerprint mismatch');
|
||||
}
|
||||
$old = true;
|
||||
} else throw new \danog\MadelineProto\SecurityException('Key fingerprint mismatch');
|
||||
|
||||
} else {
|
||||
throw new \danog\MadelineProto\SecurityException('Key fingerprint mismatch');
|
||||
}
|
||||
}
|
||||
$message_key = substr($message['message']['bytes'], 8, 16);
|
||||
$encrypted_data = substr($message['message']['bytes'], 24);
|
||||
|
@ -19,39 +19,42 @@ trait SeqNoHandler
|
||||
{
|
||||
public function check_secret_in_seq_no($chat_id, $seqno)
|
||||
{
|
||||
$seqno = ($seqno - $this->secret_chats[$chat_id]['out_seq_no_x'])/2;
|
||||
$seqno = ($seqno - $this->secret_chats[$chat_id]['out_seq_no_x']) / 2;
|
||||
$last = 0;
|
||||
foreach ($this->secret_chats[$chat_id]['incoming'] as $message) {
|
||||
if (isset($message['decrypted_message']['in_seq_no'])) {
|
||||
if (($message['decrypted_message']['in_seq_no'] - $this->secret_chats[$chat_id]['out_seq_no_x'])/2 < $last) {
|
||||
|
||||
if (($message['decrypted_message']['in_seq_no'] - $this->secret_chats[$chat_id]['out_seq_no_x']) / 2 < $last) {
|
||||
unset($this->secret_chats[$chat_id]);
|
||||
throw new \danog\MadelineProto\SecurityException('in_seq_no is not increasing');
|
||||
}
|
||||
$last = ($message['decrypted_message']['in_seq_no'] - $this->secret_chats[$chat_id]['out_seq_no_x'])/2;
|
||||
$last = ($message['decrypted_message']['in_seq_no'] - $this->secret_chats[$chat_id]['out_seq_no_x']) / 2;
|
||||
}
|
||||
}
|
||||
if ($seqno > $this->secret_chats[$chat_id]['out_seq_no']+1) {
|
||||
if ($seqno > $this->secret_chats[$chat_id]['out_seq_no'] + 1) {
|
||||
unset($this->secret_chats[$chat_id]);
|
||||
throw new \danog\MadelineProto\SecurityException('in_seq_no is too big');
|
||||
}
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function check_secret_out_seq_no($chat_id, $seqno)
|
||||
{
|
||||
$seqno = ($seqno - $this->secret_chats[$chat_id]['in_seq_no_x'])/2;
|
||||
$seqno = ($seqno - $this->secret_chats[$chat_id]['in_seq_no_x']) / 2;
|
||||
$C = 0;
|
||||
foreach ($this->secret_chats[$chat_id]['incoming'] as $message) {
|
||||
if (isset($message['decrypted_message']['out_seq_no']) && $C !== $this->secret_chats[$chat_id]['in_seq_no']-1) {
|
||||
if (isset($message['decrypted_message']['out_seq_no']) && $C !== $this->secret_chats[$chat_id]['in_seq_no'] - 1) {
|
||||
if (($message['decrypted_message']['out_seq_no'] - $this->secret_chats[$chat_id]['in_seq_no_x']) / 2 !== $C) {
|
||||
throw new \danog\MadelineProto\SecurityException('out_seq_no hole: should be '.$C.', is '.(($message['decrypted_message']['out_seq_no'] - $this->secret_chats[$chat_id]['in_seq_no_x'])/2));
|
||||
} else $C++;
|
||||
throw new \danog\MadelineProto\SecurityException('out_seq_no hole: should be '.$C.', is '.(($message['decrypted_message']['out_seq_no'] - $this->secret_chats[$chat_id]['in_seq_no_x']) / 2));
|
||||
} else {
|
||||
$C++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($seqno < $C) { // <= C
|
||||
\danog\MadelineProto\Logger::log(['WARNING: dropping repeated message with seqno '.$seqno]);
|
||||
$this->secret_chats[$chat_id]['in_seq_no']--;
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($seqno > $C) { // > C+1
|
||||
@ -59,6 +62,7 @@ trait SeqNoHandler
|
||||
throw new \danog\MadelineProto\SecurityException('WARNING: out_seq_no gap detected ('.$seqno.' > '.$C.')!');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -71,5 +75,4 @@ trait SeqNoHandler
|
||||
{
|
||||
return ($this->secret_chats[$chat]['out_seq_no'] * 2) + $this->secret_chats[$chat]['out_seq_no_x'];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -343,6 +343,7 @@ trait TL
|
||||
if (!$bare) {
|
||||
$concat .= \danog\PHP\Struct::pack('<i', $constructorData['id']);
|
||||
}
|
||||
|
||||
return $concat.$this->serialize_params($constructorData, $object, $layer);
|
||||
}
|
||||
|
||||
@ -390,7 +391,7 @@ trait TL
|
||||
continue;
|
||||
}
|
||||
if ($current_argument['name'] === 'random_bytes') {
|
||||
$serialized .= $this->serialize_object(['type' => 'bytes'], $this->random(15+(4*(random_int(0, PHP_INT_MAX) % 3))));
|
||||
$serialized .= $this->serialize_object(['type' => 'bytes'], $this->random(15 + (4 * (random_int(0, PHP_INT_MAX) % 3))));
|
||||
continue;
|
||||
}
|
||||
if ($current_argument['name'] === 'data' && isset($arguments['message'])) {
|
||||
@ -561,7 +562,9 @@ trait TL
|
||||
if ($arg['name'] === 'random_bytes') {
|
||||
if (strlen($x[$arg['name']]) < 15) {
|
||||
throw new \danog\MadelineProto\SecurityException('random_bytes is too small!');
|
||||
} else unset($x[$arg['name']]);
|
||||
} else {
|
||||
unset($x[$arg['name']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($x['flags'])) { // I don't think we need this anymore
|
||||
|
@ -56,11 +56,14 @@ class TLConstructor extends TLParams
|
||||
$key = $k;
|
||||
$newlayer = $this->layer[$k];
|
||||
}
|
||||
if (!isset($key)) $key = $keys[0];
|
||||
if (!isset($key)) {
|
||||
$key = $keys[0];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$key = array_search($predicate, $this->predicate);
|
||||
}
|
||||
|
||||
return ($key === false) ? false : [
|
||||
'id' => $this->id[$key],
|
||||
'predicate' => $this->predicate[$key],
|
||||
|
@ -20,7 +20,7 @@ $MadelineProto = false;
|
||||
try {
|
||||
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
var_dump($e);
|
||||
var_dump($e);
|
||||
}
|
||||
if (file_exists('.env')) {
|
||||
echo 'Loading .env...'.PHP_EOL;
|
||||
@ -85,8 +85,6 @@ $InputEncryptedChat = $MadelineProto->get_secret_chat($secret)['InputEncryptedCh
|
||||
$sentMessage = $MadelineProto->messages->sendEncrypted(['peer' => $InputEncryptedChat, 'message' => ['_' => 'decryptedMessage', 'media' => ['_' => 'decryptedMessageMediaEmpty'], 'ttl' => 10, 'message' => $message, 'entities' => [['_' => 'messageEntityCode', 'offset' => 0, 'length' => mb_strlen($message)]]]]); // should work with all layers
|
||||
\danog\MadelineProto\Logger::log([$sentMessage], \danog\MadelineProto\Logger::NOTICE);
|
||||
|
||||
|
||||
|
||||
$media = [];
|
||||
$secret_media = [];
|
||||
|
||||
@ -104,7 +102,6 @@ $secret_media['document_photo'] = ['peer' => $secret, 'file' => $inputEncryptedF
|
||||
// Photo, secret chat
|
||||
$secret_media['photo'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaPhoto', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'caption' => 'This file was uploaded using MadelineProto', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'size' => filesize('tests/faust.jpg'), 'w' => 1280, 'h' => 914]]];
|
||||
|
||||
|
||||
// GIF
|
||||
$inputFile = $MadelineProto->upload('tests/pony.mp4');
|
||||
$media['gif'] = ['_' => 'inputMediaUploadedDocument', 'file' => $inputFile, 'mime_type' => mime_content_type('tests/pony.mp4'), 'caption' => 'test', 'attributes' => [['_' => 'documentAttributeAnimated']]];
|
||||
@ -137,7 +134,6 @@ $media['audio'] = ['_' => 'inputMediaUploadedDocument', 'file' => $inputFile, 'm
|
||||
$inputEncryptedFile = $MadelineProto->upload_encrypted('tests/mosconi.mp3');
|
||||
$secret_media['audio'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/mosconi.mp3'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'mosconi.mp3', 'size' => filesize('tests/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false, 'duration' => 1, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
|
||||
|
||||
|
||||
// voice
|
||||
$media['voice'] = ['_' => 'inputMediaUploadedDocument', 'file' => $inputFile, 'mime_type' => mime_content_type('tests/mosconi.mp3'), 'caption' => 'test', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'duration' => 1, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]];
|
||||
$secret_media['voice'] = ['peer' => $secret, 'file' => $inputEncryptedFile, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => '', 'media' => ['_' => 'decryptedMessageMediaDocument', 'thumb' => file_get_contents('tests/faust.preview.jpg'), 'thumb_w' => 90, 'thumb_h' => 90, 'mime_type' => mime_content_type('tests/mosconi.mp3'), 'caption' => 'test', 'key' => $inputEncryptedFile['key'], 'iv' => $inputEncryptedFile['iv'], 'file_name' => 'mosconi.mp3', 'size' => filesize('tests/mosconi.mp3'), 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true, 'duration' => 1, 'title' => 'AH NON LO SO IO', 'performer' => 'IL DIO GERMANO MOSCONI']]]]];
|
||||
|
Loading…
Reference in New Issue
Block a user