room.py 2.9 KB

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