Repository navigation
Follow key provider key index on media frame cryptors #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tangowhisky-dev
wants to merge
6
commits into
livekit:main
Choose a base branch
from
tangowhisky-dev:e2ee-sender-key-index-observer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+663
−34
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
41fd624
Follow key provider key index on media frame cryptors
tangowhisky-dev 7ed2cec
Merge branch 'main' into e2ee-sender-key-index-observer
tangowhisky-dev 50d9894
Review fixes: API-21-safe index mod + Room doc example
tangowhisky-dev 9ff81dd
Fix key-index stamp and dispose races in E2EEManager
tangowhisky-dev 1c19096
Match native key-index semantics and observable precedence
tangowhisky-dev 0fdcffa
Resolve negative shared-key index to the Kotlin current slot
tangowhisky-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "client-sdk-android": patch | ||
| --- | ||
|
|
||
| Media frame cryptors now follow the key provider's current key index, matching the JavaScript and Swift SDKs. `BaseKeyProvider` implements the new `KeyIndexObservable` contract: installing a shared key moves the current index, `setCurrentKeyIndex` re-points live senders, and `getLatestKeyIndex` returns the current index. Custom `KeyProvider` implementations can opt into live re-pointing by implementing `KeyIndexObservable`. Behavior change: in non-shared key mode `setKey` no longer moves the sender index — the key may belong to a remote participant — use `setCurrentKeyIndex` to switch the local one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Key rotation can stall strict receivers
During a live rotation, native
encryptFramecan select the old key but label the frame with the new index. A receiver withfailureTolerance = 0stops decrypting subsequent frames if ratcheting cannot recover that frame.Learn more
The SDK pins WebRTC milestone 150 in the dependency catalog. In the corresponding native encryptFrame implementation, frame encryption runs on a worker separate from the SDK's RTC executor. The worker reads the mutable key index separately for the key lookup and the frame trailer. The Kotlin monitor does not cover that worker. On the receiving side, decryptFrame skips subsequent frames after the failure threshold marks the key handler invalid and the decryption attempt fails.
Example: A sender selects the key in slot 0 for one frame, then rotates to an unrelated key in slot 1 before the worker writes the trailer. A receiver with both keys tries slot 1 against a frame encrypted using slot 0. If that receiver has a zero failure tolerance and ratcheting fails, correctly encrypted slot-1 frames also stop decrypting until the key handler is reset.
Recommended fix: Fix or upgrade the WebRTC dependency so each outgoing frame takes one synchronized snapshot of the index and uses it for the lookup and trailer. Exercise a live rotation with both slots provisioned in a native integration test.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This one is in native code:
encryptFramereadskey_index_three times withoutmutex_, so a concurrentSetKeyIndexcan split the slot lookup from the trailer byte. The race predates this PR, but it only becomes reachable now that a sender's index can move mid-call.I don't think it should block this PR. Both slots already hold valid keys when the index moves, because
setSharedKeyinstalls the key before the index changes. So the worst case is one frame the receiver can't decrypt per rotation. With the defaultfailureTolerance = -1, that never marks the key invalid, and the next frame decrypts normally.The fix is to snapshot the index under the lock once at the top of
encryptFrame. I'll send that tolivekit/libwebrtcas a separate change rather than work around it from Kotlin.