Skip to content

Commit 9be4280

Browse files
cloudwebrtcCopilotgithub-actions[bot]
authored
Fix bug for FrameCryptor and E2E test for E2EE. (#656)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cloudwebrtc <17733746+cloudwebrtc@users.noreply.github.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 4bb2f21 commit 9be4280

5 files changed

Lines changed: 777 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
@@ -466,9 +466,10 @@ def on_participant_connected(participant):
466466
)
467467

468468
req.connect.options.e2ee.encryption_type = options.e2ee.encryption_type
469-
req.connect.options.e2ee.key_provider_options.shared_key = (
470-
options.e2ee.key_provider_options.shared_key # type: ignore
471-
)
469+
if options.e2ee.key_provider_options.shared_key is not None:
470+
req.connect.options.e2ee.key_provider_options.shared_key = (
471+
options.e2ee.key_provider_options.shared_key
472+
)
472473
req.connect.options.e2ee.key_provider_options.ratchet_salt = (
473474
options.e2ee.key_provider_options.ratchet_salt
474475
)
@@ -487,9 +488,10 @@ def on_participant_connected(participant):
487488

488489
if options.encryption:
489490
req.connect.options.encryption.encryption_type = options.encryption.encryption_type
490-
req.connect.options.encryption.key_provider_options.shared_key = (
491-
options.encryption.key_provider_options.shared_key # type: ignore
492-
)
491+
if options.encryption.key_provider_options.shared_key is not None:
492+
req.connect.options.encryption.key_provider_options.shared_key = (
493+
options.encryption.key_provider_options.shared_key
494+
)
493495
req.connect.options.encryption.key_provider_options.ratchet_salt = (
494496
options.encryption.key_provider_options.ratchet_salt
495497
)

0 commit comments

Comments
 (0)