Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/mimeparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ pub(crate) struct MimeMessage {
pub chat_disposition_notification_to: Option<SingleInfo>,
pub decrypting_failed: bool,

/// Set of valid signature fingerprints if a message is an
/// Valid signature fingerprint if a message is an
/// Autocrypt encrypted and signed message.
///
/// If a message is not encrypted or the signature is not valid,
/// this set is empty.
pub signatures: HashSet<Fingerprint>,
/// this is `None`.
pub signature: Option<Fingerprint>,

/// The addresses for which there was a gossip header
/// and their respective gossiped keys.
Expand Down Expand Up @@ -571,7 +571,7 @@ impl MimeMessage {
decrypting_failed: mail.is_err(),

// only non-empty if it was a valid autocrypt message
signatures,
signature: signatures.into_iter().next(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we must take the innermost signature because in merge_headers() we prefer protected headers from the inner part (we drop outer protected headers at all).

autocrypt_fingerprint,
gossiped_keys,
is_forwarded: false,
Expand Down Expand Up @@ -936,7 +936,7 @@ impl MimeMessage {
/// This means the message was both encrypted and signed with a
/// valid signature.
pub fn was_encrypted(&self) -> bool {
!self.signatures.is_empty()
self.signature.is_some()
}

/// Returns whether the email contains a `chat-version` header.
Expand Down
7 changes: 5 additions & 2 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ pub(crate) async fn receive_imf_inner(
// For example, GitHub sends messages from `[email protected]`,
// but uses display name of the user whose action generated the notification
// as the display name.
let fingerprint = mime_parser.signatures.iter().next();
let fingerprint = mime_parser.signature.as_ref();
let (from_id, _from_id_blocked, incoming_origin) = match from_field_to_contact_id(
context,
&mime_parser.from,
Expand Down Expand Up @@ -3649,7 +3649,10 @@ async fn has_verified_encryption(
));
}

let signed_with_verified_key = mimeparser.signatures.contains(&fingerprint);
let signed_with_verified_key = mimeparser
.signature
.as_ref()
.is_some_and(|signature| *signature == fingerprint);
if signed_with_verified_key {
Ok(Verified)
} else {
Expand Down
20 changes: 11 additions & 9 deletions src/securejoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,17 +604,19 @@ fn encrypted_and_signed(
mimeparser: &MimeMessage,
expected_fingerprint: &Fingerprint,
) -> bool {
if !mimeparser.was_encrypted() {
if let Some(signature) = mimeparser.signature.as_ref() {
if signature == expected_fingerprint {
true
} else {
warn!(
context,
"Message does not match expected fingerprint {expected_fingerprint}.",
);
false
}
} else {
warn!(context, "Message not encrypted.",);
false
} else if !mimeparser.signatures.contains(expected_fingerprint) {
warn!(
context,
"Message does not match expected fingerprint {}.", expected_fingerprint,
);
false
} else {
true
}
}

Expand Down
Loading