fix(e2ee): use set_shared_key for live key rotation updates

When Element Call sees the bot join, it rotates its encryption key
(index 0 → 1). The on_encryption_key callback was calling set_key()
(per-participant) which has no effect in shared-key mode. Switch to
set_shared_key() so the shared-key decryption path stays current when
the caller rotates keys.
This commit is contained in:
Christian Gick
2026-02-22 07:38:06 +02:00
parent 9cf4afc928
commit 65340bf0ee

View File

@@ -116,15 +116,15 @@ class VoiceSession:
self._caller_all_keys[index] = key
logger.info("E2EE key received from %s:%s (index=%d, %d bytes)",
sender, device_id, index, len(key))
# Live-update key provider if already connected
# Live-update shared key when caller rotates (e.g. on bot join) — use
# set_shared_key so the shared-key decryption path stays in sync.
if self.lk_room and hasattr(self.lk_room, 'e2ee_manager'):
try:
kp = self.lk_room.e2ee_manager.key_provider
caller_id = self._caller_identity or f"{sender}:{device_id}"
kp.set_key(caller_id, key, index)
logger.info("Live-set caller key[%d] for %s", index, caller_id)
kp.set_shared_key(key, index)
logger.info("Live-updated shared key[%d] (%d bytes)", index, len(key))
except Exception as e:
logger.warning("Failed to live-set caller key: %s", e)
logger.warning("Failed to live-update shared key: %s", e)
async def _fetch_encryption_key_http(self) -> bytes | None:
"""Fetch encryption key from room timeline (NOT state) via Matrix HTTP API.