1
1
//! Internet Message Format reception pipeline.
2
2
3
- use std:: collections:: { HashMap , HashSet } ;
3
+ use std:: collections:: { BTreeMap , HashSet } ;
4
4
use std:: iter;
5
5
use std:: sync:: LazyLock ;
6
6
@@ -28,14 +28,14 @@ use crate::events::EventType;
28
28
use crate :: headerdef:: { HeaderDef , HeaderDefMap } ;
29
29
use crate :: imap:: { GENERATED_PREFIX , markseen_on_imap_table} ;
30
30
use crate :: key:: self_fingerprint_opt;
31
- use crate :: key:: { DcKey , Fingerprint , SignedPublicKey } ;
31
+ use crate :: key:: { DcKey , Fingerprint } ;
32
32
use crate :: log:: LogExt ;
33
33
use crate :: log:: { info, warn} ;
34
34
use crate :: logged_debug_assert;
35
35
use crate :: message:: {
36
36
self , Message , MessageState , MessengerMessage , MsgId , Viewtype , rfc724_mid_exists,
37
37
} ;
38
- use crate :: mimeparser:: { AvatarAction , MimeMessage , SystemMessage , parse_message_ids} ;
38
+ use crate :: mimeparser:: { AvatarAction , GossipedKey , MimeMessage , SystemMessage , parse_message_ids} ;
39
39
use crate :: param:: { Param , Params } ;
40
40
use crate :: peer_channels:: { add_gossip_peer_from_header, insert_topic_stub} ;
41
41
use crate :: reaction:: { Reaction , set_msg_reaction} ;
@@ -835,7 +835,7 @@ pub(crate) async fn receive_imf_inner(
835
835
context
836
836
. sql
837
837
. transaction ( move |transaction| {
838
- let fingerprint = gossiped_key. dc_fingerprint ( ) . hex ( ) ;
838
+ let fingerprint = gossiped_key. public_key . dc_fingerprint ( ) . hex ( ) ;
839
839
transaction. execute (
840
840
"INSERT INTO gossip_timestamp (chat_id, fingerprint, timestamp)
841
841
VALUES (?, ?, ?)
@@ -2917,7 +2917,7 @@ async fn apply_group_changes(
2917
2917
// highest `add_timestamp` to disambiguate.
2918
2918
// The result of the error is that info message
2919
2919
// may contain display name of the wrong contact.
2920
- let fingerprint = key. dc_fingerprint ( ) . hex ( ) ;
2920
+ let fingerprint = key. public_key . dc_fingerprint ( ) . hex ( ) ;
2921
2921
if let Some ( contact_id) =
2922
2922
lookup_key_contact_by_fingerprint ( context, & fingerprint) . await ?
2923
2923
{
@@ -3659,10 +3659,28 @@ async fn mark_recipients_as_verified(
3659
3659
to_ids : & [ Option < ContactId > ] ,
3660
3660
mimeparser : & MimeMessage ,
3661
3661
) -> Result < ( ) > {
3662
+ let verifier_id = Some ( from_id) . filter ( |& id| id != ContactId :: SELF ) ;
3663
+ for gossiped_key in mimeparser
3664
+ . gossiped_keys
3665
+ . values ( )
3666
+ . filter ( |gossiped_key| gossiped_key. verified )
3667
+ {
3668
+ let fingerprint = gossiped_key. public_key . dc_fingerprint ( ) . hex ( ) ;
3669
+ let Some ( to_id) = lookup_key_contact_by_fingerprint ( context, & fingerprint) . await ? else {
3670
+ continue ;
3671
+ } ;
3672
+
3673
+ if to_id == ContactId :: SELF || to_id == from_id {
3674
+ continue ;
3675
+ }
3676
+
3677
+ mark_contact_id_as_verified ( context, to_id, verifier_id) . await ?;
3678
+ ChatId :: set_protection_for_contact ( context, to_id, mimeparser. timestamp_sent ) . await ?;
3679
+ }
3680
+
3662
3681
if mimeparser. get_header ( HeaderDef :: ChatVerified ) . is_none ( ) {
3663
3682
return Ok ( ( ) ) ;
3664
3683
}
3665
- let verifier_id = Some ( from_id) . filter ( |& id| id != ContactId :: SELF ) ;
3666
3684
for to_id in to_ids. iter ( ) . filter_map ( |& x| x) {
3667
3685
if to_id == ContactId :: SELF || to_id == from_id {
3668
3686
continue ;
@@ -3755,7 +3773,7 @@ async fn add_or_lookup_contacts_by_address_list(
3755
3773
async fn add_or_lookup_key_contacts (
3756
3774
context : & Context ,
3757
3775
address_list : & [ SingleInfo ] ,
3758
- gossiped_keys : & HashMap < String , SignedPublicKey > ,
3776
+ gossiped_keys : & BTreeMap < String , GossipedKey > ,
3759
3777
fingerprints : & [ Fingerprint ] ,
3760
3778
origin : Origin ,
3761
3779
) -> Result < Vec < Option < ContactId > > > {
@@ -3771,7 +3789,7 @@ async fn add_or_lookup_key_contacts(
3771
3789
// Iterator has not ran out of fingerprints yet.
3772
3790
fp. hex ( )
3773
3791
} else if let Some ( key) = gossiped_keys. get ( addr) {
3774
- key. dc_fingerprint ( ) . hex ( )
3792
+ key. public_key . dc_fingerprint ( ) . hex ( )
3775
3793
} else if context. is_self_addr ( addr) . await ? {
3776
3794
contact_ids. push ( Some ( ContactId :: SELF ) ) ;
3777
3795
continue ;
0 commit comments