Skip to content

Commit

Permalink
fix: add "setup changed" message for verified key before the message
Browse files Browse the repository at this point in the history
Merge the code paths for verified and autocrypt key.
If both are changed, only one will be added.

Existing code path adds a message to all chats with the contact
rather than to 1:1 chat. If we later decide that
only 1:1 chat or only verified chats should be notified,
we can add a separate `verified_fingerprint_changed` flag.
  • Loading branch information
link2xt committed Nov 13, 2023
1 parent e900d50 commit 585a481
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ pub(crate) async fn receive_imf_inner(
.and_then(|value| mailparse::dateparse(value).ok())
.map_or(rcvd_timestamp, |value| min(value, rcvd_timestamp + 60));

let updated_verified_key_addr =
update_verified_keys(context, &mut mime_parser, from_id).await?;
update_verified_keys(context, &mut mime_parser, from_id).await?;

// Add parts
let received_msg = add_parts(
Expand Down Expand Up @@ -281,11 +280,6 @@ pub(crate) async fn receive_imf_inner(
MsgId::new_unset()
};

if let Some(addr) = updated_verified_key_addr {
let msg = stock_str::contact_setup_changed(context, &addr).await;
chat::add_info_msg(context, chat_id, &msg, received_msg.sort_timestamp).await?;
}

save_locations(context, &mime_parser, chat_id, from_id, insert_msg_id).await?;

if let Some(ref sync_items) = mime_parser.sync_items {
Expand Down Expand Up @@ -2288,13 +2282,10 @@ enum VerifiedEncryption {
/// Moves secondary verified key to primary verified key
/// if the message is signed with a secondary verified key.
/// Removes secondary verified key if the message is signed with primary key.
///
/// Returns address of the peerstate if the primary verified key was updated,
/// the caller then needs to add "Setup changed" notification somewhere.
async fn update_verified_keys(
context: &Context,
mimeparser: &mut MimeMessage,
from_id: ContactId,
from_id: ContactId
) -> Result<Option<String>> {
if from_id == ContactId::SELF {
return Ok(None);
Expand Down Expand Up @@ -2338,10 +2329,11 @@ async fn update_verified_keys(
peerstate.verified_key = peerstate.secondary_verified_key.take();
peerstate.verified_key_fingerprint = peerstate.secondary_verified_key_fingerprint.take();
peerstate.verifier = peerstate.secondary_verifier.take();
peerstate.fingerprint_changed = true;
peerstate.save_to_db(&context.sql).await?;

// Primary verified key changed.
Ok(Some(peerstate.addr.clone()))
Ok(None)
} else {
Ok(None)
}
Expand Down

0 comments on commit 585a481

Please sign in to comment.