Misc bugfixes
This commit is contained in:
parent
bb9804290b
commit
0cb8d7f27e
@ -20,6 +20,8 @@
|
||||
"ext-xml": "*",
|
||||
"ext-fileinfo": "*",
|
||||
"amphp/amp": "^2.0",
|
||||
|
||||
|
||||
"amphp/websocket": "dev-master#db2da8c5b3ed22eae37da5ffa10ab3ea8de19342 as 1",
|
||||
"amphp/websocket-client": "dev-master#aff808025637bd705672338b4904ad03a4dbdc04 as 1",
|
||||
"amphp/socket": "0.10.12 as 1",
|
||||
|
@ -174,11 +174,14 @@ class ReadLoop extends SignalLoop
|
||||
$auth_key_id = yield $buffer->bufferRead(8);
|
||||
|
||||
if ($auth_key_id === "\0\0\0\0\0\0\0\0") {
|
||||
|
||||
$message_id = yield $buffer->bufferRead(8);
|
||||
if (!\in_array($message_id, [1, 0])) {
|
||||
$connection->checkMessageId($message_id, ['outgoing' => false, 'container' => false]);
|
||||
}
|
||||
|
||||
$message_length = \unpack('V', yield $buffer->bufferRead(4))[1];
|
||||
|
||||
$message_data = yield $buffer->bufferRead($message_length);
|
||||
$left = $payload_length - $message_length - 4 - 8 - 8;
|
||||
if ($left) {
|
||||
|
@ -192,17 +192,19 @@ class WriteLoop extends ResumableSignalLoop
|
||||
$has_http_wait = false;
|
||||
$messages = [];
|
||||
$keys = [];
|
||||
foreach ($connection->pending_outgoing as $message) {
|
||||
if ($message['_'] === 'http_wait') {
|
||||
$has_http_wait = true;
|
||||
break;
|
||||
if ($shared->isHttp()) {
|
||||
foreach ($connection->pending_outgoing as $message) {
|
||||
if ($message['_'] === 'http_wait') {
|
||||
$has_http_wait = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$has_http_wait) {
|
||||
$API->logger->logger("Adding http_wait {$connection->pending_outgoing_key}", Logger::ULTRA_VERBOSE);
|
||||
$connection->pending_outgoing[$connection->pending_outgoing_key] = ['_' => 'http_wait', 'serialized_body' => yield $this->API->getTL()->serializeObject(['type' => ''], ['_' => 'http_wait', 'max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], 'http_wait'), 'contentRelated' => true, 'unencrypted' => false, 'method' => true];
|
||||
$temporary_keys[$connection->pending_outgoing_key] = true;
|
||||
$connection->pending_outgoing_key++;
|
||||
}
|
||||
}
|
||||
if ($shared->isHttp() && !$has_http_wait) {
|
||||
$API->logger->logger("Adding http_wait {$connection->pending_outgoing_key}", Logger::ULTRA_VERBOSE);
|
||||
$connection->pending_outgoing[$connection->pending_outgoing_key] = ['_' => 'http_wait', 'serialized_body' => yield $this->API->getTL()->serializeObject(['type' => ''], ['_' => 'http_wait', 'max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], 'http_wait'), 'contentRelated' => true, 'unencrypted' => false, 'method' => true];
|
||||
$temporary_keys[$connection->pending_outgoing_key] = true;
|
||||
$connection->pending_outgoing_key++;
|
||||
}
|
||||
|
||||
$total_length = 0;
|
||||
@ -341,8 +343,11 @@ class WriteLoop extends ResumableSignalLoop
|
||||
$padding += 16;
|
||||
}
|
||||
$padding = \danog\MadelineProto\Tools::random($padding);
|
||||
|
||||
$message_key = \substr(\hash('sha256', \substr($shared->getTempAuthKey()->getAuthKey(), 88, 32).$plaintext.$padding, true), 8, 16);
|
||||
|
||||
list($aes_key, $aes_iv) = $this->aesCalculate($message_key, $shared->getTempAuthKey()->getAuthKey());
|
||||
|
||||
$message = $shared->getTempAuthKey()->getID().$message_key.$this->igeEncrypt($plaintext.$padding, $aes_key, $aes_iv);
|
||||
|
||||
$buffer = yield $connection->stream->getWriteBuffer($len = \strlen($message));
|
||||
|
@ -1203,7 +1203,7 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
// Extra parameters to pass to the proxy class using setExtra
|
||||
'obfuscated' => false,
|
||||
'transport' => 'tcp',
|
||||
'pfs' => \extension_loaded('gmp'),
|
||||
'pfs' => false,//\extension_loaded('gmp'),
|
||||
],
|
||||
'media_socket_count' => [
|
||||
'min' => 5,
|
||||
|
@ -184,6 +184,7 @@ trait AuthKeyHandler
|
||||
*/
|
||||
$p_bytes = $p->toBytes();
|
||||
$q_bytes = $q->toBytes();
|
||||
|
||||
$new_nonce = \danog\MadelineProto\Tools::random(32);
|
||||
$data_unserialized = ['pq' => $pq_bytes, 'p' => $p_bytes, 'q' => $q_bytes, 'nonce' => $nonce, 'server_nonce' => $server_nonce, 'new_nonce' => $new_nonce, 'expires_in' => $expires_in, 'dc' => \preg_replace('|_.*|', '', $datacenter)];
|
||||
$p_q_inner_data = yield $this->TL->serializeObject(['type' => 'p_q_inner_data'.($expires_in < 0 ? '' : '_temp')], $data_unserialized, 'p_q_inner_data');
|
||||
@ -194,6 +195,7 @@ trait AuthKeyHandler
|
||||
$sha_digest = \sha1($p_q_inner_data, true);
|
||||
$random_bytes = \danog\MadelineProto\Tools::random(255 - \strlen($p_q_inner_data) - \strlen($sha_digest));
|
||||
$to_encrypt = $sha_digest.$p_q_inner_data.$random_bytes;
|
||||
|
||||
$encrypted_data = $key->encrypt($to_encrypt);
|
||||
$this->logger->logger('Starting Diffie Hellman key exchange', \danog\MadelineProto\Logger::VERBOSE);
|
||||
/*
|
||||
@ -244,8 +246,10 @@ trait AuthKeyHandler
|
||||
* Get key, iv and decrypt answer
|
||||
*/
|
||||
$encrypted_answer = $server_dh_params['encrypted_answer'];
|
||||
$tmp_aes_key = \sha1($new_nonce.$server_nonce, true).\substr(\sha1($server_nonce.$new_nonce, true), 0, 12);
|
||||
|
||||
$tmp_aes_key = \sha1($new_nonce.$server_nonce, true).\substr(\sha1($server_nonce.$new_nonce, true), 0, 12);
|
||||
$tmp_aes_iv = \substr(\sha1($server_nonce.$new_nonce, true), 12, 8).\sha1($new_nonce.$new_nonce, true).\substr($new_nonce, 0, 4);
|
||||
|
||||
$answer_with_hash = $this->igeDecrypt($encrypted_answer, $tmp_aes_key, $tmp_aes_iv);
|
||||
/*
|
||||
* ***********************************************************************
|
||||
@ -388,7 +392,7 @@ trait AuthKeyHandler
|
||||
if ($expires_in >= 0) {
|
||||
$key->expires(\time() + $expires_in);
|
||||
}
|
||||
$key->setServerSalt(\substr($new_nonce, 0, 8 - 0) ^ \substr($server_nonce, 0, 8 - 0));
|
||||
$key->setServerSalt(\substr($new_nonce, 0, 8) ^ \substr($server_nonce, 0, 8));
|
||||
$key->setAuthKey($auth_key_str);
|
||||
|
||||
$this->logger->logger('Auth key generated', \danog\MadelineProto\Logger::NOTICE);
|
||||
|
@ -54,7 +54,7 @@ class ProxySocketPool implements SocketPool
|
||||
}
|
||||
|
||||
try {
|
||||
$parts = Uri\parse($uri);
|
||||
$parts = \League\Uri\UriString::parse($uri);
|
||||
} catch (\Exception $exception) {
|
||||
throw new SocketException('Could not parse URI', 0, $exception);
|
||||
}
|
||||
|
@ -168,7 +168,6 @@ class BufferedRawStream implements BufferedStreamInterface, BufferInterface, Raw
|
||||
if ($buffer_length >= $length) {
|
||||
return new Success(\fread($this->memory_stream, $length));
|
||||
}
|
||||
|
||||
return \danog\MadelineProto\Tools::call($this->bufferReadGenerator($length));
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,6 @@ class WsStream implements RawStreamInterface
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user