-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ignore encryption preferences #6612
Open
link2xt
wants to merge
2
commits into
main
Choose a base branch
from
link2xt/ignore-encryption-preferences
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−317
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FTR, the important semantic change is in this file here, everything else is just tests |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if encryption preference is still sent in the Autocrypt header, can't this lead to other Autocrypt-capable MUA or old Delta Chat sending messages unencrypted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that it's enabled anyway, so, no need to enable it again?