diff options
author | Erik Johnston <erik@matrix.org> | 2016-02-08 16:35:44 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-02-08 16:35:44 +0000 |
commit | f078ecbc8fa47075a155765ea07a2211dbbad86d (patch) | |
tree | ade22f5192dddad3b79fef285bb6397f78035ac5 /synapse/config/key.py | |
parent | Merge pull request #564 from matrix-org/erikj/logcontext (diff) | |
download | synapse-f078ecbc8fa47075a155765ea07a2211dbbad86d.tar.xz |
Derive macaroon_secret_key from signing key.
Unfortunately, there are people that are running synapse without a `macaroon_sercret_key` set. Mandating they set one is a good solution, except that breaking auto upgrades is annoying.
Diffstat (limited to '')
-rw-r--r-- | synapse/config/key.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/synapse/config/key.py b/synapse/config/key.py index ac90cd3fc1..a072aec714 100644 --- a/synapse/config/key.py +++ b/synapse/config/key.py @@ -22,8 +22,14 @@ from signedjson.key import ( read_signing_keys, write_signing_keys, NACL_ED25519 ) from unpaddedbase64 import decode_base64 +from synapse.util.stringutils import random_string_with_symbols import os +import hashlib +import logging + + +logger = logging.getLogger(__name__) class KeyConfig(Config): @@ -40,9 +46,29 @@ class KeyConfig(Config): config["perspectives"] ) - def default_config(self, config_dir_path, server_name, **kwargs): + self.macaroon_secret_key = config.get( + "macaroon_secret_key", self.registration_shared_secret + ) + + if not self.macaroon_secret_key: + # Unfortunately, there are people out there that don't have this + # set. Lets just be "nice" and derive one from their secret key. + logger.warn("Config is missing missing macaroon_secret_key") + seed = self.signing_key[0].seed + self.macaroon_secret_key = hashlib.sha256(seed) + + def default_config(self, config_dir_path, server_name, is_generating_file=False, + **kwargs): base_key_name = os.path.join(config_dir_path, server_name) + + if is_generating_file: + macaroon_secret_key = random_string_with_symbols(50) + else: + macaroon_secret_key = None + return """\ + macaroon_secret_key: "%(macaroon_secret_key)s" + ## Signing Keys ## # Path to the signing key to sign messages with |