summary refs log tree commit diff
path: root/synapse/config/key.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-02-09 16:34:15 +0000
committerErik Johnston <erik@matrix.org>2016-02-09 16:34:15 +0000
commit6ad9586c84ed8ea97174195705b68abb4e11ba99 (patch)
treee0b6820e6a1ca2693e898e5f9eedb7243d2b427c /synapse/config/key.py
parentChange a log from debug to info (diff)
parentTypo (diff)
downloadsynapse-6ad9586c84ed8ea97174195705b68abb4e11ba99.tar.xz
Merge pull request #565 from matrix-org/erikj/macaroon_config
Derive macaroon_secret_key from signing key.
Diffstat (limited to 'synapse/config/key.py')
-rw-r--r--synapse/config/key.py28
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