Ignore `encryption_enabled_by_default_for_room_type` for notices room (#16677)

pull/16703/head
Mathieu Velten 2023-11-28 14:15:26 +01:00 committed by GitHub
parent d199b84006
commit b0ed14d815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

1
changelog.d/16677.misc Normal file
View File

@ -0,0 +1 @@
Ignore `encryption_enabled_by_default_for_room_type` setting when creating server notices room, since the notices will be send unencrypted anyway.

View File

@ -698,6 +698,7 @@ class RoomCreationHandler:
config: JsonDict, config: JsonDict,
ratelimit: bool = True, ratelimit: bool = True,
creator_join_profile: Optional[JsonDict] = None, creator_join_profile: Optional[JsonDict] = None,
ignore_forced_encryption: bool = False,
) -> Tuple[str, Optional[RoomAlias], int]: ) -> Tuple[str, Optional[RoomAlias], int]:
"""Creates a new room. """Creates a new room.
@ -714,6 +715,8 @@ class RoomCreationHandler:
derived from the user's profile. If set, should contain the derived from the user's profile. If set, should contain the
values to go in the body of the 'join' event (typically values to go in the body of the 'join' event (typically
`avatar_url` and/or `displayname`. `avatar_url` and/or `displayname`.
ignore_forced_encryption:
Ignore encryption forced by `encryption_enabled_by_default_for_room_type` setting.
Returns: Returns:
A 3-tuple containing: A 3-tuple containing:
@ -1015,6 +1018,7 @@ class RoomCreationHandler:
room_alias: Optional[RoomAlias] = None, room_alias: Optional[RoomAlias] = None,
power_level_content_override: Optional[JsonDict] = None, power_level_content_override: Optional[JsonDict] = None,
creator_join_profile: Optional[JsonDict] = None, creator_join_profile: Optional[JsonDict] = None,
ignore_forced_encryption: bool = False,
) -> Tuple[int, str, int]: ) -> Tuple[int, str, int]:
"""Sends the initial events into a new room. Sends the room creation, membership, """Sends the initial events into a new room. Sends the room creation, membership,
and power level events into the room sequentially, then creates and batches up the and power level events into the room sequentially, then creates and batches up the
@ -1049,6 +1053,8 @@ class RoomCreationHandler:
creator_join_profile: creator_join_profile:
Set to override the displayname and avatar for the creating Set to override the displayname and avatar for the creating
user in this room. user in this room.
ignore_forced_encryption:
Ignore encryption forced by `encryption_enabled_by_default_for_room_type` setting.
Returns: Returns:
A tuple containing the stream ID, event ID and depth of the last A tuple containing the stream ID, event ID and depth of the last
@ -1251,7 +1257,7 @@ class RoomCreationHandler:
) )
events_to_send.append((event, context)) events_to_send.append((event, context))
if config["encrypted"]: if config["encrypted"] and not ignore_forced_encryption:
encryption_event, encryption_context = await create_event( encryption_event, encryption_context = await create_event(
EventTypes.RoomEncryption, EventTypes.RoomEncryption,
{"algorithm": RoomEncryptionAlgorithms.DEFAULT}, {"algorithm": RoomEncryptionAlgorithms.DEFAULT},

View File

@ -178,6 +178,8 @@ class ServerNoticesManager:
"avatar_url": self._config.servernotices.server_notices_mxid_avatar_url, "avatar_url": self._config.servernotices.server_notices_mxid_avatar_url,
} }
# `ignore_forced_encryption` is used to bypass `encryption_enabled_by_default_for_room_type`
# setting if it set, since the server notices will not be encrypted anyway.
room_id, _, _ = await self._room_creation_handler.create_room( room_id, _, _ = await self._room_creation_handler.create_room(
requester, requester,
config={ config={
@ -187,6 +189,7 @@ class ServerNoticesManager:
}, },
ratelimit=False, ratelimit=False,
creator_join_profile=join_profile, creator_join_profile=join_profile,
ignore_forced_encryption=True,
) )
self.maybe_get_notice_room_for_user.invalidate((user_id,)) self.maybe_get_notice_room_for_user.invalidate((user_id,))