Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Don't reuse backup versions
Browse files Browse the repository at this point in the history
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 element-hq/element-web#7448
  • Loading branch information
dbkr committed Oct 5, 2018
1 parent bc74925 commit 497444f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions synapse/storage/e2e_room_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def delete_e2e_room_keys(
@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()
Expand Down Expand Up @@ -226,6 +227,7 @@ def _get_e2e_room_keys_version_info_txn(txn):
keyvalues={
"user_id": user_id,
"version": this_version,
"deleted": 0,
},
retcols=(
"version",
Expand Down Expand Up @@ -300,13 +302,16 @@ def _delete_e2e_room_keys_version_txn(txn):
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(
Expand Down
3 changes: 2 additions & 1 deletion synapse/storage/schema/delta/51/e2e_room_keys.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ CREATE TABLE e2e_room_keys_versions (
user_id TEXT NOT NULL,
version TEXT NOT NULL,
algorithm TEXT NOT NULL,
auth_data TEXT NOT NULL
auth_data TEXT NOT NULL,
deleted SMALLINT DEFAULT 0 NOT NULL
);

CREATE UNIQUE INDEX e2e_room_keys_versions_idx ON e2e_room_keys_versions(user_id, version);

0 comments on commit 497444f

Please sign in to comment.