Skip to content

FrameCryptor::setKeyIndex() and setEnabled() abort the process: they never send the track sid #311

Open

Description

@mdepinet

This issue was found, verified, and written up by Claude Opus 5.5 (an AI model by Anthropic), working with @mdepinet while moving godot-livekit, which wraps this SDK in a Godot extension, to v1.13.1.

LiveKit C++ SDK Version

v1.13.1 (also main at 2c56945)

Platform

Linux x86_64

OS Version

Ubuntu 24.04.5

Compiler & Version

gcc 13.3.0 (godot-livekit, against the v1.13.1 release package); Chromium's clang 23 (building main from source)

CMake Version

3.29.5

How are you using the SDK?

Other (describe below)

The pre-built release package, linked directly by godot-livekit's SCons build rather than through find_package. Also reproduced with this repo's integration tests, built from main.

Issue Description

Calling setKeyIndex() or setEnabled() on an E2EEManager::FrameCryptor aborts the process:

thread '<unnamed>' panicked at livekit-ffi/src/room_apis/server/requests.rs:760:58:
called `Result::unwrap()` on an `Err` value: ""

The FFI's FrameCryptorSetKeyIndexRequest and FrameCryptorSetEnabledRequest both require a track_sid, which the FFI uses to find the cryptor. But FrameCryptor never sends one (src/e2ee.cpp):

void E2EEManager::FrameCryptor::setKeyIndex(int key_index) {
  proto::FfiRequest req;
  req.mutable_e2ee()->set_room_handle(room_handle_);
  req.mutable_e2ee()->mutable_cryptor_set_key_index()->set_participant_identity(participant_identity_);
  req.mutable_e2ee()->mutable_cryptor_set_key_index()->set_key_index(key_index);
  FfiClient::instance().sendRequest(req);
}

It can't, since it doesn't keep the track sid: frameCryptors() drops the track_sid that each FFI FrameCryptor carries. The FFI then panics converting the empty sid (request.track_sid.try_into().unwrap()), which aborts the process. Sending the sids of the participant's tracks fixes it: #312

Expected: the cryptor switches to the new key index (or is enabled/disabled), and frameCryptors() reports the change.

Actual: the process aborts.

Steps to Reproduce

livekit::RoomOptions options;
options.encryption = livekit::E2EEOptions{};
options.encryption->key_provider_options.shared_key = std::vector<std::uint8_t>{'k', 'e', 'y'};
livekit::Room room;
room.connect(url, token, options);
auto source = std::make_shared<livekit::AudioSource>(48000, 1, 0);
auto track = room.localParticipant().lock()->publishAudioTrack("audio", source, livekit::TrackSource::SOURCE_MICROPHONE);
for (auto& cryptor : room.e2eeManager().lock()->frameCryptors()) {
  cryptor.setKeyIndex(1); // aborts
}

Logs

[ RUN      ] E2EEIntegrationTest.FrameCryptorSettersApplyToItsTrack

thread '<unnamed>' panicked at livekit-ffi/src/room_apis/server/requests.rs:760:58:
called `Result::unwrap()` on an `Err` value: ""
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted (core dumped)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions