From da96463d7ebaf1f64b03e497ee7dc7749ef63979 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Sun, 5 Nov 2023 20:02:00 +0100 Subject: [PATCH] Sketch (just TODO comments) for prevent-online-leak --- src/chat.rs | 4 ++++ src/securejoin.rs | 19 +++++++++++++++++++ src/sql/migrations.rs | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/src/chat.rs b/src/chat.rs index 60512c5920..970f00b3a8 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -460,6 +460,10 @@ impl ChatId { if sync.into() { chat.add_sync_item(context, ChatAction::Accept).await?; } + + // TODO Check in the sql table `alicestate` whether we need to resume the securejoin protocol. + // If so, remember to also update the `alicestate` table. + Ok(()) } diff --git a/src/securejoin.rs b/src/securejoin.rs index 6d57143d73..6a372643f8 100644 --- a/src/securejoin.rs +++ b/src/securejoin.rs @@ -326,6 +326,14 @@ pub(crate) async fn handle_securejoin_handshake( ChatId::create_for_contact(context, contact_id).await?; } + // TODO Here we need to check that the token isn't too old (no more than 2 days) + // and if it is too old, then we need to put the chat into "Request" state. + // Except if `get_config(Config::IsBot)` is true, in this case we just continue normally. + + // When the "Request" state is accepted (`ChatId::accept()`), we need to continue here. Also, we need to + // remember in the database that the user accepted a securejoin and the current timestamp. + // This probably needs to go into a new table `alicestate` or similar + // Alice -> Bob send_alice_handshake_msg( context, @@ -431,6 +439,17 @@ pub(crate) async fn handle_securejoin_handshake( info!(context, "Auth verified.",); context.emit_event(EventType::ContactsChanged(Some(contact_id))); inviter_progress!(context, contact_id, 600); + + // TODO Here we need to check that the token isn't too old + // and if it is too old, then we need to put the chat into "Request" state. + + // Except if `get_config(Config::IsBot)` is true, in this case we just continue normally. + + // Except if the user already accepted the securejoin above in the last 2 days, + // in this case we just continue normally. + + // When the "Request" state is accepted (in `ChatId::accept()`), we need to continue here. + if join_vg { // the vg-member-added message is special: // this is a normal Chat-Group-Member-Added message diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index 6e69311c5f..9d6347d46e 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -749,6 +749,13 @@ CREATE INDEX smtp_messageid ON imap(rfc724_mid); ) .await?; } + // TODO we need a new table called `alicestate` or similar for alice's state, which can be (for each chat): + // - Paused at step 3 because the invite code was too old. + // - Resumed by the user clicking "accept" after step 3. We need to save the timestamp when the user clicked "accept". + // - Paused at step 6 because the auth code was too old. + // I think that if it's none of these 3 states, there is no need to save it. + + // See https://countermitm.readthedocs.io/en/latest/new.html#setup-contact-protocol let new_version = sql .get_raw_config_int(VERSION_CFG)