-
-
Notifications
You must be signed in to change notification settings - Fork 107
[WIP] QR codes and symmetric encryption for broadcast channels #7042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
322bf0c
to
abc4e12
Compare
983d050
to
e4e7a36
Compare
e4e7a36
to
0b365d3
Compare
…in a 'member added' message.
…ually add a contact to a broadcast list, don't have unpromoted broadcast lists, make basic multi-device, inviter side, work
…another one where I couldn't find the problem
…oadcast_multidevice
dc4f1d4
to
fc52c8d
Compare
For `vb-member-added`: - On Bob's second device, observe_securejoin_on_other_device() isn't even called, because the message is incoming, not outgoing - On Alice's second device, Bob is added as a result of the `vb-request-with-auth` message, so, it's not necessary to add Bob as a result of the outgoing `vb-member-added` message
Not possible to use create_multiuser_record(), because it's nicer to do things in a transaction here
hash_alg: HashAlgorithm::default(), | ||
salt, | ||
}; | ||
let mut msg = msg.seipd_v2( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses SEIPD v2, while in other places, we use SEIPD v1. I assume that we used SEIPD v1 because v2 didn't exist yet at the time, and SEIPD v2 is superior, so, we should use it?
} else if chat.typ == Chattype::InBroadcast && contact_id == ContactId::SELF { | ||
// For incoming broadcast channels, it's not possible to remove members, | ||
// but it's possible to leave: | ||
let self_addr = context.get_primary_self_addr().await?; | ||
send_member_removal_msg(context, chat_id, contact_id, &self_addr).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a broadcast channel now uses the same code as leaving a group, so, we don't need this block anymore.
See this code a few lines above:
if matches!(
chat.typ,
Chattype::Group | Chattype::OutBroadcast | Chattype::InBroadcast
) {
if is_contact_in_chat(context, chat_id, contact_id).await? { | ||
return Ok(false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this block because we're in the else
clause of if is_contact_in_chat(context, chat_id, contact_id).await?
, so, this was dead code
"invalid contact_id {} for adding to group", | ||
contact_id | ||
); | ||
ensure!(!chat.is_mailing_list(), "Mailing lists can't be changed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this line because above we're ckecking ensure!(chat.typ == Chattype::Group || chat.typ == Chattype::OutBroadcast [...])
, so, this was dead code
d5ce883
to
43d65cb
Compare
Bad news: The 2-step protocol designed here would reveal Bob's display name and avatar to the server operator, if the server operator can also see the QR code. While this a rare occasion, it's bad that it's possible - a server operator could scrape the interned for QR codes, and then see if it's possible to use it to get the display name and avatar. After some discussions with @hpk42 and @link2xt, there are 2 alternatives: a 3-step protocol and a 4-step protocol that solve this problem, at the expense of taking longer. This is fine, though, because the current securejoin protocol also requires 4 steps. After some more discussions, we settled on the 4-step protocol for now, because it is a lot less complex than the 3-step protocol: ![]() Rationale:
About the complexity "Alice needs to create a Bob-contact without knowing his fingerprint": It should be possible for Alice to receive and answer the first message without any database changes. This will probably mean that The 4-step protocol in text form
Required security propertiesSecurity properties we want:
Security properties we probably want:
Other possibly-interesting security properties:
Security properties we don't need to talk about right now:
|
Part of #6884.
This will make it possible to create invite-QR codes for broadcast channels, and make them symmetrically end-to-end encrypted.
I posted the benchmark results at #6884 (comment)
Overview of the protocol when both sides have multi-device
The technical design
The QR codes / invite links and the network protocol build on the securejoin protocol in order to secure broadcast channels against MitM attacks, to securely exchange key material, and to add a member to the broadcast channel.
The mentioned securejoin protocol has 4 steps of exchanging messages. Rather than using the same protocol for broadcast channels, I will implement an improved protocol consisting of only 2 steps, described below. I will call it Securejoin v2.
The securejoin v2 protocol has these advantages over the old protocol:
If Securejoin v2 turns out to work nicely for broadcast channels, we can also use them for group and 1:1 invites, and remove the code for securejoin v1.
The QR code / invite link scheme
I will call the channel owner's device "Alice" and the device of the user who scans / clicks on the invite link "Bob".
Alice creates an invite link like this; QR codes contain the same text.
where:
The network protocol for joining a channel - Securejoin v2
In summary, Bob sends a message that is encrypted symmetrically with the AUTH token. Alice answers by adding Bob to the broadcast channel, and sending the broadcast channel's shared secret to Bob.
This is adapted from https://securejoin.readthedocs.io/en/latest/new.html:
a) Alice generates an invite code for this broadcast channel.
b) The AUTH token is generated specifically for this broadcast channel; Alice remembers in the
tokens
SQL table that this AUTH token belongs to this broadcast channel.a) Bob (the user) scans the QR code or clicks on the link. Bob saves Alice's fingerprint into the database and creates the broadcast channel chat; only messages signed with this fingerprint will be allowed in the broadcast channel.
b) Bob sends a message with the header
Secure-Join: vb-request-with-auth
to Alice. (vb-request-with-auth
follows the scheme of the securejoin v1 messages).In the encrypted part, this message contains Bob's own fingerprint
Bob_FP
in the headerSecure-Join-Fingerprint
.This message additionally contains all the information Delta Chat adds in every message: Bob's public key (so that Alice can send private messages to Bob), as well as Bob's display name and avatar (so that Alice can see who joined her channel; note that Delta Chat makes it easy to create an anonymous profile where the name and avatar are not identifying).
Alice decrypts Bob's
vb-request-with-auth
message using the AUTH token from step 1a) and verifies that Bob’s Autocrypt key matches Bob_FP and that the transferred AUTH matches the one from step 1.
b) If any verification fails, the protocol terminates.
a) Alice adds Bob to the broadcast channel in her database,
b) and sends a message with the header
Secure-Join: vb-member-added
to Bob.This message contains the broadcast channel's shared secret in the header
Chat-Broadcast-Secret
.This message is asymmetrically encrypted with Bob's public key; alternatively, it could be encrypted with the AUTH token, or with both the public key and the AUTH token.
Bob saves the shared secret into his database and is now able to decrypt messages that are sent into the channel.
If this network protocol works nicely in practice, we can start using it also for normal contact/group invites.
The symmetric encryption
Symmetric encryption uses a shared secret. Currently, we use AES128 for encryption everywhere in Delta Chat, so, this is what I'm using for broadcast channels (though it wouldn't be hard to switch to AES256).
vb-request-with-auth
has 144 bits of entropy (seefn create_id
in the code). If and when we switch to AES256, we can just generate larger AUTH tokens.fn create_broadcast_shared_secret
in the code).Since the shared secrets have more entropy than the AES session keys, it's not necessary to have a hard-to-compute string2key algorithm, so, I'm using the string2key algorithm
salted
. This is fast enough that Delta Chat can just try out all known shared secrets. 1 In order to prevent DOS attacks, Delta Chat will not attempt to decrypt with a string2key algorithm other thansalted
2.Footnotes
In a symmetrically encrypted message, it's not visible which secret was used to encrypt without trying out all secrets. If this does turn out to be too slow in the future, then we can assign a short, non-unique (~2 characters) id to every shared secret, and send it in cleartext. The receiving Delta Chat will then only try out shared secrets with this id. Of course, this would leak a little bit of metadata in cleartext, so, I would like to avoid it. ↩
A DOS attacker could send a message with a lot of encrypted session keys, all of which use a very hard-to-compute string2key algorithm. Delta Chat would then try to decrypt all of the encrypted session keys with all of the known shared secrets. In order to prevent this, as I said, Delta Chat will not attempt to decrypt with a string2key algorithm other than
salted
↩