Skip to content

Commit 02626fc

Browse files
committed
fix verification by self
1 parent 7a3f26d commit 02626fc

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

src/contact.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ pub(crate) async fn mark_contact_id_as_verified(
18671867
contact_id: ContactId,
18681868
verifier_id: ContactId,
18691869
) -> Result<()> {
1870+
debug_assert_ne!(contact_id, verifier_id, "Contact cannot be verified by self");
18701871
context
18711872
.sql
18721873
.transaction(|transaction| {
@@ -1878,13 +1879,15 @@ pub(crate) async fn mark_contact_id_as_verified(
18781879
if contact_fingerprint.is_empty() {
18791880
bail!("Non-PGP contact {contact_id} cannot be verified.");
18801881
}
1881-
let verifier_fingerprint: String = transaction.query_row(
1882-
"SELECT fingerprint FROM contacts WHERE id=?",
1883-
(verifier_id,),
1884-
|row| row.get(0),
1885-
)?;
1886-
if verifier_fingerprint.is_empty() {
1887-
bail!("Contact {contact_id} cannot be verified by non-PGP contact {verifier_id}.");
1882+
if verifier_id != ContactId::SELF {
1883+
let verifier_fingerprint: String = transaction.query_row(
1884+
"SELECT fingerprint FROM contacts WHERE id=?",
1885+
(verifier_id,),
1886+
|row| row.get(0),
1887+
)?;
1888+
if verifier_fingerprint.is_empty() {
1889+
bail!("Contact {contact_id} cannot be verified by non-PGP contact {verifier_id}.");
1890+
}
18881891
}
18891892
transaction.execute(
18901893
"UPDATE contacts SET verifier=? WHERE id=?",

src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ impl Context {
11681168
.await?
11691169
.first()
11701170
.context("Self reporting bot vCard does not contain a contact")?;
1171-
mark_contact_id_as_verified(self, contact_id, contact_id).await?;
1171+
mark_contact_id_as_verified(self, contact_id, ContactId::SELF).await?;
11721172

11731173
let chat_id = ChatId::create_for_contact(self, contact_id).await?;
11741174
chat_id

src/securejoin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ async fn verify_sender_by_fingerprint(
208208
let contact = Contact::get_by_id(context, contact_id).await?;
209209
let is_verified = contact.fingerprint().is_some_and(|fp| &fp == fingerprint);
210210
if is_verified {
211-
mark_contact_id_as_verified(context, contact_id, contact_id).await?;
211+
mark_contact_id_as_verified(context, contact_id, ContactId::SELF).await?;
212212
}
213213
Ok(is_verified)
214214
}
@@ -537,7 +537,7 @@ pub(crate) async fn observe_securejoin_on_other_device(
537537
return Ok(HandshakeMessage::Ignore);
538538
};
539539

540-
mark_contact_id_as_verified(context, contact_id, contact_id).await?;
540+
mark_contact_id_as_verified(context, contact_id, ContactId::SELF).await?;
541541

542542
ChatId::set_protection_for_contact(context, contact_id, mime_message.timestamp_sent).await?;
543543

src/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ fn print_logevent(logevent: &LogEvent) {
13701370
/// and peerstate as backwards verified.
13711371
pub(crate) async fn mark_as_verified(this: &TestContext, other: &TestContext) {
13721372
let contact_id = this.add_or_lookup_contact_id(other).await;
1373-
mark_contact_id_as_verified(this, contact_id, contact_id)
1373+
mark_contact_id_as_verified(this, contact_id, ContactId::SELF)
13741374
.await
13751375
.unwrap();
13761376
}

0 commit comments

Comments
 (0)