diff --git a/src/danog/MadelineProto/SecretChats/AuthKeyHandler.php b/src/danog/MadelineProto/SecretChats/AuthKeyHandler.php index 8e15e455..fe11f435 100644 --- a/src/danog/MadelineProto/SecretChats/AuthKeyHandler.php +++ b/src/danog/MadelineProto/SecretChats/AuthKeyHandler.php @@ -248,7 +248,7 @@ trait AuthKeyHandler throw new \danog\MadelineProto\SecurityException('Invalid key fingerprint!'); } yield $this->methodCallAsyncRead('messages.sendEncryptedService', ['peer' => $chat, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionCommitKey', 'exchange_id' => $params['exchange_id'], 'key_fingerprint' => $key['fingerprint']]]], ['datacenter' => $this->datacenter->curdc]); - unset($this->temp_rekeyed_secret_chats[$chat]); + unset($this->temp_rekeyed_secret_chats[$params['exchange_id']]); $this->secret_chats[$chat]['rekeying'] = [0]; $this->secret_chats[$chat]['old_key'] = $this->secret_chats[$chat]['key']; $this->secret_chats[$chat]['key'] = $key; @@ -267,10 +267,10 @@ trait AuthKeyHandler */ private function completeRekey(int $chat, array $params): \Generator { - if ($this->secret_chats[$chat]['rekeying'][0] !== 2 || !isset($this->temp_rekeyed_secret_chats['fingerprint'])) { + if ($this->secret_chats[$chat]['rekeying'][0] !== 2 || !isset($this->temp_rekeyed_secret_chats[$params['exchange_id']]['fingerprint'])) { return; } - if ($this->temp_rekeyed_secret_chats['fingerprint'] !== $params['key_fingerprint']) { + if ($this->temp_rekeyed_secret_chats[$params['exchange_id']]['fingerprint'] !== $params['key_fingerprint']) { yield $this->methodCallAsyncRead('messages.sendEncryptedService', ['peer' => $chat, 'message' => ['_' => 'decryptedMessageService', 'action' => ['_' => 'decryptedMessageActionAbortKey', 'exchange_id' => $params['exchange_id']]]], ['datacenter' => $this->datacenter->curdc]); throw new \danog\MadelineProto\SecurityException('Invalid key fingerprint!'); @@ -278,7 +278,7 @@ trait AuthKeyHandler $this->logger->logger('Completing rekeying of secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE); $this->secret_chats[$chat]['rekeying'] = [0]; $this->secret_chats[$chat]['old_key'] = $this->secret_chats[$chat]['key']; - $this->secret_chats[$chat]['key'] = $this->temp_rekeyed_secret_chats[$chat]; + $this->secret_chats[$chat]['key'] = $this->temp_rekeyed_secret_chats[$params['exchange_id']]; $this->secret_chats[$chat]['ttr'] = 100; $this->secret_chats[$chat]['updated'] = \time(); unset($this->temp_rekeyed_secret_chats[$params['exchange_id']]); @@ -347,9 +347,7 @@ trait AuthKeyHandler if (isset($this->temp_requested_secret_chats[$chat])) { unset($this->temp_requested_secret_chats[$chat]); } - if (isset($this->temp_rekeyed_secret_chats[$chat])) { - unset($this->temp_rekeyed_secret_chats[$chat]); - } + try { yield $this->methodCallAsyncRead('messages.discardEncryption', ['chat_id' => $chat], ['datacenter' => $this->datacenter->curdc]);