Skip to content

Commit 7e4822c

Browse files
committed
fix: do not reverify already verified contacts via gossip
If the contact is already introduced by someone, usually by adding to a verified group, it should not be reverified because of another chat message is a verified group. This usually results is verification loops and is not meaningful because the verifier likely got this same contact introduced in the same group.
1 parent a955cb5 commit 7e4822c

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

src/contact.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,8 +1977,9 @@ pub(crate) async fn mark_contact_id_as_verified(
19771977
}
19781978
}
19791979
transaction.execute(
1980-
"UPDATE contacts SET verifier=? WHERE id=?",
1981-
(verifier_id, contact_id),
1980+
"UPDATE contacts SET verifier=?1
1981+
WHERE id=?2 AND (verifier=0 OR ?1=?3)",
1982+
(verifier_id, contact_id, ContactId::SELF),
19821983
)?;
19831984
Ok(())
19841985
})

src/tests/verified_chats.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,73 @@ async fn test_verified_chat_editor_reordering() -> Result<()> {
803803
Ok(())
804804
}
805805

806+
/// Tests that already verified contact
807+
/// does not get a new "verifier"
808+
/// via gossip.
809+
///
810+
/// Directly verifying is still possible.
811+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
812+
async fn test_no_reverification() -> Result<()> {
813+
let mut tcm = TestContextManager::new();
814+
let alice = &tcm.alice().await;
815+
let bob = &tcm.bob().await;
816+
let charlie = &tcm.charlie().await;
817+
let fiona = &tcm.fiona().await;
818+
819+
tcm.execute_securejoin(alice, bob).await;
820+
tcm.execute_securejoin(alice, charlie).await;
821+
tcm.execute_securejoin(alice, fiona).await;
822+
823+
tcm.section("Alice creates a protected group with Bob, Charlie and Fiona");
824+
let alice_chat_id = alice
825+
.create_group_with_members(ProtectionStatus::Protected, "Group", &[bob, charlie, fiona])
826+
.await;
827+
let alice_sent = alice.send_text(alice_chat_id, "Hi!").await;
828+
let bob_rcvd_msg = bob.recv_msg(&alice_sent).await;
829+
let bob_alice_id = bob_rcvd_msg.from_id;
830+
831+
// Charlie is verified by Alice for Bob.
832+
let bob_charlie_contact = bob.add_or_lookup_contact(charlie).await;
833+
assert_eq!(
834+
bob_charlie_contact
835+
.get_verifier_id(bob)
836+
.await?
837+
.unwrap()
838+
.unwrap(),
839+
bob_alice_id
840+
);
841+
842+
let fiona_rcvd_msg = fiona.recv_msg(&alice_sent).await;
843+
let fiona_chat_id = fiona_rcvd_msg.chat_id;
844+
let fiona_sent = fiona.send_text(fiona_chat_id, "Post by Fiona").await;
845+
bob.recv_msg(&fiona_sent).await;
846+
847+
// Charlie should still be verified by Alice, not by Fiona.
848+
let bob_charlie_contact = bob.add_or_lookup_contact(charlie).await;
849+
assert_eq!(
850+
bob_charlie_contact
851+
.get_verifier_id(bob)
852+
.await?
853+
.unwrap()
854+
.unwrap(),
855+
bob_alice_id
856+
);
857+
858+
// Bob can still verify Charlie directly.
859+
tcm.execute_securejoin(bob, charlie).await;
860+
let bob_charlie_contact = bob.add_or_lookup_contact(charlie).await;
861+
assert_eq!(
862+
bob_charlie_contact
863+
.get_verifier_id(bob)
864+
.await?
865+
.unwrap()
866+
.unwrap(),
867+
ContactId::SELF
868+
);
869+
870+
Ok(())
871+
}
872+
806873
// ============== Helper Functions ==============
807874

808875
async fn assert_verified(this: &TestContext, other: &TestContext, protected: ProtectionStatus) {

0 commit comments

Comments
 (0)