mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-25 19:49:21 -05:00
504c8f3483
Fixes https://github.com/matrix-org/synapse/issues/7821, introduced in https://github.com/matrix-org/synapse/pull/7639 Turns out PyYAML translates `off` into a `False` boolean if it's unquoted (see https://stackoverflow.com/questions/36463531/pyyaml-automatically-converting-certain-keys-to-boolean-values), which seems to be a liberal interpretation of this bit of the YAML spec: https://yaml.org/spec/1.1/current.html#id864510 An alternative fix would be to implement the solution mentioned in the SO post linked above, but I'm aware it might break existing setups (which might use these values in the configuration file) so it's probably better just to add an extra check for this one. We should be aware that this is a thing for the next times we do that though. I didn't find any other occurrence of this bug elsewhere in the codebase.
86 lines
3.1 KiB
Python
86 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import logging
|
|
|
|
from synapse.api.constants import RoomCreationPreset
|
|
|
|
from ._base import Config, ConfigError
|
|
|
|
logger = logging.Logger(__name__)
|
|
|
|
|
|
class RoomDefaultEncryptionTypes(object):
|
|
"""Possible values for the encryption_enabled_by_default_for_room_type config option"""
|
|
|
|
ALL = "all"
|
|
INVITE = "invite"
|
|
OFF = "off"
|
|
|
|
|
|
class RoomConfig(Config):
|
|
section = "room"
|
|
|
|
def read_config(self, config, **kwargs):
|
|
# Whether new, locally-created rooms should have encryption enabled
|
|
encryption_for_room_type = config.get(
|
|
"encryption_enabled_by_default_for_room_type",
|
|
RoomDefaultEncryptionTypes.OFF,
|
|
)
|
|
if encryption_for_room_type == RoomDefaultEncryptionTypes.ALL:
|
|
self.encryption_enabled_by_default_for_room_presets = [
|
|
RoomCreationPreset.PRIVATE_CHAT,
|
|
RoomCreationPreset.TRUSTED_PRIVATE_CHAT,
|
|
RoomCreationPreset.PUBLIC_CHAT,
|
|
]
|
|
elif encryption_for_room_type == RoomDefaultEncryptionTypes.INVITE:
|
|
self.encryption_enabled_by_default_for_room_presets = [
|
|
RoomCreationPreset.PRIVATE_CHAT,
|
|
RoomCreationPreset.TRUSTED_PRIVATE_CHAT,
|
|
]
|
|
elif (
|
|
encryption_for_room_type == RoomDefaultEncryptionTypes.OFF
|
|
or encryption_for_room_type is False
|
|
):
|
|
# PyYAML translates "off" into False if it's unquoted, so we also need to
|
|
# check for encryption_for_room_type being False.
|
|
self.encryption_enabled_by_default_for_room_presets = []
|
|
else:
|
|
raise ConfigError(
|
|
"Invalid value for encryption_enabled_by_default_for_room_type"
|
|
)
|
|
|
|
def generate_config_section(self, **kwargs):
|
|
return """\
|
|
## Rooms ##
|
|
|
|
# Controls whether locally-created rooms should be end-to-end encrypted by
|
|
# default.
|
|
#
|
|
# Possible options are "all", "invite", and "off". They are defined as:
|
|
#
|
|
# * "all": any locally-created room
|
|
# * "invite": any room created with the "private_chat" or "trusted_private_chat"
|
|
# room creation presets
|
|
# * "off": this option will take no effect
|
|
#
|
|
# The default value is "off".
|
|
#
|
|
# Note that this option will only affect rooms created after it is set. It
|
|
# will also not affect rooms created by other servers.
|
|
#
|
|
#encryption_enabled_by_default_for_room_type: invite
|
|
"""
|