Skip to content

Commit 1b4206e

Browse files
authored
End to end encryption (#107)
* save * Adding a PacketWrapper protobuf type and key protobuf types * Rebase with new connection model * Add cargo workspace * cargo fmt * cargo fmt * Save close but no cigar * e2ee working poc - but it is laggy * allow non_camel_case_types * Encrypt heartbeats, clippy fix, it's smoother now * clippy fix * cargo fmt * Adding sequence diagram * If key doesn't exist send new pub key message * Rename proto var * Handle peers refreshing keys * fmt * Add feature flag for e2ee * Add missing env var * Same block * cargo clippy --fix * Removing unwraps * Refactor log statements with levels * Logging level * cargo fmt
1 parent 1ff8bf3 commit 1b4206e

40 files changed

+1484
-309
lines changed

.github/workflows/cargo-test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ env:
1919
WEBTRANSPORT_HOST: yeet
2020
ENABLE_OAUTH: false
2121
WEBTRANSPORT_ENABLED: true
22+
E2EE_ENABLED: true
2223

2324
jobs:
2425

@@ -32,7 +33,7 @@ jobs:
3233
components: clippy, rustfmt
3334
- run: cd actix-api && cargo clippy -- --deny warnings
3435
- run: cd actix-api && cargo fmt --check
35-
- run: cd actix-api && cargo test
36+
- run: cd actix-api && cargo test
3637

3738

3839
lint-ui:

Cargo.lock

Lines changed: 14 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actix-api/src/actors/chat_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Handler<ClientMessage> for ChatServer {
9494
user: _,
9595
} = msg;
9696
trace!("got message in server room {} session {}", room, session);
97-
self.send_message(&room, &msg.media_packet, session);
97+
self.send_message(&room, &msg.data, session);
9898
}
9999
}
100100

actix-api/src/actors/chat_session.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::messages::server::{ClientMessage, MediaPacketUpdate};
1+
use crate::messages::server::{ClientMessage, Packet};
22
use crate::messages::session::Message;
33
use crate::{actors::chat_server::ChatServer, constants::CLIENT_TIMEOUT};
44
use std::sync::Arc;
@@ -102,10 +102,10 @@ impl Handler<Message> for WsChatSession {
102102
}
103103
}
104104

105-
impl Handler<MediaPacketUpdate> for WsChatSession {
105+
impl Handler<Packet> for WsChatSession {
106106
type Result = ();
107107

108-
fn handle(&mut self, msg: MediaPacketUpdate, _ctx: &mut Self::Context) -> Self::Result {
108+
fn handle(&mut self, msg: Packet, _ctx: &mut Self::Context) -> Self::Result {
109109
let room_id = self.room.clone();
110110
trace!(
111111
"got message and sending to chat session {} email {} room {}",
@@ -136,8 +136,8 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WsChatSession {
136136

137137
match msg {
138138
ws::Message::Binary(msg) => {
139-
ctx.notify(MediaPacketUpdate {
140-
media_packet: Arc::new(msg.to_vec()),
139+
ctx.notify(Packet {
140+
data: Arc::new(msg.to_vec()),
141141
});
142142
}
143143
ws::Message::Ping(msg) => {

actix-api/src/messages/server/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct ClientMessage {
1111
pub session: SessionId,
1212
pub user: String,
1313
pub room: RoomId,
14-
pub msg: MediaPacketUpdate,
14+
pub msg: Packet,
1515
}
1616

1717
#[derive(ActixMessage)]
@@ -30,8 +30,8 @@ pub struct Connect {
3030

3131
#[derive(ActixMessage)]
3232
#[rtype(result = "()")]
33-
pub struct MediaPacketUpdate {
34-
pub media_packet: Arc<Vec<u8>>,
33+
pub struct Packet {
34+
pub data: Arc<Vec<u8>>,
3535
}
3636

3737
#[derive(ActixMessage)]

bot/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ async fn main() {
2222
let email_prefix = env::var("EMAIL_PREFIX").unwrap_or_else(|_| "".to_string());
2323

2424
(0..n_clients)
25-
.into_iter()
2625
.map(|_| async {
2726
let handle = create_client(&endpoint, &room, &echo_user, &email_prefix).await;
2827
let _ = handle.await;

docker/docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
- RUSTFLAGS=--cfg=web_sys_unstable_apis
2323
- RUST_BACKTRACE=1
2424
- WEBTRANSPORT_ENABLED=${WEBTRANSPORT_ENABLED:-false}
25+
- E2EE_ENABLED=${E2EE_ENABLED:-false}
2526
ports:
2627
- "${TRUNK_SERVE_PORT:-80}:${TRUNK_SERVE_PORT:-80}"
2728

protobuf/build-env-rust.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rust:1.62-slim
1+
FROM rust:1.71-slim
22
ENV DEBIAN_FRONTEND=noninteractive
33
ARG USER
44
ARG UID

protobuf/types/aes_packet.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
syntax = "proto3";
2+
3+
message AesPacket {
4+
bytes key = 1;
5+
bytes iv = 2;
6+
}

protobuf/types/packet_wrapper.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
syntax = "proto3";
2+
3+
message PacketWrapper {
4+
enum PacketType {
5+
RSA_PUB_KEY = 0;
6+
AES_KEY = 1;
7+
MEDIA = 2;
8+
}
9+
PacketType packet_type = 1;
10+
string email = 2;
11+
bytes data = 3;
12+
}

protobuf/types/rsa_packet.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
syntax = "proto3";
2+
3+
message RsaPacket {
4+
bytes public_key_der = 1;
5+
string username = 2;
6+
}

sequence-diagram.txt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
title videocall-rs e2ee sequence diagram
2+
3+
participant Alice
4+
participant Bob
5+
participant Server
6+
participant Casey
7+
8+
9+
Alice->Server:Alice joins room 1
10+
Alice->Server:Alice starts sending encrypted heartbeats
11+
Alice->Server:Alice sends RSA pub key message
12+
13+
Bob->Server:Bob joins room 1
14+
Bob->Server:Bob starts sending encrypted heartbeats
15+
Bob->Server:Bob sends RSA pub key message
16+
17+
Server->Alice:Server sends Bob's RSA pub key message to Alice
18+
Alice-->Server:Responding to Bob's RSA pub key msg, Alice encrypts their AES key with Bob's RSA pub key and sends it to the server
19+
Server-->Bob:Bob receives the AES msg from Alice and decrypts it with Bob's RSA private key
20+
21+
Alice->Server:Alice notices that Bob is a new peer and sends the RSA pub key message again
22+
Server->Bob:Server sends Alice's RSA pub key message to Bob
23+
Bob-->Server:Responding to Alices's RSA pub key msg, Bob encrypts their AES key with Alice's RSA pub key and sends it to the server
24+
Server-->Alice:Alice receives the AES msg from Bob and decrypts it with Alice's RSA private key
25+
26+
Casey->Server:Casey joins room 1
27+
Casey->Server:Casey starts sending encrypted heartbeats
28+
Casey->Server:Casey sends RSA pub key message
29+
30+
Server->Alice:Server sends Casey's RSA pub key message to Alice
31+
Alice-->Server:Responding to Casey's RSA pub key msg, Alice encrypts their AES key with Casey's RSA pub key and sends it to the server
32+
Server-->Casey:Casey receives the AES msg from Alice and decrypts it with Casey's RSA private key
33+
34+
Server->Bob:Server sends Casey's RSA pub key message to Bob
35+
Bob-->Server:Responding to Casey's RSA pub key msg, Bob encrypts their AES key with Casey's RSA pub key and sends it to the server
36+
Server-->Casey:Casey receives the AES msg from Bob and decrypts it with Casey's RSA private key
37+
38+
Alice->Server:Alice notices that Casey is a new peer and sends the RSA pub key message again
39+
Server->Casey:Server sends Alice's RSA pub key message to Casey
40+
Casey-->Server:Responding to Alices's RSA pub key msg, Casey encrypts their AES key with Alice's RSA pub key and sends it to the server
41+
Server-->Alice:Alice receives the AES msg from Casey and decrypts it with Alice's RSA private key
42+
43+
Server->Bob:Server sends Alice's RSA pub key message to Bob
44+
Bob-->Server:Responding to Alices's RSA pub key msg, Bob encrypts their AES key with Alice's RSA pub key and sends it to the server
45+
Server-->Alice:Alice receives the AES msg from Bob and decrypts it with Alice's RSA private key
46+
47+
Bob->Server:Bob notices that Casey is a new peer and sends the RSA pub key message again
48+
Server->Casey:Server sends Bob's RSA pub key message to Casey
49+
Casey-->Server:Responding to Bob's RSA pub key msg, Casey encrypts their AES key with Bob's RSA pub key and sends it to the server
50+
Server-->Bob:Bob receives the AES msg from Casey and decrypts it with Bob's RSA private key
51+
52+
Server->Alice:Server sends Bob's RSA pub key message to Alice
53+
Alice-->Server:Responding to Bob's RSA pub key msg, Alice encrypts their AES key with Bob's RSA pub key and sends it to the server
54+
Server-->Bob:Bob receives the AES msg from Alice and decrypts it with Bob's RSA private key
55+

types/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ edition = "2021"
88
[dependencies]
99
serde_json = "1.0.81"
1010
serde = { version = "1.0.37", features = ["derive"]}
11-
protobuf = "3.2.0"
11+
protobuf = "3.2.0"
12+
yew-websocket = "1.0.1"

0 commit comments

Comments
 (0)