Skip to content

Commit 543b050

Browse files
mulmartaMarta Mularczyk
and
Marta Mularczyk
authored
Fix bug where double-hitting a ciphertext deleted the whole ratchet (#228)
Co-authored-by: Marta Mularczyk <[email protected]>
1 parent 3add368 commit 543b050

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

mls-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mls-rs"
3-
version = "0.43.1"
3+
version = "0.43.2"
44
edition = "2021"
55
description = "An implementation of Messaging Layer Security (RFC 9420)"
66
homepage = "https://github.com/awslabs/mls-rs"

mls-rs/src/group/secret_tree.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ impl<T: TreeIndex> SecretTree<T> {
262262

263263
let res = ratchet
264264
.message_key_generation(cipher_suite, generation, key_type)
265-
.await?;
265+
.await;
266266

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

270-
Ok(res)
270+
res
271271
}
272272
}
273273

@@ -808,6 +808,30 @@ mod tests {
808808
)
809809
}
810810

811+
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))]
812+
async fn double_hit_leaves_epoch_intact() {
813+
let cs = test_cipher_suite_provider(TEST_CIPHER_SUITE);
814+
let test_secret = vec![0u8; cs.kdf_extract_size()];
815+
let mut test_tree = get_test_tree(test_secret, 4u32);
816+
let key_type = KeyType::Application;
817+
818+
// We receive a ciphertext from leaf 2 (node 4)
819+
test_tree
820+
.message_key_generation(&cs, 4, key_type, 0)
821+
.await
822+
.unwrap();
823+
824+
// Due to a double hit we receive that ciphertext again
825+
let res = test_tree.message_key_generation(&cs, 4, key_type, 0).await;
826+
assert_matches!(res, Err(MlsError::KeyMissing(0)));
827+
828+
// We receive another ciphertext from leaf 2
829+
test_tree
830+
.message_key_generation(&cs, 4, key_type, 1)
831+
.await
832+
.unwrap();
833+
}
834+
811835
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)]
812836
struct Ratchet {
813837
application_keys: Vec<Vec<u8>>,

0 commit comments

Comments
 (0)