Skip to content

Conversation

@pblazej
Copy link
Contributor

@pblazej pblazej commented Sep 8, 2025

  • Adds data channel encryption based on Add e2ee for data channel messages client-sdk-js#1595
  • Adds currentKey state to BaseKeyProvider
    • It was missing comparing to other platforms, and we cannot explicitly default to 0
  • Adds some integration tests, as most of the crypto stuff is tested by webrtc
    • Existing hi-level tests e.g. data streams will get a sharedKey by default 🎉

Migration/deprecations

  • Replace E2EEOptions with EncryptionOptions (1:1)
  • Add EncryptionType parameter to Room/ParticipantDelegate methods

_state.mutate { $0.connectOptions = connectOptions }
}

await cleanUp()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved due to E2EEManager.cleanUp called after setup

@pblazej pblazej marked this pull request as ready for review September 11, 2025 11:35
@pblazej
Copy link
Contributor Author

pblazej commented Sep 11, 2025

@lukasIO would be nice to perform some x-platform test (proto compatibility)

@pblazej
Copy link
Contributor Author

pblazej commented Sep 11, 2025

@lukasIO as for x-platform test:

  • ratcheting from JS → native works fine after fixing default window size
🆔 CHAT:  Hello new participant participant-qwfdzf1mmbr. This is just an progressively updating chat message from me, participant participant-oghni0gl54h.
🆔 CHAT:  rat1
🆔 CHAT:  rat2
🆔 CHAT:  rat3
  • ratcheting from the native client → JS does not work - tried to listen for KeyProviderEvent.RatchetRequest but nothing...
image

cc @cloudwebrtc maybe it's worth to do another x-check with flutter

@lukasIO
Copy link
Contributor

lukasIO commented Sep 11, 2025

ratcheting from the native client → JS does not work

does audio/video keep working when ratcheting on the native client ?

@pblazej
Copy link
Contributor Author

pblazej commented Sep 11, 2025

ratcheting from the native client → JS does not work

does audio/video keep working when ratcheting on the native client ?

nope, keys get out of sync.

Error encrypting track data: InvalidKey: Decryption failed: The operation failed for an operation-specific reason 

@pblazej
Copy link
Contributor Author

pblazej commented Sep 12, 2025

@lukasIO if you wanna dig deeper, I added one option to the example (2.8.0). Seems like the frame logic may be broken, unrelated to this PR (I haven't tested main tho).

Screenshot 2025-09-12 at 8 22 38 AM

BTW, macOS chat is still using old infra, but you should be able to get there with frame encryption. I can help you real-time if needed.

For me:

  • if JS ratchets, native is able to decrypt, JS is unable
  • if native ratchets, both are unable

so looks like the issue is on JS side (custom logic vs rtc)?

@pblazej
Copy link
Contributor Author

pblazej commented Sep 12, 2025

Looks like the above behavior is by design, for the shared key it should still be: public let defaultRatchetWindowSize: Int32 = 0 so no auto-ratcheting.

@pblazej
Copy link
Contributor Author

pblazej commented Sep 12, 2025

Ended up reverting that [extended ratchet window] ⬆️

delegates.notify {
$0.dataChannel(self, didReceiveDataPacket: dataPacket)
if let encryptedPacket = dataPacket.encryptedPacketOrNil,
let e2eeManager, e2eeManager.isDataChannelEncryptionEnabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decrypting should also work when data channel encryption is not explicitly enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought about that, yep it makes more sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6070ec2

It does not apply to situations where e2ee is explicitly disabled (no options passed).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Copy link
Contributor

@lukasIO lukasIO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the encryption workflow perspective this looks good to me!


/// Failed to decrypt a data packet when encryption is enabled.
@objc optional
func room(_ room: Room, didFailToDecryptDataWithEror error: LiveKitError)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be good to pull participant id here?

@pblazej
Copy link
Contributor Author

pblazej commented Sep 23, 2025

@hiroshihorie feel free to take a look at the Swift side, I don't see any obvious improvements atm.


var isOpen: Bool { _state.isOpen }

var e2eeManager: E2EEManager?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be weak ? I think the Room holds the instance. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be careful with that - I mean, there's no point in making sure that there's only 1 strong ref... if there's no cycle here... Let's double-check if the DC is deallocated properly (if needed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We gotta move'm to submodules finally, it's hard to track these subtle changes.

@pblazej
Copy link
Contributor Author

pblazej commented Oct 1, 2025

Merging as macOS build must be fixed on main anyway.

@pblazej pblazej merged commit b74ed1f into main Oct 1, 2025
81 of 109 checks passed
@pblazej pblazej deleted the blaze/dc-e2ee branch October 1, 2025 07:09
@hiroshihorie hiroshihorie mentioned this pull request Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants