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

Fuzz test fixes related to pre_key_id and archived sessions count #521

Closed
wants to merge 3 commits into from
Closed
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
22 changes: 19 additions & 3 deletions rust/protocol/fuzz/fuzz_targets/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct Participant {
store: InMemSignalProtocolStore,
message_queue: Vec<(CiphertextMessage, Box<[u8]>)>,
archive_count: u8,
pre_key_count: u32,
}

impl Participant {
Expand All @@ -41,7 +42,8 @@ impl Participant {
.calculate_signature(&their_signed_pre_key_public, rng)
.unwrap();

let signed_pre_key_id: SignedPreKeyId = rng.gen_range(0..0xFF_FFFF).into();
them.pre_key_count += 1;
let signed_pre_key_id: SignedPreKeyId = them.pre_key_count.into();

them.store
.save_signed_pre_key(
Expand All @@ -56,8 +58,10 @@ impl Participant {
.await
.unwrap();

them.pre_key_count += 1;
let pre_key_id: PreKeyId = them.pre_key_count.into();

let pre_key_info = if use_one_time_pre_key {
let pre_key_id: PreKeyId = rng.gen_range(0..0xFF_FFFF).into();
let one_time_pre_key = KeyPair::generate(rng);

them.store
Expand Down Expand Up @@ -195,6 +199,7 @@ fuzz_target!(|data: (u64, &[u8])| {
.unwrap(),
message_queue: Vec::new(),
archive_count: 0,
pre_key_count: 0,
};
let mut bob = Participant {
name: "bob",
Expand All @@ -206,6 +211,7 @@ fuzz_target!(|data: (u64, &[u8])| {
.unwrap(),
message_queue: Vec::new(),
archive_count: 0,
pre_key_count: 0,
};

for action in actions {
Expand All @@ -216,10 +222,20 @@ fuzz_target!(|data: (u64, &[u8])| {
};
match action >> 1 {
0 => {
if me.archive_count < 40 {
let mut estimated_prev_states = 0;
// The set of previous session states grows in two ways:
// 1) The current session state of "me" is archived explicitly.
estimated_prev_states += me.archive_count;
// 2) A pre-key message is received from "them" and displaces the
// current session state. They may send one pre-key message initially.
// Additional pre-key messages from "them" follow explicit archiving.
estimated_prev_states += 1 + them.archive_count;
if estimated_prev_states < 40 {
// Only archive if it can't result in old sessions getting expired.
// We're not testing that.
me.archive_session(&them.address).await
} else {
info!("{}: archiving LIMITED at {}/{}", me.name, me.archive_count, them.archive_count);
}
}
1..=32 => me.receive_messages(&them.address, &mut csprng).await,
Expand Down