|
| 1 | +use std::{ |
| 2 | + thread, |
| 3 | + time::{Duration, SystemTime, UNIX_EPOCH}, |
| 4 | +}; |
| 5 | + |
| 6 | +use openmls::{prelude::*, test_utils::single_group_test_framework::*}; |
| 7 | +use openmls_test::openmls_test; |
| 8 | + |
| 9 | +#[openmls_test] |
| 10 | +fn join_tree_with_outdated_leafnodes() { |
| 11 | + // The validity of the key package into the future. |
| 12 | + // This has to be short to keep the test run fast, but not too short to produce |
| 13 | + // failing tests. |
| 14 | + const VALIDITY: u64 = 2; |
| 15 | + |
| 16 | + let alice_party = CorePartyState::<Provider>::new("alice"); |
| 17 | + let bob_party = CorePartyState::<Provider>::new("bob"); |
| 18 | + let charlie_party = CorePartyState::<Provider>::new("charlie"); |
| 19 | + |
| 20 | + // Create group |
| 21 | + let create_config = MlsGroupCreateConfig::test_default_from_ciphersuite(ciphersuite); |
| 22 | + let join_config = create_config.join_config().clone(); |
| 23 | + let mut group_state = { |
| 24 | + let group_id = GroupId::from_slice(b"Test Group"); |
| 25 | + |
| 26 | + let group_state = GroupState::new_from_party( |
| 27 | + group_id, |
| 28 | + alice_party.generate_pre_group(ciphersuite), |
| 29 | + create_config, |
| 30 | + ) |
| 31 | + .unwrap(); |
| 32 | + group_state |
| 33 | + }; |
| 34 | + |
| 35 | + // Create Charlie key package |
| 36 | + let charlie_pre_group = charlie_party.generate_pre_group(ciphersuite); |
| 37 | + let charlie_key_package = charlie_pre_group.key_package_bundle.key_package().clone(); |
| 38 | + |
| 39 | + // Generate a key package for Bob that is outdated when inviting Charlie. |
| 40 | + // This test assumes that the setup goes through within VALIDITY seconds. |
| 41 | + // After that the key package is invalid already. |
| 42 | + let now = SystemTime::now() |
| 43 | + .duration_since(UNIX_EPOCH) |
| 44 | + .expect("SystemTime before UNIX EPOCH!") |
| 45 | + .as_secs(); |
| 46 | + let bob_pre_group = bob_party |
| 47 | + .generate_pre_group_lifetime(ciphersuite, Lifetime::init(now - 60, now + VALIDITY)); |
| 48 | + let bob_key_package = bob_pre_group.key_package_bundle.key_package().clone(); |
| 49 | + |
| 50 | + let [alice] = group_state.members_mut(&["alice"]); |
| 51 | + |
| 52 | + // Alice adds Bob |
| 53 | + let (_mls_message_out, _welcome, _group_info) = alice |
| 54 | + .group |
| 55 | + .add_members( |
| 56 | + &alice_party.provider, |
| 57 | + &alice.party.signer, |
| 58 | + &[bob_key_package], |
| 59 | + ) |
| 60 | + .expect("Could not add Bob."); |
| 61 | + |
| 62 | + alice |
| 63 | + .group |
| 64 | + .merge_pending_commit(&alice_party.provider) |
| 65 | + .unwrap(); |
| 66 | + |
| 67 | + // We don't care about Bob actually processing the Welcome. |
| 68 | + // Let's wait for VALIDITY seconds to ensure that the leaf node is invalid. |
| 69 | + thread::sleep(Duration::from_secs(VALIDITY)); |
| 70 | + |
| 71 | + // Alice adds Charlie |
| 72 | + // At this point Bob's key package is outdated in the tree. |
| 73 | + let (_mls_message_out, welcome, _group_info) = alice |
| 74 | + .group |
| 75 | + .add_members( |
| 76 | + &alice_party.provider, |
| 77 | + &alice.party.signer, |
| 78 | + &[charlie_key_package], |
| 79 | + ) |
| 80 | + .expect("Could not add Charlie."); |
| 81 | + |
| 82 | + alice |
| 83 | + .group |
| 84 | + .merge_pending_commit(&alice_party.provider) |
| 85 | + .unwrap(); |
| 86 | + |
| 87 | + // Charlie tries to join the group |
| 88 | + let _charlie_group = StagedWelcome::new_from_welcome( |
| 89 | + &charlie_party.provider, |
| 90 | + &join_config, |
| 91 | + MlsMessageIn::from(welcome).into_welcome().unwrap(), |
| 92 | + None, |
| 93 | + ) |
| 94 | + .expect("Failed to create group due to an invalid lifetime in a leaf node in the tree.") |
| 95 | + .into_group(provider) |
| 96 | + .unwrap(); |
| 97 | +} |
0 commit comments