Skip to content

Commit 31cc967

Browse files
authored
Merge pull request #106 from mautrix/sumner/bri-3628
encryption: add rotation settings and utilities to control them
2 parents fa1514c + 9964447 commit 31cc967

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

mautrix/bridge/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ def do_update(self, helper: ConfigUpdateHelper) -> None:
102102
copy("bridge.management_room_text.additional_help")
103103
copy("bridge.management_room_multiple_messages")
104104

105+
copy("bridge.encryption.allow")
106+
copy("bridge.encryption.default")
107+
copy("bridge.encryption.key_sharing.allow")
108+
copy("bridge.encryption.key_sharing.require_cross_signing")
109+
copy("bridge.encryption.key_sharing.require_verification")
110+
copy("bridge.encryption.rotation.enable_custom")
111+
copy("bridge.encryption.rotation.milliseconds")
112+
copy("bridge.encryption.rotation.messages")
113+
105114
copy("bridge.relay.enabled")
106115
copy_dict("bridge.relay.message_formats", override_existing_map=False)
107116

mautrix/bridge/portal.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
import logging
1515
import time
1616

17-
from mautrix.appservice import DOUBLE_PUPPET_SOURCE_KEY, AppService, IntentAPI
17+
from mautrix.appservice import AppService, IntentAPI
1818
from mautrix.errors import MatrixError, MatrixRequestError, MForbidden, MNotFound
1919
from mautrix.types import (
20+
JSON,
2021
EncryptionAlgorithm,
2122
EventID,
2223
EventType,
@@ -321,6 +322,13 @@ async def check_dm_encryption(self) -> bool | None:
321322
return await self.enable_dm_encryption()
322323
return None
323324

325+
def get_encryption_state_event_json(self) -> JSON:
326+
evt = RoomEncryptionStateEventContent(EncryptionAlgorithm.MEGOLM_V1)
327+
if self.bridge.config["bridge.encryption.rotation.enable_custom"]:
328+
evt.rotation_period_ms = self.bridge.config["bridge.encryption.rotation.milliseconds"]
329+
evt.rotation_period_msgs = self.bridge.config["bridge.encryption.rotation.messages"]
330+
return evt.serialize()
331+
324332
async def enable_dm_encryption(self) -> bool:
325333
self.log.debug("Inviting bridge bot to room for end-to-bridge encryption")
326334
try:
@@ -330,7 +338,7 @@ async def enable_dm_encryption(self) -> bool:
330338
await self.main_intent.send_state_event(
331339
self.mxid,
332340
EventType.ROOM_ENCRYPTION,
333-
RoomEncryptionStateEventContent(EncryptionAlgorithm.MEGOLM_V1),
341+
self.get_encryption_state_event_json(),
334342
)
335343
except Exception:
336344
self.log.warning(f"Failed to enable end-to-bridge encryption", exc_info=True)

0 commit comments

Comments
 (0)