11//! Internet Message Format reception pipeline.
22
3- use std:: collections:: { HashMap , HashSet } ;
3+ use std:: collections:: { BTreeMap , HashSet } ;
44use std:: iter;
55use std:: sync:: LazyLock ;
66
@@ -28,14 +28,14 @@ use crate::events::EventType;
2828use crate :: headerdef:: { HeaderDef , HeaderDefMap } ;
2929use crate :: imap:: { GENERATED_PREFIX , markseen_on_imap_table} ;
3030use crate :: key:: self_fingerprint_opt;
31- use crate :: key:: { DcKey , Fingerprint , SignedPublicKey } ;
31+ use crate :: key:: { DcKey , Fingerprint } ;
3232use crate :: log:: LogExt ;
3333use crate :: log:: { info, warn} ;
3434use crate :: logged_debug_assert;
3535use crate :: message:: {
3636 self , Message , MessageState , MessengerMessage , MsgId , Viewtype , rfc724_mid_exists,
3737} ;
38- use crate :: mimeparser:: { AvatarAction , MimeMessage , SystemMessage , parse_message_ids} ;
38+ use crate :: mimeparser:: { AvatarAction , GossipedKey , MimeMessage , SystemMessage , parse_message_ids} ;
3939use crate :: param:: { Param , Params } ;
4040use crate :: peer_channels:: { add_gossip_peer_from_header, insert_topic_stub} ;
4141use crate :: reaction:: { Reaction , set_msg_reaction} ;
@@ -743,7 +743,7 @@ pub(crate) async fn receive_imf_inner(
743743 let verified_encryption = has_verified_encryption ( context, & mime_parser, from_id) . await ?;
744744
745745 if verified_encryption == VerifiedEncryption :: Verified {
746- mark_recipients_as_verified ( context, from_id, & to_ids , & mime_parser) . await ?;
746+ mark_recipients_as_verified ( context, from_id, & mime_parser) . await ?;
747747 }
748748
749749 let received_msg = if let Some ( received_msg) = received_msg {
@@ -836,7 +836,7 @@ pub(crate) async fn receive_imf_inner(
836836 context
837837 . sql
838838 . transaction ( move |transaction| {
839- let fingerprint = gossiped_key. dc_fingerprint ( ) . hex ( ) ;
839+ let fingerprint = gossiped_key. public_key . dc_fingerprint ( ) . hex ( ) ;
840840 transaction. execute (
841841 "INSERT INTO gossip_timestamp (chat_id, fingerprint, timestamp)
842842 VALUES (?, ?, ?)
@@ -2923,7 +2923,7 @@ async fn apply_group_changes(
29232923 // highest `add_timestamp` to disambiguate.
29242924 // The result of the error is that info message
29252925 // may contain display name of the wrong contact.
2926- let fingerprint = key. dc_fingerprint ( ) . hex ( ) ;
2926+ let fingerprint = key. public_key . dc_fingerprint ( ) . hex ( ) ;
29272927 if let Some ( contact_id) =
29282928 lookup_key_contact_by_fingerprint ( context, & fingerprint) . await ?
29292929 {
@@ -3662,18 +3662,32 @@ async fn has_verified_encryption(
36623662async fn mark_recipients_as_verified (
36633663 context : & Context ,
36643664 from_id : ContactId ,
3665- to_ids : & [ Option < ContactId > ] ,
36663665 mimeparser : & MimeMessage ,
36673666) -> Result < ( ) > {
3668- if mimeparser. get_header ( HeaderDef :: ChatVerified ) . is_none ( ) {
3669- return Ok ( ( ) ) ;
3670- }
3671- for to_id in to_ids. iter ( ) . filter_map ( |& x| x) {
3667+ for gossiped_key in mimeparser
3668+ . gossiped_keys
3669+ . values ( )
3670+ . filter ( |gossiped_key| gossiped_key. is_verified )
3671+ {
3672+ let fingerprint = gossiped_key. public_key . dc_fingerprint ( ) . hex ( ) ;
3673+ let Some ( to_id) = lookup_key_contact_by_fingerprint ( context, & fingerprint) . await ? else {
3674+ continue ;
3675+ } ;
3676+
36723677 if to_id == ContactId :: SELF || to_id == from_id {
36733678 continue ;
36743679 }
36753680
3676- mark_contact_id_as_verified ( context, to_id, from_id) . await ?;
3681+ if from_id == ContactId :: SELF {
3682+ // Mark the contact as verified.
3683+ // We don't know however if the contact was directly verified
3684+ // as we did not observe SecureJoin, so mark as verified by unknown contact.
3685+ // `verifier` equal to contact ID itself means that the contact
3686+ // is verified, but it is not known by whom.
3687+ context. sql . execute ( "UPDATE contacts SET verifier=?1 WHERE id=?1" , ( to_id, ) ) . await ?;
3688+ } else {
3689+ mark_contact_id_as_verified ( context, to_id, from_id) . await ?;
3690+ }
36773691 ChatId :: set_protection_for_contact ( context, to_id, mimeparser. timestamp_sent ) . await ?;
36783692 }
36793693
@@ -3760,7 +3774,7 @@ async fn add_or_lookup_contacts_by_address_list(
37603774async fn add_or_lookup_key_contacts (
37613775 context : & Context ,
37623776 address_list : & [ SingleInfo ] ,
3763- gossiped_keys : & HashMap < String , SignedPublicKey > ,
3777+ gossiped_keys : & BTreeMap < String , GossipedKey > ,
37643778 fingerprints : & [ Fingerprint ] ,
37653779 origin : Origin ,
37663780) -> Result < Vec < Option < ContactId > > > {
@@ -3776,7 +3790,7 @@ async fn add_or_lookup_key_contacts(
37763790 // Iterator has not ran out of fingerprints yet.
37773791 fp. hex ( )
37783792 } else if let Some ( key) = gossiped_keys. get ( addr) {
3779- key. dc_fingerprint ( ) . hex ( )
3793+ key. public_key . dc_fingerprint ( ) . hex ( )
37803794 } else if context. is_self_addr ( addr) . await ? {
37813795 contact_ids. push ( Some ( ContactId :: SELF ) ) ;
37823796 continue ;
0 commit comments