summary refs log tree commit diff
path: root/synapse/storage/e2e_room_keys.py
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2018-10-05 15:08:36 +0100
committerDavid Baker <dave@matrix.org>2018-10-05 15:08:36 +0100
commit497444f1fdd2c39906179b1dde8c67415e465398 (patch)
tree8b7a5a70181bc85cf09ca148656056d0d2ac884f /synapse/storage/e2e_room_keys.py
parentWIP e2e key backups (diff)
downloadsynapse-497444f1fdd2c39906179b1dde8c67415e465398.tar.xz
Don't reuse backup versions
Since we don't actually delete the keys, just mark the versions
as deleted in the db rather than actually deleting them, then we
won't reuse versions.

Fixes https://github.com/vector-im/riot-web/issues/7448
Diffstat (limited to 'synapse/storage/e2e_room_keys.py')
-rw-r--r--synapse/storage/e2e_room_keys.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/synapse/storage/e2e_room_keys.py b/synapse/storage/e2e_room_keys.py
index 969f4aef9c..4d439bb164 100644
--- a/synapse/storage/e2e_room_keys.py
+++ b/synapse/storage/e2e_room_keys.py
@@ -193,7 +193,8 @@ class EndToEndRoomKeyStore(SQLBaseStore):
     @staticmethod
     def _get_current_version(txn, user_id):
         txn.execute(
-            "SELECT MAX(version) FROM e2e_room_keys_versions WHERE user_id=?",
+            "SELECT MAX(version) FROM e2e_room_keys_versions "
+            "WHERE user_id=? AND deleted=0",
             (user_id,)
         )
         row = txn.fetchone()
@@ -226,6 +227,7 @@ class EndToEndRoomKeyStore(SQLBaseStore):
                 keyvalues={
                     "user_id": user_id,
                     "version": this_version,
+                    "deleted": 0,
                 },
                 retcols=(
                     "version",
@@ -300,13 +302,16 @@ class EndToEndRoomKeyStore(SQLBaseStore):
             else:
                 this_version = version
 
-            return self._simple_delete_one_txn(
+            return self._simple_update_one_txn(
                 txn,
                 table="e2e_room_keys_versions",
                 keyvalues={
                     "user_id": user_id,
                     "version": this_version,
                 },
+                updatevalues={
+                    "deleted": 1,
+                }
             )
 
         return self.runInteraction(