Skip to content

Commit 9ee684b

Browse files
authored
rfc: faster handshake protocol (#1203)
* rfc: faster handshake protocol * update * 1 message * SKEY * use SKEY for both parties * test * update doc * NEW command parameter * add k=s param to queue URI * fix * add sndSecure field to queues * make sender key non-optional in SndQueue (WIP, tests fail) * fast handshake sometimes works (many tests fail) * correctly handle SKEY retries, avoiding to re-generate the keys * handle SKEY retries during async connection * fix most tests (1 test fails) * remove do * fix contact requests encoding/tests * export * fix: ignore duplicate confirmations, fixes testBatchedPendingMessages * do not store sndSecure in store log if it is false to allow server downgrade * add connection invitation encoding tests
1 parent c788692 commit 9ee684b

30 files changed

+1183
-778
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
sequenceDiagram
2+
participant A as Alice
3+
participant AA as Alice's<br>agent
4+
participant AS as Alice's<br>server
5+
participant BS as Bob's<br>server
6+
participant BA as Bob's<br>agent
7+
participant B as Bob
8+
9+
note over AA, BA: status (receive/send): NONE/NONE
10+
11+
note over A, AA: 1. request connection<br>from agent
12+
A ->> AA: NEW: create<br>duplex connection
13+
14+
note over AA, AS: 2. create Alice's SMP queue
15+
AA ->> AS: NEW: create SMP queue
16+
AS ->> AA: IDS: SMP queue IDs
17+
note over AA: status: NEW/NONE
18+
19+
AA ->> A: INV: invitation<br>to connect
20+
21+
note over A, B: 3. out-of-band invitation
22+
A ->> B: OOB: invitation to connect
23+
24+
note over BA, B: 4. accept connection
25+
B ->> BA: JOIN:<br>via invitation info
26+
note over BA: status: NONE/NEW
27+
28+
note over BA, AS: 5. secure Alice's SMP queue
29+
BA ->> AS: SKEY: secure queue (this command needs to be proxied)
30+
note over BA: status: NONE/SECURED
31+
32+
note over BA, BS: 6. create Bob's SMP queue
33+
BA ->> BS: NEW: create SMP queue
34+
BS ->> BA: IDS: SMP queue IDs
35+
note over BA: status: NEW/SECURED
36+
37+
note over BA, AA: 7. confirm Alice's SMP queue
38+
BA ->> AS: SEND: Bob's info without sender's key (SMP confirmation with reply queues)
39+
note over BA: status: NEW/CONFIRMED
40+
41+
AS ->> AA: MSG: Bob's info without<br>sender server key
42+
note over AA: status: CONFIRMED/NEW
43+
AA ->> AS: ACK: confirm message
44+
45+
note over AA, BS: 8. secure Bob's SMP queue
46+
AA ->> BS: SKEY: secure queue (this command needs to be proxied)
47+
note over BA: status: CONFIRMED/SECURED
48+
49+
AA ->> BS: SEND: Alice's info without sender's server key (SMP confirmation without reply queues)
50+
note over AA: status: CONFIRMED/CONFIRMED
51+
52+
note over AA, A: 9. notify Alice<br>about connection success<br>(no HELLO needed in v6)
53+
AA ->> A: CON: connected
54+
note over AA: status: ACTIVE/ACTIVE
55+
56+
BS ->> BA: MSG: Alice's info without<br>sender's server key
57+
note over BA: status: CONFIRMED/CONFIRMED
58+
BA ->> B: INFO: Alice's info
59+
BA ->> BS: ACK: confirm message
60+
61+
note over BA, B: 10. notify Bob<br>about connection success
62+
BA ->> B: CON: connected
63+
note over BA: status: ACTIVE/ACTIVE

rfcs/2024-06-14-fast-connection.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Faster connection establishment
2+
3+
## Problem
4+
5+
SMP protocol is unidirectional, and to create a connection users have to agree two messaging queues.
6+
7+
V1 of handshake protocol required 5 messages and multiple HELLO sent between the users, which consumed a lot of traffic.
8+
9+
V2 of handshake protocol was optimized to remove multiple HELLO and also REPLY message, thanks to including queue address together with the key to secure this queue into the confirmation message.
10+
11+
This eliminated unnecessary traffic from repeated HELLOs, but still requires 4 messages in total and 2 times of each client being online. It is perceived by the users as "it didn't work" (because they see "connecting" after using the link) or "we have to be online at the same time" (and even in this case it is slow on bad network). This hurts usability and creates churn of the new users, as unless people are onboarded by the friends who know how the app works, they cannot figure out how to connect.
12+
13+
Ideally, we want to have handshake protocol design when an accepting user can send messages straight after using the link (their client says "connected") and the initiating client can send messages as soon as it received confirmation message with the profile.
14+
15+
This RFC proposes modifications to SMP and SMP Agent protocols to reduce the number of required messages to 2 and allows accepting client to send messages straight after using the link (and sending the confirmation), before receiving the profile of the initiating client in the second message, and the initiating client can send the messages straight after processing the confirmation and sending its own confirmation.
16+
17+
## Solution
18+
19+
The current protocol design allows additional confirmation step where the initiating client can confirm the connection having received the profile of the sender. We don't use it in the UI - this confirmation is done automatically and unconditionally.
20+
21+
Instead of requiring the initiating client to secure its queue with sender's key, we can allow the accepting client to secure it with the additional SKEY command. This would avoid "connecting" state but would introduce "Profile unknown" state where the accepting client does not yet have the profile of the initiating client. In this case we could also use the non-optional alias created during the connection (or have something like "Add alias to be able to send messages immediately" and show warning if the user proceeds without it).
22+
23+
The additional advantage here is that if the queue of the initiating client was removed, the connection will not procede to create additional queue, failing faster.
24+
25+
These are the proposed changes:
26+
27+
1. Modify NEW command to add flag allowing sender to secure the queue (it should not be allowed if queue is created for the contact address).
28+
2. Include flag into the invitation link URI and in reply address encoding that queue(s) can be secured by the sender (to avoid coupling with the protocol version and preserve the possibility of the longer handshakes).
29+
3. Add SKEY command to SMP protocol to allow the sender securing the message queue.
30+
4. This command has to be supported by SMP proxy as well, so that the sender does not connect to the recipient's server directly.
31+
5. Accepting client will secure the messaging queue before sending the confirmation to it.
32+
6. Initiating client will secure the messaging queue before sending the confirmation.
33+
34+
See [this sequence diagram](../protocol/diagrams/duplex-messaging/duplex-creating-v6.mmd) for the updated handshake protocol.
35+
36+
Changes to threat model: the attacker who compromised TLS and knows the queue address can block the connection, as the protocol no longer requires the recipient to decrypt the confirmation to secure the queue.
37+
38+
Possibly, "fast connection" should be an option in Privacy & security settings.
39+
40+
## Implementation questions
41+
42+
Currently we store received confirmations in the database, so that the client can confirm them. This becomes unnecessary.

simplexmq.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ library
134134
Simplex.Messaging.Agent.Store.SQLite.Migrations.M20240225_ratchet_kem
135135
Simplex.Messaging.Agent.Store.SQLite.Migrations.M20240417_rcv_files_approved_relays
136136
Simplex.Messaging.Agent.Store.SQLite.Migrations.M20240518_servers_stats
137+
Simplex.Messaging.Agent.Store.SQLite.Migrations.M20240624_snd_secure
137138
Simplex.Messaging.Agent.TRcvQueues
138139
Simplex.Messaging.Client
139140
Simplex.Messaging.Client.Agent

0 commit comments

Comments
 (0)