Skip to content

Commit 29e39a7

Browse files
committed
feat: do not mark Bob as verified if auth token is old
1 parent 30a434b commit 29e39a7

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/securejoin.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::qr::check_qr;
2323
use crate::securejoin::bob::JoinerProgress;
2424
use crate::sync::Sync::*;
2525
use crate::token;
26+
use crate::tools::time;
2627

2728
mod bob;
2829
mod qrinvite;
@@ -364,7 +365,19 @@ pub(crate) async fn handle_securejoin_handshake(
364365
);
365366
return Ok(HandshakeMessage::Ignore);
366367
};
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 {
368381
warn!(
369382
context,
370383
"Ignoring {step} message because of invalid auth code."
@@ -382,14 +395,23 @@ pub(crate) async fn handle_securejoin_handshake(
382395
}
383396
};
384397

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 {
386403
warn!(
387404
context,
388405
"Ignoring {step} message because of fingerprint mismatch."
389406
);
390407
return Ok(HandshakeMessage::Ignore);
391408
}
392409
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+
}
393415
contact_id.regossip_keys(context).await?;
394416
ContactId::scaleup_origin(context, &[contact_id], Origin::SecurejoinInvited).await?;
395417
// for setup-contact, make Alice's one-to-one chat with Bob visible

src/token.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,6 @@ pub async fn exists(context: &Context, namespace: Namespace, token: &str) -> Res
8686
Ok(exists)
8787
}
8888

89-
/// Looks up foreign key by auth token.
90-
///
91-
/// Returns None if auth token is not valid.
92-
/// Returns an empty string if the token corresponds to "setup contact" rather than group join.
93-
pub async fn auth_foreign_key(context: &Context, token: &str) -> Result<Option<String>> {
94-
context
95-
.sql
96-
.query_row_optional(
97-
"SELECT foreign_key FROM tokens WHERE namespc=? AND token=?",
98-
(Namespace::Auth, token),
99-
|row| {
100-
let foreign_key: String = row.get(0)?;
101-
Ok(foreign_key)
102-
},
103-
)
104-
.await
105-
}
106-
10789
pub async fn delete(context: &Context, namespace: Namespace, token: &str) -> Result<()> {
10890
context
10991
.sql

0 commit comments

Comments
 (0)