@@ -23,6 +23,7 @@ use crate::qr::check_qr;
23
23
use crate :: securejoin:: bob:: JoinerProgress ;
24
24
use crate :: sync:: Sync :: * ;
25
25
use crate :: token;
26
+ use crate :: tools:: time;
26
27
27
28
mod bob;
28
29
mod qrinvite;
@@ -364,7 +365,19 @@ pub(crate) async fn handle_securejoin_handshake(
364
365
) ;
365
366
return Ok ( HandshakeMessage :: Ignore ) ;
366
367
} ;
367
- let Some ( grpid) = token:: auth_foreign_key ( context, auth) . await ? else {
368
+ let Some ( ( grpid, timestamp) ) = context
369
+ . sql
370
+ . query_row_optional (
371
+ "SELECT foreign_key, timestamp FROM tokens WHERE namespc=? AND token=?" ,
372
+ ( Namespace :: Auth , auth) ,
373
+ |row| {
374
+ let foreign_key: String = row. get ( 0 ) ?;
375
+ let timestamp: i64 = row. get ( 1 ) ?;
376
+ Ok ( ( foreign_key, timestamp) )
377
+ } ,
378
+ )
379
+ . await ?
380
+ else {
368
381
warn ! (
369
382
context,
370
383
"Ignoring {step} message because of invalid auth code."
@@ -382,14 +395,23 @@ pub(crate) async fn handle_securejoin_handshake(
382
395
}
383
396
} ;
384
397
385
- if !verify_sender_by_fingerprint ( context, & fingerprint, contact_id) . await ? {
398
+ let sender_contact = Contact :: get_by_id ( context, contact_id) . await ?;
399
+ let sender_is_verified = sender_contact
400
+ . fingerprint ( )
401
+ . is_some_and ( |fp| fp == fingerprint) ;
402
+ if !sender_is_verified {
386
403
warn ! (
387
404
context,
388
405
"Ignoring {step} message because of fingerprint mismatch."
389
406
) ;
390
407
return Ok ( HandshakeMessage :: Ignore ) ;
391
408
}
392
409
info ! ( context, "Fingerprint verified via Auth code." , ) ;
410
+
411
+ // Mark the contact as verified if auth code is 600 second old.
412
+ if time ( ) < timestamp + 600 {
413
+ mark_contact_id_as_verified ( context, contact_id, ContactId :: SELF ) . await ?;
414
+ }
393
415
contact_id. regossip_keys ( context) . await ?;
394
416
ContactId :: scaleup_origin ( context, & [ contact_id] , Origin :: SecurejoinInvited ) . await ?;
395
417
// for setup-contact, make Alice's one-to-one chat with Bob visible
0 commit comments