diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 35a985fdd..cd4ddced5 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -1117,6 +1117,53 @@ class TestOnlineAccount: assert not msg.is_encrypted() ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT") + def test_gossip_encryption_preference(self, acfactory, lp): + """Test that encryption preference of group members is gossiped to new members. + This is a Delta Chat extension to Autocrypt 1.1.0, which Autocrypt-Gossip headers + SHOULD NOT contain encryption preference. + """ + ac1, ac2, ac3 = acfactory.get_many_online_accounts(3) + + lp.sec("ac1 learns that ac2 prefers encryption") + ac1.create_chat(ac2) + msg = ac2.create_chat(ac1).send_text("first message") + msg = ac1._evtracker.wait_next_incoming_message() + assert msg.text == "first message" + assert not msg.is_encrypted() + + lp.sec("ac2 learns that ac3 prefers encryption") + ac2.create_chat(ac3) + msg = ac3.create_chat(ac2).send_text("I prefer encryption") + msg = ac2._evtracker.wait_next_incoming_message() + assert msg.text == "I prefer encryption" + assert not msg.is_encrypted() + + lp.sec("ac3 does not know that ac1 prefers encryption") + ac1.create_chat(ac3) + chat = ac3.create_chat(ac1) + msg = chat.send_text("not encrypted") + msg = ac1._evtracker.wait_next_incoming_message() + assert msg.text == "not encrypted" + assert not msg.is_encrypted() + + lp.sec("ac1 creates a group chat with ac2") + group_chat = ac1.create_group_chat("hello") + group_chat.add_contact(ac2) + msg = group_chat.send_text("hi") + + msg = ac2._evtracker.wait_next_incoming_message() + assert msg.is_encrypted() + assert msg.text == "hi" + + lp.sec("ac2 adds ac3 to the group") + msg.chat.add_contact(ac3) + assert msg.is_encrypted() + + lp.sec("ac3 learns that ac1 prefers encryption") + msg = ac3._evtracker.wait_next_incoming_message() + msg = chat.send_text("encrypted") + assert msg.is_encrypted() + def test_send_first_message_as_long_unicode_with_cr(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() ac2.set_config("save_mime_headers", "1") diff --git a/src/peerstate.rs b/src/peerstate.rs index 15e8bc046..e6bf43c79 100644 --- a/src/peerstate.rs +++ b/src/peerstate.rs @@ -120,7 +120,15 @@ impl<'a> Peerstate<'a> { addr: gossip_header.addr.clone(), last_seen: 0, last_seen_autocrypt: 0, - prefer_encrypt: Default::default(), + + // Non-standard extension. According to Autocrypt 1.1.0 gossip headers SHOULD NOT + // contain encryption preference. + // + // Delta Chat includes encryption preference to ensure new users introduced to a group + // learn encryption preferences of other members immediately and don't send unencrypted + // messages to a group where everyone prefers encryption. + prefer_encrypt: gossip_header.prefer_encrypt, + public_key: None, public_key_fingerprint: None, gossip_key: Some(gossip_header.public_key.clone()),