Skip to content

Commit

Permalink
Fix bug where double-hitting a ciphertext deleted the whole ratchet (#…
Browse files Browse the repository at this point in the history
…228)

Co-authored-by: Marta Mularczyk <[email protected]>
  • Loading branch information
mulmarta and Marta Mularczyk authored Dec 23, 2024
1 parent 3add368 commit 543b050
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
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

0 comments on commit 543b050

Please sign in to comment.