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

Fix bug where double-hitting a ciphertext deleted the whole ratchet #228

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion mls-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mls-rs"
version = "0.43.1"
version = "0.43.2"
edition = "2021"
description = "An implementation of Messaging Layer Security (RFC 9420)"
homepage = "https://github.com/awslabs/mls-rs"
Expand Down
28 changes: 26 additions & 2 deletions mls-rs/src/group/secret_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ impl<T: TreeIndex> SecretTree<T> {

let res = ratchet
.message_key_generation(cipher_suite, generation, key_type)
.await?;
.await;

self.known_secrets
.set_node(leaf_index, SecretTreeNode::Ratchet(ratchet));

Ok(res)
res
}
}

Expand Down Expand Up @@ -808,6 +808,30 @@ mod tests {
)
}

#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))]
async fn double_hit_leaves_epoch_intact() {
let cs = test_cipher_suite_provider(TEST_CIPHER_SUITE);
let test_secret = vec![0u8; cs.kdf_extract_size()];
let mut test_tree = get_test_tree(test_secret, 4u32);
let key_type = KeyType::Application;

// We receive a ciphertext from leaf 2 (node 4)
test_tree
.message_key_generation(&cs, 4, key_type, 0)
.await
.unwrap();

// Due to a double hit we receive that ciphertext again
let res = test_tree.message_key_generation(&cs, 4, key_type, 0).await;
assert_matches!(res, Err(MlsError::KeyMissing(0)));

// We receive another ciphertext from leaf 2
test_tree
.message_key_generation(&cs, 4, key_type, 1)
.await
.unwrap();
}

#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)]
struct Ratchet {
application_keys: Vec<Vec<u8>>,
Expand Down
Loading