-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Encryption preference is sent in Autocrypt header, but otherwise ignored. Delta Chat always prefers encryption if it is available.
- Loading branch information
Showing
8 changed files
with
32 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,10 +299,6 @@ async fn test_member_add_remove() -> Result<()> { | |
let alice = tcm.alice().await; | ||
let bob = tcm.bob().await; | ||
|
||
// Disable encryption so we can inspect raw message contents. | ||
alice.set_config(Config::E2eeEnabled, Some("0")).await?; | ||
bob.set_config(Config::E2eeEnabled, Some("0")).await?; | ||
|
||
// Create contact for Bob on the Alice side with name "robert". | ||
let alice_bob_contact_id = Contact::create(&alice, "robert", "[email protected]").await?; | ||
|
||
|
@@ -373,9 +369,6 @@ async fn test_parallel_member_remove() -> Result<()> { | |
let alice = tcm.alice().await; | ||
let bob = tcm.bob().await; | ||
|
||
alice.set_config(Config::E2eeEnabled, Some("0")).await?; | ||
bob.set_config(Config::E2eeEnabled, Some("0")).await?; | ||
|
||
let alice_bob_contact_id = Contact::create(&alice, "Bob", "[email protected]").await?; | ||
let alice_fiona_contact_id = Contact::create(&alice, "Fiona", "[email protected]").await?; | ||
let alice_claire_contact_id = Contact::create(&alice, "Claire", "[email protected]").await?; | ||
|
@@ -2677,11 +2670,10 @@ async fn test_chat_get_encryption_info() -> Result<()> { | |
"No encryption:\n\ | ||
[email protected]\n\ | ||
\n\ | ||
End-to-end encryption preferred:\n\ | ||
End-to-end encryption available:\n\ | ||
[email protected]" | ||
); | ||
|
||
bob.set_config(Config::E2eeEnabled, Some("0")).await?; | ||
send_text_msg(&bob, direct_chat.id, "Hello!".to_string()).await?; | ||
alice.recv_msg(&bob.pop_sent_msg().await).await; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,22 +54,13 @@ impl EncryptHelper { | |
peerstates: &[(Option<Peerstate>, String)], | ||
) -> Result<bool> { | ||
let is_chatmail = context.is_chatmail().await?; | ||
let mut prefer_encrypt_count = if self.prefer_encrypt == EncryptPreference::Mutual { | ||
1 | ||
} else { | ||
0 | ||
}; | ||
let mut prefer_encrypt_count = 1; | ||
for (peerstate, addr) in peerstates { | ||
match peerstate { | ||
Some(peerstate) => { | ||
let prefer_encrypt = peerstate.prefer_encrypt; | ||
info!(context, "Peerstate for {addr:?} is {prefer_encrypt}."); | ||
if match peerstate.prefer_encrypt { | ||
EncryptPreference::NoPreference | EncryptPreference::Reset => { | ||
(peerstate.prefer_encrypt != EncryptPreference::Reset || is_chatmail) | ||
&& self.prefer_encrypt == EncryptPreference::Mutual | ||
} | ||
EncryptPreference::Mutual => true, | ||
EncryptPreference::Reset => is_chatmail, | ||
EncryptPreference::NoPreference | EncryptPreference::Mutual => true, | ||
} { | ||
prefer_encrypt_count += 1; | ||
} | ||
|
@@ -176,6 +167,7 @@ pub async fn ensure_secret_key_exists(context: &Context) -> Result<()> { | |
mod tests { | ||
use super::*; | ||
use crate::chat::send_text_msg; | ||
use crate::config::Config; | ||
use crate::key::DcKey; | ||
use crate::message::{Message, Viewtype}; | ||
use crate::param::Param; | ||
|
@@ -329,7 +321,6 @@ Sent with my Delta Chat Messenger: https://delta.chat"; | |
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_should_encrypt() -> Result<()> { | ||
let t = TestContext::new_alice().await; | ||
assert!(t.get_config_bool(Config::E2eeEnabled).await?); | ||
let encrypt_helper = EncryptHelper::new(&t).await.unwrap(); | ||
|
||
let ps = new_peerstates(EncryptPreference::NoPreference); | ||
|
@@ -352,61 +343,6 @@ Sent with my Delta Chat Messenger: https://delta.chat"; | |
Ok(()) | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_should_encrypt_e2ee_disabled() -> Result<()> { | ||
let t = &TestContext::new_alice().await; | ||
t.set_config_bool(Config::E2eeEnabled, false).await?; | ||
let encrypt_helper = EncryptHelper::new(t).await.unwrap(); | ||
|
||
let ps = new_peerstates(EncryptPreference::NoPreference); | ||
assert!(!encrypt_helper.should_encrypt(t, false, &ps).await?); | ||
|
||
let ps = new_peerstates(EncryptPreference::Reset); | ||
assert!(encrypt_helper.should_encrypt(t, true, &ps).await?); | ||
|
||
let mut ps = new_peerstates(EncryptPreference::Mutual); | ||
// Own preference is `NoPreference` and there's no majority with `Mutual`. | ||
assert!(!encrypt_helper.should_encrypt(t, false, &ps).await?); | ||
// Now the majority wants to encrypt. Let's encrypt, anyway there are other cases when we | ||
// can't send unencrypted, e.g. protected groups. | ||
ps.push(ps[0].clone()); | ||
assert!(encrypt_helper.should_encrypt(t, false, &ps).await?); | ||
|
||
// Test with missing peerstate. | ||
let ps = vec![(None, "[email protected]".to_string())]; | ||
assert!(encrypt_helper.should_encrypt(t, true, &ps).await.is_err()); | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_chatmail_prefers_to_encrypt() -> Result<()> { | ||
let mut tcm = TestContextManager::new(); | ||
let alice = &tcm.alice().await; | ||
let bob = &tcm.bob().await; | ||
bob.set_config_bool(Config::IsChatmail, true).await?; | ||
|
||
let bob_chat_id = tcm | ||
.send_recv_accept(alice, bob, "Hello from DC") | ||
.await | ||
.chat_id; | ||
receive_imf( | ||
bob, | ||
b"From: [email protected]\n\ | ||
To: [email protected]\n\ | ||
Message-ID: <[email protected]>\n\ | ||
Date: Sun, 22 Mar 3000 22:37:58 +0000\n\ | ||
\n\ | ||
Hello from another MUA\n", | ||
false, | ||
) | ||
.await?; | ||
send_text_msg(bob, bob_chat_id, "hi".to_string()).await?; | ||
let sent_msg = bob.pop_sent_msg().await; | ||
let msg = Message::load_from_db(bob, sent_msg.sender_msg_id).await?; | ||
assert!(msg.get_showpadlock()); | ||
Ok(()) | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_chatmail_can_send_unencrypted() -> Result<()> { | ||
let mut tcm = TestContextManager::new(); | ||
|
Oops, something went wrong.