mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
only save remote cross-signing keys if they're different from the current ones (#9634)
Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
This commit is contained in:
parent
ad721fc559
commit
73dbce5523
1
changelog.d/9634.misc
Normal file
1
changelog.d/9634.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Only save remote cross-signing and device keys if they're different from the current ones.
|
@ -907,6 +907,7 @@ class DeviceListUpdater:
|
|||||||
master_key = result.get("master_key")
|
master_key = result.get("master_key")
|
||||||
self_signing_key = result.get("self_signing_key")
|
self_signing_key = result.get("self_signing_key")
|
||||||
|
|
||||||
|
ignore_devices = False
|
||||||
# If the remote server has more than ~1000 devices for this user
|
# If the remote server has more than ~1000 devices for this user
|
||||||
# we assume that something is going horribly wrong (e.g. a bot
|
# we assume that something is going horribly wrong (e.g. a bot
|
||||||
# that logs in and creates a new device every time it tries to
|
# that logs in and creates a new device every time it tries to
|
||||||
@ -925,6 +926,12 @@ class DeviceListUpdater:
|
|||||||
len(devices),
|
len(devices),
|
||||||
)
|
)
|
||||||
devices = []
|
devices = []
|
||||||
|
ignore_devices = True
|
||||||
|
else:
|
||||||
|
cached_devices = await self.store.get_cached_devices_for_user(user_id)
|
||||||
|
if cached_devices == {d["device_id"]: d for d in devices}:
|
||||||
|
devices = []
|
||||||
|
ignore_devices = True
|
||||||
|
|
||||||
for device in devices:
|
for device in devices:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@ -934,7 +941,10 @@ class DeviceListUpdater:
|
|||||||
stream_id,
|
stream_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.store.update_remote_device_list_cache(user_id, devices, stream_id)
|
if not ignore_devices:
|
||||||
|
await self.store.update_remote_device_list_cache(
|
||||||
|
user_id, devices, stream_id
|
||||||
|
)
|
||||||
device_ids = [device["device_id"] for device in devices]
|
device_ids = [device["device_id"] for device in devices]
|
||||||
|
|
||||||
# Handle cross-signing keys.
|
# Handle cross-signing keys.
|
||||||
@ -945,6 +955,7 @@ class DeviceListUpdater:
|
|||||||
)
|
)
|
||||||
device_ids = device_ids + cross_signing_device_ids
|
device_ids = device_ids + cross_signing_device_ids
|
||||||
|
|
||||||
|
if device_ids:
|
||||||
await self.device_handler.notify_device_update(user_id, device_ids)
|
await self.device_handler.notify_device_update(user_id, device_ids)
|
||||||
|
|
||||||
# We clobber the seen updates since we've re-synced from a given
|
# We clobber the seen updates since we've re-synced from a given
|
||||||
@ -973,14 +984,17 @@ class DeviceListUpdater:
|
|||||||
"""
|
"""
|
||||||
device_ids = []
|
device_ids = []
|
||||||
|
|
||||||
if master_key:
|
current_keys_map = await self.store.get_e2e_cross_signing_keys_bulk([user_id])
|
||||||
|
current_keys = current_keys_map.get(user_id) or {}
|
||||||
|
|
||||||
|
if master_key and master_key != current_keys.get("master"):
|
||||||
await self.store.set_e2e_cross_signing_key(user_id, "master", master_key)
|
await self.store.set_e2e_cross_signing_key(user_id, "master", master_key)
|
||||||
_, verify_key = get_verify_key_from_cross_signing_key(master_key)
|
_, verify_key = get_verify_key_from_cross_signing_key(master_key)
|
||||||
# verify_key is a VerifyKey from signedjson, which uses
|
# verify_key is a VerifyKey from signedjson, which uses
|
||||||
# .version to denote the portion of the key ID after the
|
# .version to denote the portion of the key ID after the
|
||||||
# algorithm and colon, which is the device ID
|
# algorithm and colon, which is the device ID
|
||||||
device_ids.append(verify_key.version)
|
device_ids.append(verify_key.version)
|
||||||
if self_signing_key:
|
if self_signing_key and self_signing_key != current_keys.get("self_signing"):
|
||||||
await self.store.set_e2e_cross_signing_key(
|
await self.store.set_e2e_cross_signing_key(
|
||||||
user_id, "self_signing", self_signing_key
|
user_id, "self_signing", self_signing_key
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user