Some CDN fixes

This commit is contained in:
Daniil Gentili 2017-07-24 09:18:10 +02:00
parent 54f69ece92
commit 4c05506baf
3 changed files with 14 additions and 5 deletions

View File

@ -195,7 +195,7 @@ class MTProto extends \Volatile
\danog\MadelineProto\Logger::class_exists();
// Detect ipv6
$this->ipv6 = strlen(@file_get_contents('http://ipv6.test-ipv6.com/', false, stream_context_create(['http' => ['timeout' => 1]]))) > 0;
$this->ipv6 = (bool) strlen(@file_get_contents('http://ipv6.test-ipv6.com/', false, stream_context_create(['http' => ['timeout' => 1]]))) > 0;
preg_match('/const V = (\d+);/', file_get_contents('https://raw.githubusercontent.com/danog/MadelineProto/master/src/danog/MadelineProto/MTProto.php'), $matches);
if (isset($matches[1]) && self::V < (int) $matches[1]) {

View File

@ -325,6 +325,7 @@ trait Files
}
if (isset($message_media['key'])) {
$res['bytes'] = $ige->decrypt($res['bytes']);
$this->check_cdn_hash($msssage_media['file_token'], $offset, $res['bytes'], $datacenter);
}
if ($start_at) {
$res['bytes'] = substr($res['bytes'], $start_at);
@ -350,7 +351,9 @@ trait Files
if ($end === -1) {
$cb(100);
}
if ($cdn) {
$this->clear_cdn_hashes($message_media['file_token']);
}
return true;
}
@ -366,7 +369,7 @@ trait Files
}
}
private function check_cdn_hashes($file, $offset, $data, &$datacenter)
private function check_cdn_hash($file, $offset, $data, &$datacenter)
{
if (!isset($this->cdn_hashes[$file][$offset])) {
$this->add_cdn_hashes($this->method_call('upload.getCdnFileHashes', ['file_token' => $file, 'offset' => $offset], ['datacenter' => &$datacenter]));
@ -374,12 +377,16 @@ trait Files
if (!isset($this->cdn_hashes[$file][$offset])) {
throw new \danog\MadelineProto\Exception('Could not fetch CDN hashes for offset '.$offset);
}
if (hash('sha256', substr($data, 0, $this->cdn_hashes[$file][$offset]['limit']), true) !== $this->cdn_hashes[$file][$offset]['hash']) {
if (hash('sha256', $data, true) !== $this->cdn_hashes[$file][$offset]['hash']) {
throw new \danog\MadelineProto\SecurityException('CDN hashe mismatch for offset '.$offset);
}
unset($this->cdn_hashes[$file][$offset]);
return true;
}
private function clear_cdn_hashes($file)
{
unset($this->cdn_hashes[$file]);
return true;
}
}

View File

@ -29,7 +29,9 @@ if (file_exists('.env')) {
$dotenv = new Dotenv\Dotenv(getcwd());
$dotenv->load();
}
if (getenv('TEST_SECRET_CHAT') == '') {
die('TEST_SECRET_CHAT is not defined in .env, please define it.'.PHP_EOL);
}
echo 'Loading settings...'.PHP_EOL;
$settings = json_decode(getenv('MTPROTO_SETTINGS'), true) ?: [];