End-to-End Encryption#
Process Overview#
Registered user#
Pretend that the involved operator is:
Operator |
Description |
|---|---|
server |
server |
userA |
This user executes the registration operation |
userA generates a pair of RSA key pairs (public key and private key) and sets the public_key field in the RegisterRequest to the public key. Ensure that the private key is not leaked to any other operator, including the server, and is saved locally.
create an end-to-end encrypted group chat#
Operator |
Description |
|---|---|
server |
server |
userA |
This user creates a group chat |
userA creates a symmetric encryption room_key and saves it locally. Ensure that it is not leaked to other untrusted operators, including the server.
Then userA sends a request to the server to create a group chat, setting e2ee_on to true in the NewSessionRequest.
Accept a user to join the group chat#
Pretend that the involved operator is:
Operator |
Description |
|---|---|
server |
server |
userA |
Someone who is already in the group |
userB |
Yet to be in the group, will send an entry request to userA |
userB sends a
join_sessionrequest to the serveruserA receives a
JoinSessionApprovalmessage, which contains the public key of userB,public_key. Encryptroom_keywithpublic_keyto getencrypted_room_keyuserA sends a
allow_user_join_sessionrequest, sets theroom_keyfield toencrypted_room_keyuserB receives an
AllowUserJoinSessionNotificationmessage, which contains theroom_keyfield with the content ofencrypted_room_key. Use their own RSA private key to decrypt it and obtain the original content ofroom_key. Similarly, it must not be leaked to other untrusted operators, including the server.
Invite a user to join the group chat#
Pretend that the involved operator is:
Operator |
Description |
|---|---|
server |
server |
userA |
Someone who is already in the group, will invite userB to join |
userB |
Yet to be in the group |
userA sends a
invite_user_to_sessionrequest to the serveruserB receives an
InviteUserToSessionmessage, then uses the information to send anaccept_join_session_approvalrequest to the serveruserA receives an
AcceptSessionNotificationmessage, which contains the public key of userB,public_key. Encryptroom_keywithpublic_keyto getencrypted_room_keyuserA sends a
send_room_keyrequest, sets theroom_keyfield toencrypted_room_keyuserB receives a
ReceiveRoomKeyNotificationmessage, which contains theroom_keyfield with the content ofencrypted_room_key. Use their own RSA private key to decrypt it and obtain the original content ofroom_key. Similarly, it must not be leaked to other untrusted operators, including the server.
The replacement of room_key#
Replacement conditions: When a certain time (can be set) has passed since the last replacement or someone leaves the group chat, the group will be marked. When someone speaks in the marked group, a key exchange operation will be performed. The user’s e2eeize_session request to the server can also trigger a replacement of the group’s room_key.
Pretend that the involved operator is:
Operator |
Description |
|---|---|
server |
server |
userA |
The first user to speak in the group after it is marked |
userB |
Others in the group |
When an update is needed, userA will receive an
UpdateRoomKeyNotificationmessage after the message is successfully sent. At this time, userA needs to update the group’sroom_key, and there will be severalSendRoomKeyNotificationmessages containing the public keys of other members. The following example uses userB.userA encrypts the updated
room_keywith userB’s public key to obtain the encryptedencrypted_room_keyuserA sends a
send_room_keyrequest, sets theroom_keyfield toencrypted_room_keyuserB receives a
ReceiveRoomKeyNotificationmessage, which contains theroom_keyfield with the content ofencrypted_room_key. Use their own RSA private key to decrypt it and obtain the original content ofroom_key. Similarly, it must not be leaked to other untrusted operators, including the server.
Switch the end-to-end encryption status of the group chat (on/off)#
Pretend that the involved operator is:
Operator |
Description |
|---|---|
server |
server |
userA |
The user in this group and with |
Set the group chat to end-to-end encryption#
userA sends a
e2eeize_sessionrequest to the serverthen it is the process of replacing
room_key
Set the group chat to non-end-to-end encryption#
userA sends a
dee2eeize_sessionrequest to the server
Things to note when sending messages#
In an end-to-end encrypted group chat, each user chooses whether to encrypt when sending a message. If so, they use the room_key for encryption.
A room_key is valid from the time it is created until it is replaced. Any client holding the room_key can decrypt the encrypted message.