summary refs log tree commit diff
path: root/synapse/rest
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2019-05-22 16:41:24 -0400
committerHubert Chathi <hubert@uhoreg.ca>2019-09-04 20:02:56 -0400
commit4bb454478470c6b707d33292113ac3a23010db8b (patch)
tree7fbfb83aaf491a6b0f5f2ead8e56e3d4b491a072 /synapse/rest
parentadd user signature stream change cache to slaved device store (diff)
downloadsynapse-4bb454478470c6b707d33292113ac3a23010db8b.tar.xz
implement device signature uploading/fetching
Diffstat (limited to 'synapse/rest')
-rw-r--r--synapse/rest/client/v2_alpha/keys.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/synapse/rest/client/v2_alpha/keys.py b/synapse/rest/client/v2_alpha/keys.py
index 151a70d449..5c288d48b7 100644
--- a/synapse/rest/client/v2_alpha/keys.py
+++ b/synapse/rest/client/v2_alpha/keys.py
@@ -277,9 +277,59 @@ class SigningKeyUploadServlet(RestServlet):
         return (200, result)
 
 
+class SignaturesUploadServlet(RestServlet):
+    """
+    POST /keys/signatures/upload HTTP/1.1
+    Content-Type: application/json
+
+    {
+      "@alice:example.com": {
+        "<device_id>": {
+          "user_id": "<user_id>",
+          "device_id": "<device_id>",
+          "algorithms": [
+            "m.olm.curve25519-aes-sha256",
+            "m.megolm.v1.aes-sha"
+          ],
+          "keys": {
+            "<algorithm>:<device_id>": "<key_base64>",
+          },
+          "signatures": {
+            "<signing_user_id>": {
+              "<algorithm>:<signing_key_base64>": "<signature_base64>>"
+            }
+          }
+        }
+      }
+    }
+    """
+    PATTERNS = client_v2_patterns("/keys/signatures/upload$")
+
+    def __init__(self, hs):
+        """
+        Args:
+            hs (synapse.server.HomeServer): server
+        """
+        super(SignaturesUploadServlet, self).__init__()
+        self.auth = hs.get_auth()
+        self.e2e_keys_handler = hs.get_e2e_keys_handler()
+
+    @defer.inlineCallbacks
+    def on_POST(self, request):
+        requester = yield self.auth.get_user_by_req(request, allow_guest=True)
+        user_id = requester.user.to_string()
+        body = parse_json_object_from_request(request)
+
+        result = yield self.e2e_keys_handler.upload_signatures_for_device_keys(
+            user_id, body
+        )
+        defer.returnValue((200, result))
+
+
 def register_servlets(hs, http_server):
     KeyUploadServlet(hs).register(http_server)
     KeyQueryServlet(hs).register(http_server)
     KeyChangesServlet(hs).register(http_server)
     OneTimeKeyServlet(hs).register(http_server)
     SigningKeyUploadServlet(hs).register(http_server)
+    SignaturesUploadServlet(hs).register(http_server)