This commit is contained in:
danogentili 2017-03-25 17:42:12 +03:00
parent 9f2a240d15
commit cde197a2bf
7 changed files with 43 additions and 66 deletions

View File

@ -280,6 +280,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
'telegram' => __DIR__.'/TL_telegram_v62.tl', // telegram TL scheme
'secret' => __DIR__.'/TL_secret.tl', // secret chats TL scheme
'td' => __DIR__.'/TL_td.tl', // telegram-cli TL scheme
'botAPI' => __DIR__.'/TL_botAPI.tl', // bot API TL scheme for file ids
],
],
'logger' => [ // Logger settings
@ -477,7 +478,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
public function getV()
{
return 4;
return 5;
}
public function get_self()

View File

@ -68,7 +68,7 @@ trait AuthKeyHandler
if (!isset($this->key->keydata['fp'])) {
$this->key = new \danog\MadelineProto\RSA($this->settings['authorization']['rsa_key']);
}
if (in_array($this->key->keydata['fp'], $ResPQ['server_public_key_fingerprints'])) {
if (!in_array($this->key->keydata['fp'], $ResPQ['server_public_key_fingerprints'])) {
throw new \danog\MadelineProto\SecurityException("Couldn't find our key in the server_public_key_fingerprints vector.");
}
$pq_bytes = $ResPQ['pq'];

View File

@ -203,7 +203,7 @@ trait PeerHandler
}
}
$dbres = json_decode(file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http'=> [
'timeout' => 1,
'timeout' => 2,
],
])), true);
if ($dbres['ok']) {

View File

@ -29,7 +29,7 @@ trait SeqNoHandler
public function check_in_seq_no($datacenter, $current_msg_id)
{
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) && ($seq_no = $this->generate_in_seq_no($datacenter, $this->content_related($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_']))) !== $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) {
\danog\MadelineProto\Logger::log(['Seqno mismatch (should be '.$seq_no.', is '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no'].', '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].')'], \danog\MadelineProto\Logger::ERROR);
\danog\MadelineProto\Logger::log(['SECURITY WARNING: Seqno mismatch (should be '.$seq_no.', is '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no'].', '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].')'], \danog\MadelineProto\Logger::ERROR);
}
}

View File

@ -243,7 +243,6 @@ trait BotAPI
return [];
case 'messageMediaDocument':
$type = 5;
$type_name = 'document';
$res = [];
if ($data['document']['thumb']['_'] === 'photoSize') {
@ -260,9 +259,7 @@ trait BotAPI
case 'documentAttributeAudio':
$audio = $attribute;
$type_name = 'audio';
$type = 9;
if ($attribute['voice']) {
$type = 3;
$type_name = 'voice';
}
$res['duration'] = $attribute['duration'];
@ -278,7 +275,6 @@ trait BotAPI
break;
case 'documentAttributeVideo':
$type = 4;
$type_name = 'video';
$res['width'] = $attribute['w'];
$res['height'] = $attribute['h'];
@ -300,7 +296,6 @@ trait BotAPI
case 'documentAttributeSticker':
$type_name = 'sticker';
$type = 8;
$res['mask'] = $attribute['mask'];
$res['emoji'] = $attribute['alt'];
$res['sticker_set'] = $attribute['stickerset'];
@ -329,7 +324,7 @@ trait BotAPI
}
$res['file_size'] = $data['document']['size'];
$res['mime_type'] = $data['document']['mime_type'];
$res['file_id'] = $this->base64url_encode($this->rle_encode(\danog\PHP\Struct::pack('<iiqqb', $type, $data['document']['dc_id'], $data['document']['id'], $data['document']['access_hash'], 2)));
$res['file_id'] = $this->base64url_encode($this->rle_encode($this->serialize_object(['type' => 'bot_'.$type_name], $data['document']).chr(2)));
return [$type_name => $res, 'caption' => $data['caption']];
default:

View File

@ -66,7 +66,10 @@ trait BotAPIFiles
public function photosize_to_botapi($photo, $message_media, $thumbnail = false)
{
$ext = $this->get_extension_from_location(['_' => 'inputFileLocation', 'volume_id' => $photo['location']['volume_id'], 'local_id' => $photo['location']['local_id'], 'secret' => $photo['location']['secret'], 'dc_id' => $photo['location']['dc_id']], '.jpg');
$data = \danog\PHP\Struct::pack('<iiqqqqib', $thumbnail ? 0 : 2, $photo['location']['dc_id'], isset($message_media['id']) ? $message_media['id'] : 0, isset($message_media['access_hash']) ? $message_media['access_hash'] : 0, $photo['location']['volume_id'], $photo['location']['secret'], $photo['location']['local_id'], 2);
$photo['location']['access_hash'] = isset($message_media['access_hash']) ? $message_media['access_hash'] : 0;
$photo['location']['id'] = isset($message_media['id']) ? $message_media['id'] : 0;
$data = $this->serialize_object(['type' => $thumbnail ? 'bot_thumbnail' : 'bot_photo'], $photo['location']).chr(2);
return [
'file_id' => $this->base64url_encode($this->rle_encode($data)),
@ -81,79 +84,57 @@ trait BotAPIFiles
public function unpack_file_id($file_id)
{
$file_id = $this->rle_decode($this->base64url_decode($file_id));
$res = [];
$type = \danog\PHP\Struct::unpack('<i', substr($file_id, 0, 4))[0];
switch ($type) {
case 0:
if ($file_id[strlen($file_id) - 1] !== chr(2)) throw new Exception('Invalid last byte');
$deserialized = $this->deserialize($file_id);
$res = ['type' => str_replace('bot_', $deserialized['_'])];
switch ($deserialized['_']) {
case 'bot_thumbnail':
case 'bot_photo':
$constructor = ['_' => 'photo', 'sizes' => []];
list($type, $constructor['sizes'][0]['location']['dc_id'], $constructor['id'], $constructor['access_hash'], $constructor['sizes'][0]['location']['volume_id'], $constructor['sizes'][0]['location']['secret'], $constructor['sizes'][0]['location']['local_id'], $verify) = \danog\PHP\Struct::unpack('<iiqqqqib', $file_id);
if ($verify !== 2) {
throw new Exception('Invalid last byte');
}
$res['type'] = 'photo';
$constructor['id'] = $deserialized['id'];
$constructor['access_hash'] = $deserialized['access_hash'];
unset($deserialized['id']);
unset($deserialized['access_hash']);
unset($deserialized['_']);
$constructor['sizes'][0]['location'] = $deserialized;
$res['MessageMedia'] = ['_' => 'messageMediaPhoto', 'photo' => $constructor, 'caption' => ''];
return $res;
case 2:
$constructor = ['_' => 'photo', 'sizes' => []];
list($type, $constructor['sizes'][0]['location']['dc_id'], $constructor['id'], $constructor['access_hash'], $constructor['sizes'][0]['location']['volume_id'], $constructor['sizes'][0]['location']['secret'], $constructor['sizes'][0]['location']['local_id'], $verify) = \danog\PHP\Struct::unpack('<iiqqqqib', $file_id);
if ($verify !== 2) {
throw new Exception('Invalid last byte');
}
$res['type'] = 'photo';
$res['MessageMedia'] = ['_' => 'messageMediaPhoto', 'photo' => $constructor, 'caption' => ''];
return $res;
case 3:
$constructor = ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true]]];
list($type, $constructor['dc_id'], $constructor['id'], $constructor['access_hash'], $verify) = \danog\PHP\Struct::unpack('<iiqqb', $file_id);
if ($verify !== 2) {
throw new Exception('Invalid last byte');
}
$res['type'] = 'voice';
case 'bot_voice':
unset($deserialized['_']);
$constructor = array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true]]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 4:
$res['type'] = 'videos';
$constructor = ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeVideo']]];
list($type, $constructor['dc_id'], $constructor['id'], $constructor['access_hash'], $verify) = \danog\PHP\Struct::unpack('<iiqqb', $file_id);
if ($verify !== 2) {
throw new Exception('Invalid last byte');
}
case 'bot_video':
unset($deserialized['_']);
$constructor = array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeVideo']]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 5:
$res['type'] = 'document';
$constructor = ['_' => 'document', 'mime_type' => '', 'attributes' => []];
list($type, $constructor['dc_id'], $constructor['id'], $constructor['access_hash'], $verify) = \danog\PHP\Struct::unpack('<iiqqb', $file_id);
if ($verify !== 2) {
throw new Exception('Invalid last byte');
}
case 'bot_document':
unset($deserialized['_']);
$constructor = array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => []]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 8:
$constructor = ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeSticker']]];
list($type, $constructor['dc_id'], $constructor['id'], $constructor['access_hash'], $verify) = \danog\PHP\Struct::unpack('<iiqqb', $file_id);
if ($verify !== 2) {
throw new Exception('Invalid last byte');
}
$res['type'] = 'sticker';
case 'bot_sticker':
unset($deserialized['_']);
$constructor = array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeSticker']]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 9:
$constructor = ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false]]];
list($type, $constructor['dc_id'], $constructor['id'], $constructor['access_hash'], $verify) = \danog\PHP\Struct::unpack('<iiqqb', $file_id);
if ($verify !== 2) {
throw new Exception('Invalid last byte');
}
$res['type'] = 'music';
case 'bot_audio':
unset($deserialized['_']);
$constructor = array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false]]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;

View File

@ -119,7 +119,7 @@ trait TL
'',
'', ], $line);
$id = hash('crc32b', $clean);
if (preg_match('/^[^\s]+#/', $line)) {
if (preg_match('/^[^\s]+#/', $line) && $scheme_type !== 'botAPI') {
$nid = str_pad(preg_replace(['/^[^#]+#/', '/\s.+/'], '', $line), 8, '0', \STR_PAD_LEFT);
if ($id !== $nid) {
\danog\MadelineProto\Logger::log(['CRC32 mismatch ('.$id.', '.$nid.') for '.$line], \danog\MadelineProto\Logger::ERROR);
@ -554,7 +554,7 @@ trait TL
break;
}
}
if (in_array($arg['name'], ['msg_ids', 'msg_id', 'bad_msg_id', 'req_msg_id', 'answer_msg_id', 'first_msg_id', 'key_fingerprint', 'server_salt', 'new_server_salt'])) {
if (in_array($arg['name'], ['msg_ids', 'msg_id', 'bad_msg_id', 'req_msg_id', 'answer_msg_id', 'first_msg_id', 'key_fingerprint', 'server_salt', 'new_server_salt', 'server_public_key_fingerprints'])) {
$arg['strlong'] = true;
}
$x[$arg['name']] = $this->deserialize($bytes_io, $arg);