Repository navigation
Follow key provider key index on media frame cryptors - #1042
Open
tangowhisky-dev wants to merge 3 commits into
Open
tangowhisky-dev wants to merge 3 commits into
tangowhisky-dev wants to merge 3 commits into
Conversation
Ports the semantics merged in livekit/client-sdk-swift#1157 to Android, superseding the approach in livekit#1039. BaseKeyProvider now implements the new KeyIndexObservable contract: the current key index is the single source of truth for what the local participant encrypts with. Installing a shared key moves the index and setCurrentKeyIndex() exposes it directly; getLatestKeyIndex() returns it for both media senders and data packets. E2EEManager subscribes to the provider and re-stamps the frame cryptors of already-published local tracks on the RTC thread whenever the index changes, and stamps new senders at creation. Receivers are unaffected: they read the index from each incoming frame. Cryptor map iteration is synchronized, and a serialized dispatch that re-reads the latest index prevents overlapping rotations from leaving senders stale. Behavior change: in non-shared key mode setKey() no longer moves the sender index, since the key may belong to a remote participant. Use setCurrentKeyIndex() to switch the local one. Custom KeyProvider implementations opt into live re-pointing by implementing KeyIndexObservable.
tangowhisky-dev
requested review from
MaxHeimbrock,
davidliu and
xianshijing-lk
as code owners
October 22, 2026 15:55
🦋 Changeset detectedLatest commit: 50d9894 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
- setCurrentKeyIndex: Math.floorMod -> Int.mod (kotlin stdlib) — floorMod is API 24+ and would NoSuchMethodError on API 21-23 devices during E2EEOptions(sharedKey) setup - Room.e2eeOptions KDoc: short shared-key rotation example covering setCurrentKeyIndex and the KeyIndexObservable opt-in for custom providers
Author
|
@davidliu can you please look into this. Merging it would remove issues associated with E2EE key rotations. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Supersedes #1039 — ports the approach merged in client-sdk-swift#1157 to Android.
Problem
addRtpSenderstamps a sender'sFrameCryptor.keyIndexonce at creation and never updates it. Apps that rotate keys into different key-ring slots (e.g. per-epoch MLS key rings in E2EE deployments) can update live data packets viasetSharedKey(key, index), but media senders keep stamping the old index — receivers hitMISSING_KEYand drop frames. There is no public API to re-point live senders.Approach
Mirrors the Swift design rather than adding a
setKeyIndex(participant)API (whose identity parameter let a remote identity redirect local encryption — the review concern on the earlier Swift PR #1156).KeyIndexObservable— new opt-in contract forKeyProviders that track the local encryption index:BaseKeyProviderimplements it —currentKeyIndexis the single source of truth:setSharedKey(key, index)moves it (parity with JS SDKsetSharedKeybehavior merged in client-sdk-js#1830/#1831)setCurrentKeyIndex(index)exposes it directly (ring-size modulo)getLatestKeyIndex()returns it — senders stamp at creation, data packets pick it up per-sendE2EEManagersubscribes internally and re-stamps the frame cryptors of already-published local tracks on the RTC thread (viaexecuteOnRTCThread, honoring the SDK's threading rule). Receivers are untouched — they read the index from each frame's trailer.Behavior change
In non-shared key mode,
setKey()no longer moves the sender index — the key may belong to a remote participant, so it must not redirect local encryption. Apps switching the local index should callsetCurrentKeyIndex(). This matches the Swift change.Custom
KeyProviderimplementations (e.g. ones that bypassBaseKeyProviderto hand raw key bytes to the RTC provider) opt into live re-pointing by implementingKeyIndexObservable.Test plan
FrameCryptorKeyIndexTest(new, 7 tests): shared-key install moves index,setCurrentKeyIndexmodulo wrap, non-sharedsetKeydoes not move index, observer add/remove, new senders stamp current index, existing senders follow changes, receivers not re-stampede2eetests pass (DataPacketCryptorMockE2ETest,DataTrackCryptorTest):livekit-android-sdk:detektRelease,spotlessCheckclean