mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 14:56:33 +03:00
test and fix that a group with mixed-encryption members (with some we can encrypt, others not) does not break
This commit is contained in:
@@ -516,6 +516,14 @@ class TestOnlineAccount:
|
|||||||
assert msg_back.text == "message-back"
|
assert msg_back.text == "message-back"
|
||||||
assert msg_back.is_encrypted()
|
assert msg_back.is_encrypted()
|
||||||
|
|
||||||
|
lp.sec("create group chat with two members, one of which has no encrypt state")
|
||||||
|
chat = ac1.create_group_chat("encryption test")
|
||||||
|
chat.add_contact(ac1.create_contact(ac2.get_config("addr")))
|
||||||
|
chat.add_contact(ac1.create_contact("notexisting@testrun.org"))
|
||||||
|
msg = chat.send_text("test not encrypt")
|
||||||
|
ev = ac1._evlogger.get_matching("DC_EVENT_SMTP_MESSAGE_SENT")
|
||||||
|
assert not msg.is_encrypted()
|
||||||
|
|
||||||
def test_saved_mime_on_received_message(self, acfactory, lp):
|
def test_saved_mime_on_received_message(self, acfactory, lp):
|
||||||
ac1, ac2 = acfactory.get_two_online_accounts()
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
|
|
||||||
|
|||||||
23
src/chat.rs
23
src/chat.rs
@@ -299,10 +299,10 @@ impl Chat {
|
|||||||
do_guarantee_e2ee = false;
|
do_guarantee_e2ee = false;
|
||||||
e2ee_enabled = context.get_config_bool(Config::E2eeEnabled);
|
e2ee_enabled = context.get_config_bool(Config::E2eeEnabled);
|
||||||
if e2ee_enabled && msg.param.get_int(Param::ForcePlaintext).unwrap_or_default() == 0 {
|
if e2ee_enabled && msg.param.get_int(Param::ForcePlaintext).unwrap_or_default() == 0 {
|
||||||
let mut can_encrypt = 1;
|
let mut can_encrypt = true;
|
||||||
let mut all_mutual = 1;
|
let mut all_mutual = true;
|
||||||
|
|
||||||
let res = context.sql.query_row(
|
let res = context.sql.query_map(
|
||||||
"SELECT ps.prefer_encrypted, c.addr \
|
"SELECT ps.prefer_encrypted, c.addr \
|
||||||
FROM chats_contacts cc \
|
FROM chats_contacts cc \
|
||||||
LEFT JOIN contacts c ON cc.contact_id=c.id \
|
LEFT JOIN contacts c ON cc.contact_id=c.id \
|
||||||
@@ -310,29 +310,30 @@ impl Chat {
|
|||||||
WHERE cc.chat_id=? AND cc.contact_id>9;",
|
WHERE cc.chat_id=? AND cc.contact_id>9;",
|
||||||
params![self.id],
|
params![self.id],
|
||||||
|row| {
|
|row| {
|
||||||
let state: String = row.get(1)?;
|
let addr: String = row.get(1)?;
|
||||||
|
|
||||||
if let Some(prefer_encrypted) = row.get::<_, Option<i32>>(0)? {
|
if let Some(prefer_encrypted) = row.get::<_, Option<i32>>(0)? {
|
||||||
if prefer_encrypted != 1 {
|
if prefer_encrypted != 1 {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"[autocrypt] peerstate for {} is {}",
|
"[autocrypt] peerstate for {} is {}",
|
||||||
state,
|
addr,
|
||||||
if prefer_encrypted == 0 {
|
if prefer_encrypted == 0 {
|
||||||
"NOPREFERENCE"
|
"NOPREFERENCE"
|
||||||
} else {
|
} else {
|
||||||
"RESET"
|
"RESET"
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
all_mutual = 0;
|
all_mutual = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!(context, "[autocrypt] no peerstate for {}", state,);
|
info!(context, "[autocrypt] no peerstate for {}", addr,);
|
||||||
can_encrypt = 0;
|
can_encrypt = false;
|
||||||
all_mutual = 0;
|
all_mutual = false;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
|rows| rows.collect::<Result<Vec<_>, _>>().map_err(Into::into),
|
||||||
);
|
);
|
||||||
match res {
|
match res {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
@@ -341,8 +342,8 @@ impl Chat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if 0 != can_encrypt {
|
if can_encrypt {
|
||||||
if 0 != all_mutual {
|
if all_mutual {
|
||||||
do_guarantee_e2ee = true;
|
do_guarantee_e2ee = true;
|
||||||
} else if last_msg_in_chat_encrypted(context, &context.sql, self.id) {
|
} else if last_msg_in_chat_encrypted(context, &context.sql, self.id) {
|
||||||
do_guarantee_e2ee = true;
|
do_guarantee_e2ee = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user