Skip to content

E2EE: allow setting key_ring_size and key_derivation_algorithm#921

Merged
cloudwebrtc merged 6 commits intolivekit:mainfrom
onestacked:EC-compat-changes-webrtc-change
Mar 20, 2026
Merged

E2EE: allow setting key_ring_size and key_derivation_algorithm#921
cloudwebrtc merged 6 commits intolivekit:mainfrom
onestacked:EC-compat-changes-webrtc-change

Conversation

@onestacked
Copy link
Copy Markdown
Contributor

@onestacked onestacked commented Feb 28, 2026

This PR uses this webrtc-sdk PR to configure the KDF, instead of just overwriting the derived key afterwards. This should also now properly support KeyRatcheting.

I've tested this with https://codeberg.org/esoteric_programmer/matrix-jukebox and it is compatible with Element Call.

Fixes: #796

@onestacked
Copy link
Copy Markdown
Contributor Author

Now based on webrtc-sdk/webrtc#224

@onestacked onestacked changed the title E2EE: Alternative implementation: allow setting key_ring_size and key_derivation_function (And add HKDF as a kdf) E2EE: allow setting key_ring_size and key_derivation_function (And add HKDF as a kdf) Mar 6, 2026
@onestacked onestacked changed the title E2EE: allow setting key_ring_size and key_derivation_function (And add HKDF as a kdf) E2EE: allow setting key_ring_size and key_derivation_algorithm Mar 6, 2026
@onestacked
Copy link
Copy Markdown
Contributor Author

webrtc-sdk/webrtc#224 is now merged, this will only need a new webrtc-sdk build and update to that. (once thats done I'll look into why node fails.

@alexander-potemkin
Copy link
Copy Markdown

Please, keep going, @onestacked !! :)

@onestacked
Copy link
Copy Markdown
Contributor Author

onestacked commented Mar 8, 2026

This is mosly waiting for review and the WebRTC build to be done.
From my side there isn'tuch to do anymore, just fixing the CI (which needs something for node) and maybe adding some tests. Most of the CI failures are because this uses a local WebRTC build which of course doesn't exust in CI.

@alexander-potemkin
Copy link
Copy Markdown

@theomonnom , @typester , I hope you would forgive me for pinging you directly. I'm just a person who wants to help a very needed work from @onestacked to make to your product.

@maxinflection
Copy link
Copy Markdown

We've been running a production deployment with an equivalent patch set for about three weeks now — a Matrix bot that joins Element Call rooms via LiveKit, decrypts E2EE audio, and transcribes it. Our patches target the same layers (webrtc C++ → webrtc-sys → livekit crates → livekit-ffi) and the approach is functionally identical: branch on a KeyDerivationAlgorithm enum in DeriveKeys(), call BoringSSL's HKDF() with EVP_sha256(), and thread the option through the Rust/FFI stack.
Can confirm:
• HKDF-SHA256 with salt "LKFrameEncryptionKey" and 128 zero-byte info produces correct AES-128-GCM keys matching Element Call's JS SDK
• Key ratcheting still works correctly when left on PBKDF2 (default path unchanged)
• Tested against Element Call clients on Element Web and Element X

Happy to help test once the new webrtc-sdk release unblocks this. Looking forward to dropping our custom .so build.

@onestacked
Copy link
Copy Markdown
Contributor Author

onestacked commented Mar 12, 2026

Webrtc-sdk has just been rebased to a new upstream release: webrtc-sdk/webrtc#217 so livekit will probably update fairly soon.

@fkwp
Copy link
Copy Markdown

fkwp commented Mar 12, 2026

We've been running a production deployment with an equivalent patch set for about three weeks now — a Matrix bot that joins Element Call rooms via LiveKit, decrypts E2EE audio, and transcribes it. Our patches target the same layers (webrtc C++ → webrtc-sys → livekit crates → livekit-ffi) and the approach is functionally identical: branch on a KeyDerivationAlgorithm enum in DeriveKeys(), call BoringSSL's HKDF() with EVP_sha256(), and thread the option through the Rust/FFI stack. Can confirm: • HKDF-SHA256 with salt "LKFrameEncryptionKey" and 128 zero-byte info produces correct AES-128-GCM keys matching Element Call's JS SDK • Key ratcheting still works correctly when left on PBKDF2 (default path unchanged) • Tested against Element Call clients on Element Web and Element X

Happy to help test once the new webrtc-sdk release unblocks this. Looking forward to dropping our custom .so build.

that's nice @maxinflection that MatrixRTC is getting traction around the matrix rust-sdk. I think the community would be really interested in your project. So yes please share your stuff :-)

@onestacked onestacked force-pushed the EC-compat-changes-webrtc-change branch from a775d90 to 303b040 Compare March 18, 2026 09:08
@onestacked onestacked changed the title E2EE: allow setting key_ring_size and key_derivation_algorithm E2EE: allow setting key_ring_size and key_derivation_algorithm, update webrtc to m144 Mar 18, 2026
@onestacked onestacked force-pushed the EC-compat-changes-webrtc-change branch from 303b040 to 229e2bb Compare March 18, 2026 11:26
@onestacked
Copy link
Copy Markdown
Contributor Author

I'm not sure why the FFI Proto fails on checkout?

I don't think any change should effect this.

@onestacked
Copy link
Copy Markdown
Contributor Author

onestacked commented Mar 18, 2026

Also let me know if you want my PR split, as it now does three two things (key_ring_size and key_derivation_algorithm and webrtc update)

@onestacked onestacked force-pushed the EC-compat-changes-webrtc-change branch from 229e2bb to 6f225c3 Compare March 18, 2026 11:48
@onestacked onestacked force-pushed the EC-compat-changes-webrtc-change branch from 6f225c3 to 6856cd4 Compare March 18, 2026 12:06
@onestacked onestacked changed the title E2EE: allow setting key_ring_size and key_derivation_algorithm, update webrtc to m144 E2EE: allow setting key_ring_size and key_derivation_algorithm Mar 20, 2026
@onestacked onestacked requested a review from cloudwebrtc March 20, 2026 09:18
Copy link
Copy Markdown
Contributor

@cloudwebrtc cloudwebrtc left a comment

Choose a reason for hiding this comment

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

lgtm!

@cloudwebrtc cloudwebrtc merged commit c863be7 into livekit:main Mar 20, 2026
18 of 22 checks passed
@knope-bot knope-bot bot mentioned this pull request Mar 20, 2026
@onestacked onestacked deleted the EC-compat-changes-webrtc-change branch March 20, 2026 10:10
theomonnom pushed a commit that referenced this pull request Mar 23, 2026
> [!IMPORTANT]
> Merging this pull request will create these releases

# libwebrtc 0.3.27 (2026-03-22)
## Features

### E2EE: allow setting key_ring_size and key_derivation_algorithm,
update webrtc to m144

#921 by @onestacked

This PR uses [this webrtc-sdk
PR](webrtc-sdk/webrtc#224) to configure the KDF.

I've tested this with
https://codeberg.org/esoteric_programmer/matrix-jukebox and it is
compatible with Element Call.

Fixed: #796

## Fixes

- Fix H.264 codec matching

### add bounded buffer to audio_stream, and use 10 frames as the default

#945 by @xianshijing-lk

### fix clang build issue from zed patches (#949)

#950 by @cloudwebrtc

* webrtc-sys: Use clang instead of gcc

* Debug CI output for aarch64-linux

* ci: Install lld for aarch64-linux FFI builders

* webrtc-sys: Disable CREL
# livekit 0.7.34 (2026-03-22)
## Features

### E2EE: allow setting key_ring_size and key_derivation_algorithm,
update webrtc to m144

#921 by @onestacked

This PR uses [this webrtc-sdk
PR](webrtc-sdk/webrtc#224) to configure the KDF.

I've tested this with
https://codeberg.org/esoteric_programmer/matrix-jukebox and it is
compatible with Element Call.

Fixed: #796

## Fixes

- Add disconnectReason to Room::close
- End-to-end testing for video streams
- Fix H.264 codec matching

### add bounded buffer to audio_stream, and use 10 frames as the default

#945 by @xianshijing-lk

### fix PC timeout when connecting with can_subscribe=false

#955 by @s-hamdananwar

When a participant connects with `canSubscribe=false` in their token,
the server sends `subscriber_primary=false` in the JoinResponse and does
not send a subscriber offer. This results in `wait_pc_connection` timing
out as it is expecting a subscriber PC even when the publisher PC is
primary. This PR will skip waiting for subscriber PC when
`subscriber_primary=false`.

### Send client os and os_version from rust

#952 by @MaxHeimbrock

Adds [os_info](https://crates.io/crates/os_info) crate as dependency and
sends the data for client connections.
# livekit-ffi 0.12.50 (2026-03-22)
## Features

### E2EE: allow setting key_ring_size and key_derivation_algorithm,
update webrtc to m144

#921 by @onestacked

This PR uses [this webrtc-sdk
PR](webrtc-sdk/webrtc#224) to configure the KDF.

I've tested this with
https://codeberg.org/esoteric_programmer/matrix-jukebox and it is
compatible with Element Call.

Fixed: #796

## Fixes

- Fix H.264 codec matching

### add bounded buffer to audio_stream, and use 10 frames as the default

#945 by @xianshijing-lk

### Send client os and os_version from rust

#952 by @MaxHeimbrock

Adds [os_info](https://crates.io/crates/os_info) crate as dependency and
sends the data for client connections.
# webrtc-sys 0.3.25 (2026-03-22)
## Fixes

- fix: enable AGC2 adaptive digital controller
- Fix H.264 codec matching

### E2EE: allow setting key_ring_size and key_derivation_algorithm,
update webrtc to m144

#921 by @onestacked

This PR uses [this webrtc-sdk
PR](webrtc-sdk/webrtc#224) to configure the KDF.

I've tested this with
https://codeberg.org/esoteric_programmer/matrix-jukebox and it is
compatible with Element Call.

Fixed: #796

### fix clang build issue from zed patches (#949)

#950 by @cloudwebrtc

* webrtc-sys: Use clang instead of gcc

* Debug CI output for aarch64-linux

* ci: Install lld for aarch64-linux FFI builders

* webrtc-sys: Disable CREL
# livekit-datatrack 0.1.1 (2026-03-22)
## Features

- Initial release.
# webrtc-sys-build 0.3.14 (2026-03-22)
## Fixes

### fix: Bump webrtc build to fix build for Android JNI prefixed.

#954 by @cloudwebrtc

### fix clang build issue from zed patches (#949)

#950 by @cloudwebrtc

* webrtc-sys: Use clang instead of gcc

* Debug CI output for aarch64-linux

* ci: Install lld for aarch64-linux FFI builders

* webrtc-sys: Disable CREL
# livekit-protocol 0.7.2 (2026-03-22)
## Fixes

- Add disconnectReason to Room::close
# livekit-api 0.4.16 (2026-03-22)
## Fixes

### Send client os and os_version from rust

#952 by @MaxHeimbrock

Adds [os_info](https://crates.io/crates/os_info) crate as dependency and
sends the data for client connections.

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
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.

E2EE HKDF & keyring_size support

5 participants