diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 097cd8de0..1958bffdf 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -1389,7 +1389,7 @@ fn check_verified_properties( ) -> Result<()> { let contact = Contact::load_from_db(context, from_id)?; - ensure!(mimeparser.encrypted, "This message is not encrypted."); + ensure!(mimeparser.was_encrypted(), "This message is not encrypted."); // ensure, the contact is verified // and the message is signed with a verified key of the sender. diff --git a/src/mimeparser.rs b/src/mimeparser.rs index aa017e645..ad157ccea 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -30,7 +30,6 @@ pub struct MimeParser<'a> { pub parts: Vec, pub header: HashMap, pub decrypting_failed: bool, - pub encrypted: bool, pub signatures: HashSet, pub gossipped_addr: HashSet, pub is_forwarded: bool, @@ -73,7 +72,8 @@ impl<'a> MimeParser<'a> { parts: Vec::new(), header: Default::default(), decrypting_failed: false, - encrypted: false, + + // only non-empty if it was a valid autocrypt message signatures: Default::default(), gossipped_addr: Default::default(), is_forwarded: false, @@ -100,7 +100,6 @@ impl<'a> MimeParser<'a> { let mail = match e2ee::try_decrypt(parser.context, &mail, message_time) { Ok((raw, signatures)) => { // Valid autocrypt message, encrypted - parser.encrypted = raw.is_some(); parser.signatures = signatures; if let Some(raw) = raw { @@ -330,6 +329,10 @@ impl<'a> MimeParser<'a> { self.parts.iter_mut().rev().find(|part| !part.is_meta) } + pub fn was_encrypted(&self) -> bool { + !self.signatures.is_empty() + } + pub(crate) fn has_chat_version(&self) -> bool { self.header.contains_key("chat-version") } @@ -450,6 +453,9 @@ impl<'a> MimeParser<'a> { } } (mime::MULTIPART, "encrypted") => { + // we currently do not try to decrypt non-autocrypt messages + // at all. If we see an encrypted part, we set + // decrypting_failed. let msg_body = self.context.stock_str(StockMessage::CantDecryptMsgBody); let txt = format!("[{}]", msg_body); @@ -636,15 +642,8 @@ impl<'a> MimeParser<'a> { } fn do_add_single_part(&mut self, mut part: Part) { - if self.encrypted { - if !self.signatures.is_empty() { - part.param.set_int(Param::GuaranteeE2ee, 1); - } else { - // XXX if the message was encrypted but not signed - // it's not neccessarily an error we need to signal. - // we could just treat it as if it was not encrypted. - part.param.set_int(Param::ErroneousE2ee, 0x2); - } + if self.was_encrypted() { + part.param.set_int(Param::GuaranteeE2ee, 1); } self.parts.push(part); } diff --git a/src/securejoin.rs b/src/securejoin.rs index b7e3c0995..ae493d4ee 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -422,7 +422,7 @@ pub(crate) fn handle_securejoin_handshake( could_not_establish_secure_connection( context, contact_chat_id, - if mimeparser.encrypted { + if mimeparser.was_encrypted() { "No valid signature." } else { "Not encrypted." @@ -717,7 +717,7 @@ fn mark_peer_as_verified(context: &Context, fingerprint: impl AsRef) -> Res ******************************************************************************/ fn encrypted_and_signed(mimeparser: &MimeParser, expected_fingerprint: impl AsRef) -> bool { - if !mimeparser.encrypted { + if !mimeparser.was_encrypted() { warn!(mimeparser.context, "Message not encrypted.",); false } else if mimeparser.signatures.is_empty() {