core_crypto/mls/conversation/
orphan_welcome.rs

1//! This deals with DS inconsistencies. When a Welcome message is received, the client might have
2//! already deleted its associated KeyPackage (and encryption key).
3//! Feel free to remove this when this is no longer a problem !!!
4
5#[cfg(test)]
6mod tests {
7
8    use openmls::prelude::KeyPackage;
9    use openmls_traits::OpenMlsCryptoProvider;
10    use wasm_bindgen_test::*;
11
12    use super::super::error::Error;
13    use crate::test_utils::*;
14
15    wasm_bindgen_test_configure!(run_in_browser);
16
17    #[apply(all_cred_cipher)]
18    #[wasm_bindgen_test]
19    pub async fn orphan_welcome_should_generate_external_commit(case: TestContext) {
20        let [alice, bob] = case.sessions().await;
21        Box::pin(async move {
22            let conversation = case.create_conversation([&alice]).await;
23
24                let bob_kp = bob.rand_key_package(&case).await;
25                let bob_kp_ref = KeyPackage::from(bob_kp.clone())
26                    .hash_ref(bob.transaction.mls_provider().await.unwrap().crypto())
27                    .unwrap();
28
29                // Alice invites Bob with a KeyPackage...
30                conversation.guard().await
31                    .add_members(vec![bob_kp])
32                    .await
33                    .unwrap();
34
35                // ...Bob deletes locally (with the associated private key) before processing the Welcome
36                bob.transaction.delete_keypackages(&[bob_kp_ref]).await.unwrap();
37
38                let welcome = alice.mls_transport().await.latest_welcome_message().await;
39
40                // in that case a dedicated error is thrown for clients to identify this case
41                // and rejoin with an external commit
42                let process_welcome = bob
43                    .transaction
44                    .process_welcome_message(welcome.into(), case.custom_cfg())
45                    .await;
46                assert!(matches!(
47                    process_welcome.unwrap_err(),
48                    crate::transaction_context::Error::Recursive(crate::RecursiveError::MlsConversation { source, .. }) if matches!(*source, Error::OrphanWelcome)
49                ));
50            })
51        .await;
52    }
53}