Skip to content

E2EE: EncodeError when connecting with encryption enabled #606

@Uldiniad

Description

@Uldiniad

When connecting with E2EE enabled via E2EEOptions(key_provider_options=KeyProviderOptions(shared_key=...)), the connect call fails with a protobuf EncodeError.

The cause appears to be that key_ring_size and key_derivation_function on the KeyProviderOptions proto message are never populated. They're required fields in the proto2 schema but aren't exposed on the Python KeyProviderOptions dataclass and aren't set in room.py's connect() method.

This affects both the options.e2ee and options.encryption code paths.

We're currently working around this by monkey-patching the FFI request to set defaults before it's sent.

from livekit.rtc._ffi_client import FfiClient
from livekit.rtc._proto import ffi_pb2 as _proto_ffi

_original_ffi_request = FfiClient.request


def _patched_ffi_request(
    self: FfiClient, req: _proto_ffi.FfiRequest
) -> _proto_ffi.FfiResponse:
    if req.HasField("connect"):
        for field_name in ("encryption", "e2ee"):
            if req.connect.options.HasField(field_name):
                kpo = getattr(req.connect.options, field_name).key_provider_options
                if not kpo.key_ring_size:
                    kpo.key_ring_size = 16
                if not kpo.key_derivation_function:
                    kpo.key_derivation_function = 0
    return _original_ffi_request(self, req)


FfiClient.request = _patched_ffi_request  # type: ignore[assignment]

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