forked from MirrorHub/synapse
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
This commit is contained in:
parent
bc74925c5b
commit
497444f1fd
2 changed files with 9 additions and 3 deletions
|
@ -193,7 +193,8 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_current_version(txn, user_id):
|
def _get_current_version(txn, user_id):
|
||||||
txn.execute(
|
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,)
|
(user_id,)
|
||||||
)
|
)
|
||||||
row = txn.fetchone()
|
row = txn.fetchone()
|
||||||
|
@ -226,6 +227,7 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
||||||
keyvalues={
|
keyvalues={
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"version": this_version,
|
"version": this_version,
|
||||||
|
"deleted": 0,
|
||||||
},
|
},
|
||||||
retcols=(
|
retcols=(
|
||||||
"version",
|
"version",
|
||||||
|
@ -300,13 +302,16 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
||||||
else:
|
else:
|
||||||
this_version = version
|
this_version = version
|
||||||
|
|
||||||
return self._simple_delete_one_txn(
|
return self._simple_update_one_txn(
|
||||||
txn,
|
txn,
|
||||||
table="e2e_room_keys_versions",
|
table="e2e_room_keys_versions",
|
||||||
keyvalues={
|
keyvalues={
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"version": this_version,
|
"version": this_version,
|
||||||
},
|
},
|
||||||
|
updatevalues={
|
||||||
|
"deleted": 1,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.runInteraction(
|
return self.runInteraction(
|
||||||
|
|
|
@ -32,7 +32,8 @@ CREATE TABLE e2e_room_keys_versions (
|
||||||
user_id TEXT NOT NULL,
|
user_id TEXT NOT NULL,
|
||||||
version TEXT NOT NULL,
|
version TEXT NOT NULL,
|
||||||
algorithm 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);
|
CREATE UNIQUE INDEX e2e_room_keys_versions_idx ON e2e_room_keys_versions(user_id, version);
|
||||||
|
|
Loading…
Reference in a new issue