You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

85 lines
3.1 KiB

  1. # Copyright 2020 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import logging
  15. from synapse.api.constants import RoomCreationPreset
  16. from ._base import Config, ConfigError
  17. logger = logging.Logger(__name__)
  18. class RoomDefaultEncryptionTypes:
  19. """Possible values for the encryption_enabled_by_default_for_room_type config option"""
  20. ALL = "all"
  21. INVITE = "invite"
  22. OFF = "off"
  23. class RoomConfig(Config):
  24. section = "room"
  25. def read_config(self, config, **kwargs):
  26. # Whether new, locally-created rooms should have encryption enabled
  27. encryption_for_room_type = config.get(
  28. "encryption_enabled_by_default_for_room_type",
  29. RoomDefaultEncryptionTypes.OFF,
  30. )
  31. if encryption_for_room_type == RoomDefaultEncryptionTypes.ALL:
  32. self.encryption_enabled_by_default_for_room_presets = [
  33. RoomCreationPreset.PRIVATE_CHAT,
  34. RoomCreationPreset.TRUSTED_PRIVATE_CHAT,
  35. RoomCreationPreset.PUBLIC_CHAT,
  36. ]
  37. elif encryption_for_room_type == RoomDefaultEncryptionTypes.INVITE:
  38. self.encryption_enabled_by_default_for_room_presets = [
  39. RoomCreationPreset.PRIVATE_CHAT,
  40. RoomCreationPreset.TRUSTED_PRIVATE_CHAT,
  41. ]
  42. elif (
  43. encryption_for_room_type == RoomDefaultEncryptionTypes.OFF
  44. or encryption_for_room_type is False
  45. ):
  46. # PyYAML translates "off" into False if it's unquoted, so we also need to
  47. # check for encryption_for_room_type being False.
  48. self.encryption_enabled_by_default_for_room_presets = []
  49. else:
  50. raise ConfigError(
  51. "Invalid value for encryption_enabled_by_default_for_room_type"
  52. )
  53. def generate_config_section(self, **kwargs):
  54. return """\
  55. ## Rooms ##
  56. # Controls whether locally-created rooms should be end-to-end encrypted by
  57. # default.
  58. #
  59. # Possible options are "all", "invite", and "off". They are defined as:
  60. #
  61. # * "all": any locally-created room
  62. # * "invite": any room created with the "private_chat" or "trusted_private_chat"
  63. # room creation presets
  64. # * "off": this option will take no effect
  65. #
  66. # The default value is "off".
  67. #
  68. # Note that this option will only affect rooms created after it is set. It
  69. # will also not affect rooms created by other servers.
  70. #
  71. #encryption_enabled_by_default_for_room_type: invite
  72. """