summary refs log tree commit diff
path: root/synapse/crypto/event_signing.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-11-07 11:36:40 +0000
committerErik Johnston <erik@matrix.org>2014-11-07 11:37:06 +0000
commit97a096b507b92d70a2e07d49122b4f5d93b7dac4 (patch)
tree92ce0649cbe7323088ec845f5050af460f37423d /synapse/crypto/event_signing.py
parentReturn auth chain when handling send_join (diff)
downloadsynapse-97a096b507b92d70a2e07d49122b4f5d93b7dac4.tar.xz
Add hash of current state to events
Diffstat (limited to '')
-rw-r--r--synapse/crypto/event_signing.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/synapse/crypto/event_signing.py b/synapse/crypto/event_signing.py
index de5d2e7465..7d800615fe 100644
--- a/synapse/crypto/event_signing.py
+++ b/synapse/crypto/event_signing.py
@@ -45,7 +45,7 @@ def check_event_content_hash(event, hash_algorithm=hashlib.sha256):
 
 def _compute_content_hash(event, hash_algorithm):
     event_json = event.get_full_dict()
-    #TODO: We need to sign the JSON that is going out via fedaration.
+    # TODO: We need to sign the JSON that is going out via fedaration.
     event_json.pop("age_ts", None)
     event_json.pop("unsigned", None)
     event_json.pop("signatures", None)
@@ -81,6 +81,15 @@ def compute_event_signature(event, signature_name, signing_key):
 
 def add_hashes_and_signatures(event, signature_name, signing_key,
                               hash_algorithm=hashlib.sha256):
+    if hasattr(event, "old_state_events"):
+        state_json_bytes = encode_canonical_json(
+            [e.event_id for e in event.old_state_events.values()]
+        )
+        hashed = hash_algorithm(state_json_bytes)
+        event.state_hash = {
+            hashed.name: encode_base64(hashed.digest())
+        }
+
     hashed = _compute_content_hash(event, hash_algorithm=hash_algorithm)
 
     if not hasattr(event, "hashes"):