Skip to content

fix: Rerun the full securejoin protocol if the address was outdated#8358

Open
Hocuri wants to merge 7 commits into
mainfrom
hoc/rerun-full-securejoin-on-outdated-addr
Open

fix: Rerun the full securejoin protocol if the address was outdated#8358
Hocuri wants to merge 7 commits into
mainfrom
hoc/rerun-full-securejoin-on-outdated-addr

Conversation

@Hocuri

@Hocuri Hocuri commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Alternative to #8355, fixes #8329

hpk42 and others added 4 commits June 22, 2026 04:24
…heir singular relay and added a new one and then perform a securejoin
…ropped their singular relay and added a new one and then perform a securejoin"

This reverts commit a9d19bc.
@Hocuri Hocuri changed the title Hoc/rerun full securejoin on outdated addr fix: Rerun the full securejoin protocol if the address was outdated Jun 22, 2026
Comment thread src/securejoin/qrinvite.rs Outdated
Contact {
contact_id: ContactId,
fingerprint: Fingerprint,
addr: String,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QrInvite is serialized into the database, so this addr should likely be passed next to the QrInvite as a separate argument.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you need to put #[serde(default)] on it for when it is deserialized from the bob state table.

Comment thread src/securejoin/bob.rs
Comment on lines +70 to +78
let has_up_to_date_key = if let Some(public_key_bytes) = public_key_bytes {
let public_key = SignedPublicKey::from_slice(&public_key_bytes)?;
let addrs_in_key = addresses_from_public_key(&public_key);
// The key is up to date if it contains all the addresses from the QR code:
addrs_in_key
.is_some_and(|addrs_in_key| invite.addrs().iter().all(|a| addrs_in_key.contains(a)))
} else {
false
};

@Hocuri Hocuri Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit unsure whether I prefer this PR here or #8355. For example, this logic here is somewhat hard to read. OTOH, the fix here is more "self-contained" in the securejoin logic, rather than needing logic changes elsewhere.

@hpk42 hpk42 Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's readable enough.
maybe rename the var to key_contains_all_invite_addrs and remove the comment? When i read "has_up_to_date_key" in other places i immediately wonder what that means concretely. It might also be that someone is scanning an old invite link, and the relay addresses in the Alice key that Bob has are actually the correct ones. #8355 would use both the key and the invite addresses but i think it's fine to only use invite addresses. This handshake would fail anyway if Alice has meanwhile changed all her relays.

@iequidoo iequidoo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks easy to read, but link2xt's comment looked unobvious for me

Comment thread src/securejoin/bob.rs Outdated

@hpk42 hpk42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, also maybe make sense to to generate multi-address invite links soon.

Comment thread src/securejoin/bob.rs
// The key is up to date iff it contains all the addresses from the QR code:
let has_up_to_date_key = if let Some(public_key_bytes) = public_key_bytes {
let public_key = SignedPublicKey::from_slice(&public_key_bytes)?;
let addrs_in_key = addresses_from_public_key(&public_key).unwrap_or_default();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unwrap_or_default() hides a corner case when we have a key for a key-contact, but the key has no addresses (because it does not have the notation subpacket). In this case if the address of the key-contact (the one in the contacts table which is usually the last seen From address and the address we are going to send messages to) is the same the address in the invite, there is no need to request a new key.

Can be fixed like this:

let inviter_addrs = if let Some(addrs_in_key) = addresses_from_public_key(&public_key) {
  addrs_in_key
} else if  let Some(contact_addr) = context.query_get_value("SELECT addr FROM contacts WHERE fingerprint=?", (invite.fingerprint().hex(),)).await? {
  vec![contact_addr]
} else {
  Vec::new()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scanning QR for existing contact doesn't update relay list

4 participants