Skip to content

Commit 8982410

Browse files
committed
E2E Test: E2E test for end to end encryption.
1 parent e796fdd commit 8982410

5 files changed

Lines changed: 764 additions & 9 deletions

File tree

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ jobs:
128128
LIVEKIT_API_SECRET: ${{ secrets.LIVEKIT_API_SECRET }}
129129
run: |
130130
source .test-venv/bin/activate
131-
pytest tests/
131+
pytest tests/ livekit-rtc/tests/
132132
133133
- name: Run tests (Windows)
134134
if: runner.os == 'Windows'
135135
env:
136136
LIVEKIT_URL: ${{ secrets.LIVEKIT_URL }}
137137
LIVEKIT_API_KEY: ${{ secrets.LIVEKIT_API_KEY }}
138138
LIVEKIT_API_SECRET: ${{ secrets.LIVEKIT_API_SECRET }}
139-
run: .test-venv\Scripts\python.exe -m pytest tests/
139+
run: .test-venv\Scripts\python.exe -m pytest tests/ livekit-rtc/tests/
140140
shell: pwsh
141141

livekit-rtc/livekit/rtc/e2ee.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,28 @@ def ratchet_key(self, participant_identity: str, key_index: int) -> bytes:
185185

186186

187187
class FrameCryptor:
188-
def __init__(self, room_handle: int, participant_identity: str, key_index: int, enabled: bool):
188+
def __init__(
189+
self,
190+
room_handle: int,
191+
participant_identity: str,
192+
track_sid: str,
193+
key_index: int,
194+
enabled: bool,
195+
):
189196
self._room_handle = room_handle
190197
self._enabled = enabled
191198
self._participant_identity = participant_identity
199+
self._track_sid = track_sid
192200
self._key_index = key_index
193201

194202
@property
195203
def participant_identity(self) -> str:
196204
return self._participant_identity
197205

206+
@property
207+
def track_sid(self) -> str:
208+
return self._track_sid
209+
198210
@property
199211
def key_index(self) -> int:
200212
return self._key_index
@@ -218,6 +230,7 @@ def set_enabled(self, enabled: bool) -> None:
218230
req = proto_ffi.FfiRequest()
219231
req.e2ee.room_handle = self._room_handle
220232
req.e2ee.cryptor_set_enabled.participant_identity = self._participant_identity
233+
req.e2ee.cryptor_set_enabled.track_sid = self._track_sid
221234
req.e2ee.cryptor_set_enabled.enabled = enabled
222235
FfiClient.instance.request(req)
223236

@@ -236,6 +249,7 @@ def set_key_index(self, key_index: int) -> None:
236249
req = proto_ffi.FfiRequest()
237250
req.e2ee.room_handle = self._room_handle
238251
req.e2ee.cryptor_set_key_index.participant_identity = self._participant_identity
252+
req.e2ee.cryptor_set_key_index.track_sid = self._track_sid
239253
req.e2ee.cryptor_set_key_index.key_index = key_index
240254
FfiClient.instance.request(req)
241255

@@ -289,6 +303,7 @@ def frame_cryptors(self) -> List[FrameCryptor]:
289303
"""
290304
req = proto_ffi.FfiRequest()
291305
req.e2ee.room_handle = self._room_handle
306+
req.e2ee.manager_get_frame_cryptors.SetInParent()
292307

293308
resp = FfiClient.instance.request(req)
294309
frame_cryptors = []
@@ -297,6 +312,7 @@ def frame_cryptors(self) -> List[FrameCryptor]:
297312
FrameCryptor(
298313
self._room_handle,
299314
frame_cryptor.participant_identity,
315+
frame_cryptor.track_sid,
300316
frame_cryptor.key_index,
301317
frame_cryptor.enabled,
302318
)

livekit-rtc/livekit/rtc/room.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,10 @@ def on_participant_connected(participant):
460460
)
461461

462462
req.connect.options.e2ee.encryption_type = options.e2ee.encryption_type
463-
req.connect.options.e2ee.key_provider_options.shared_key = (
464-
options.e2ee.key_provider_options.shared_key # type: ignore
465-
)
463+
if options.e2ee.key_provider_options.shared_key is not None:
464+
req.connect.options.e2ee.key_provider_options.shared_key = (
465+
options.e2ee.key_provider_options.shared_key
466+
)
466467
req.connect.options.e2ee.key_provider_options.ratchet_salt = (
467468
options.e2ee.key_provider_options.ratchet_salt
468469
)
@@ -481,9 +482,10 @@ def on_participant_connected(participant):
481482

482483
if options.encryption:
483484
req.connect.options.encryption.encryption_type = options.encryption.encryption_type
484-
req.connect.options.encryption.key_provider_options.shared_key = (
485-
options.encryption.key_provider_options.shared_key # type: ignore
486-
)
485+
if options.encryption.key_provider_options.shared_key is not None:
486+
req.connect.options.encryption.key_provider_options.shared_key = (
487+
options.encryption.key_provider_options.shared_key
488+
)
487489
req.connect.options.encryption.key_provider_options.ratchet_salt = (
488490
options.encryption.key_provider_options.ratchet_salt
489491
)

0 commit comments

Comments
 (0)