Skip to content

Commit 9964447

Browse files
committed
encryption: add ability to control rotation settings
Signed-off-by: Sumner Evans <[email protected]>
1 parent 1f89639 commit 9964447

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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)