Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch internal salt responses in mtproto #272

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/grammers-mtproto/src/mtp/encrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub struct Encrypted {
start_salt_time: Option<(i32, Instant)>,

/// Internal request for salts which should not be propagated.
salt_request_msg_id: Option<i64>,
salt_request_msg_id: Option<MsgId>,

/// The secure, random identifier for this instance.
client_id: i64,
Expand Down Expand Up @@ -239,14 +239,12 @@ impl Encrypted {
// This would break, because we couldn't identify the response.
//
// So salts are only requested once we have a valid salt to reduce the chances of this happening.
if self.salts.len() == 1 {
info!("only one future salt remaining; asking for more salts");
}
info!("only one future salt remaining; asking for more salts");
let body = tl::functions::GetFutureSalts {
num: NUM_FUTURE_SALTS,
}
.to_bytes();
self.serialize_msg(buffer, &body, true);
self.salt_request_msg_id = Some(self.serialize_msg(buffer, &body, true));
}
}

Expand Down Expand Up @@ -644,7 +642,7 @@ impl Encrypted {

if self
.salt_request_msg_id
.is_some_and(|msg_id| msg_id == bad_msg.bad_msg_id())
.is_some_and(|msg_id| msg_id == MsgId(bad_msg.bad_msg_id()))
{
// Response to internal request, do not propagate.
self.salt_request_msg_id = None;
Expand Down Expand Up @@ -881,7 +879,7 @@ impl Encrypted {

if self
.salt_request_msg_id
.is_some_and(|msg_id| msg_id == salts.req_msg_id)
.is_some_and(|msg_id| msg_id == MsgId(salts.req_msg_id))
{
// Response to internal request, do not propagate.
self.salt_request_msg_id = None;
Expand Down Expand Up @@ -1306,6 +1304,7 @@ impl Mtp for Encrypted {
self.last_msg_id = 0;
self.pending_ack.clear();
self.msg_count = 0;
self.salt_request_msg_id = None;
}
}

Expand Down
Loading