Merge pull request #2001 from deltachat/protect-one-to-one

check protection properties for all chats, allow missing Chat-Verified header
This commit is contained in:
bjoern
2020-10-16 23:02:41 +02:00
committed by GitHub

View File

@@ -714,7 +714,18 @@ async fn add_parts(
ephemeral_timer = EphemeralTimer::Disabled; ephemeral_timer = EphemeralTimer::Disabled;
} }
// change chat protection // if a chat is protected, check additional properties
if !chat_id.is_special() {
let chat = Chat::load_from_db(context, *chat_id).await?;
if chat.is_protected() {
if let Err(err) =
check_verified_properties(context, mime_parser, from_id as u32, to_ids).await
{
warn!(context, "verification problem: {}", err);
let s = format!("{}. See 'Info' for more details", err);
mime_parser.repl_msg_by_error(s);
} else {
// change chat protection only when verification check passes
if let Some(new_status) = match mime_parser.is_system_message { if let Some(new_status) = match mime_parser.is_system_message {
SystemMessage::ChatProtectionEnabled => Some(ProtectionStatus::Protected), SystemMessage::ChatProtectionEnabled => Some(ProtectionStatus::Protected),
SystemMessage::ChatProtectionDisabled => Some(ProtectionStatus::Unprotected), SystemMessage::ChatProtectionDisabled => Some(ProtectionStatus::Unprotected),
@@ -726,6 +737,9 @@ async fn add_parts(
context.stock_protection_msg(new_status, from_id).await, context.stock_protection_msg(new_status, from_id).await,
); );
} }
}
}
}
// correct message_timestamp, it should not be used before, // correct message_timestamp, it should not be used before,
// however, we cannot do this earlier as we need from_id to be set // however, we cannot do this earlier as we need from_id to be set
@@ -1167,20 +1181,10 @@ async fn create_or_lookup_group(
set_better_msg(mime_parser, &better_msg); set_better_msg(mime_parser, &better_msg);
// check, if we have a chat with this group ID // check, if we have a chat with this group ID
let (mut chat_id, chat_id_verified, _blocked) = chat::get_chat_id_by_grpid(context, &grpid) let (mut chat_id, _, _blocked) = chat::get_chat_id_by_grpid(context, &grpid)
.await .await
.unwrap_or((ChatId::new(0), false, Blocked::Not)); .unwrap_or((ChatId::new(0), false, Blocked::Not));
if !chat_id.is_unset() { if !chat_id.is_unset() && !chat::is_contact_in_chat(context, chat_id, from_id as u32).await {
if chat_id_verified {
if let Err(err) =
check_verified_properties(context, mime_parser, from_id as u32, to_ids).await
{
warn!(context, "verification problem: {}", err);
let s = format!("{}. See 'Info' for more details", err);
mime_parser.repl_msg_by_error(s);
}
}
if !chat::is_contact_in_chat(context, chat_id, from_id as u32).await {
// The From-address is not part of this group. // The From-address is not part of this group.
// It could be a new user or a DSN from a mailer-daemon. // It could be a new user or a DSN from a mailer-daemon.
// in any case we do not want to recreate the member list // in any case we do not want to recreate the member list
@@ -1190,7 +1194,6 @@ async fn create_or_lookup_group(
let s = context.stock_str(StockMessage::UnknownSenderForChat).await; let s = context.stock_str(StockMessage::UnknownSenderForChat).await;
mime_parser.repl_msg_by_error(s.to_string()); mime_parser.repl_msg_by_error(s.to_string());
} }
}
// check if the group does not exist but should be created // check if the group does not exist but should be created
let group_explicitly_left = chat::is_group_explicitly_left(context, &grpid) let group_explicitly_left = chat::is_group_explicitly_left(context, &grpid)
@@ -1299,11 +1302,6 @@ async fn create_or_lookup_group(
} }
} else if mime_parser.is_system_message == SystemMessage::ChatProtectionEnabled { } else if mime_parser.is_system_message == SystemMessage::ChatProtectionEnabled {
recreate_member_list = true; recreate_member_list = true;
if let Err(e) = check_verified_properties(context, mime_parser, from_id, to_ids).await {
warn!(context, "checking verified properties failed: {}", e);
let s = format!("{}. See 'Info' for more details", e);
mime_parser.repl_msg_by_error(s);
}
} }
if let Some(avatar_action) = &mime_parser.group_avatar { if let Some(avatar_action) = &mime_parser.group_avatar {
@@ -1669,10 +1667,16 @@ async fn check_verified_properties(
ensure!(mimeparser.was_encrypted(), "This message is not encrypted."); ensure!(mimeparser.was_encrypted(), "This message is not encrypted.");
ensure!( if mimeparser.get(HeaderDef::ChatVerified).is_none() {
mimeparser.get(HeaderDef::ChatVerified).is_some(), // we do not fail here currently, this would exclude (a) non-deltas
"Sender did not mark the message as protected." // and (b) deltas with different protection views across multiple devices.
// for group creation or protection enabled/disabled, however, Chat-Verified is respected.
warn!(
context,
"{} did not mark message as protected.",
contact.get_addr()
); );
}
// ensure, the contact is verified // ensure, the contact is verified
// and the message is signed with a verified key of the sender. // and the message is signed with a verified key of the sender.