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

Commit 2e380f0

Browse files
authored
e2e: ensure we have both master and self-signing key (#8455)
it seems to be possible that only one of them ends up to be cached. when this was the case, the missing one was not fetched via federation, and clients then failed to validate cross-signed devices. Signed-off-by: Jonas Jelten <jj@sft.lol>
1 parent 10f45d8 commit 2e380f0

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

changelog.d/8455.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix fetching of E2E cross signing keys over federation when only one of the master key and device signing key is cached already.

synapse/handlers/e2e_keys.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ async def query_devices(self, query_body, timeout, from_user_id):
129129
if user_id in local_query:
130130
results[user_id] = keys
131131

132+
# Get cached cross-signing keys
133+
cross_signing_keys = await self.get_cross_signing_keys_from_cache(
134+
device_keys_query, from_user_id
135+
)
136+
132137
# Now attempt to get any remote devices from our local cache.
133138
remote_queries_not_in_cache = {}
134139
if remote_queries:
@@ -155,16 +160,28 @@ async def query_devices(self, query_body, timeout, from_user_id):
155160
unsigned["device_display_name"] = device_display_name
156161
user_devices[device_id] = result
157162

163+
# check for missing cross-signing keys.
164+
for user_id in remote_queries.keys():
165+
cached_cross_master = user_id in cross_signing_keys["master_keys"]
166+
cached_cross_selfsigning = (
167+
user_id in cross_signing_keys["self_signing_keys"]
168+
)
169+
170+
# check if we are missing only one of cross-signing master or
171+
# self-signing key, but the other one is cached.
172+
# as we need both, this will issue a federation request.
173+
# if we don't have any of the keys, either the user doesn't have
174+
# cross-signing set up, or the cached device list
175+
# is not (yet) updated.
176+
if cached_cross_master ^ cached_cross_selfsigning:
177+
user_ids_not_in_cache.add(user_id)
178+
179+
# add those users to the list to fetch over federation.
158180
for user_id in user_ids_not_in_cache:
159181
domain = get_domain_from_id(user_id)
160182
r = remote_queries_not_in_cache.setdefault(domain, {})
161183
r[user_id] = remote_queries[user_id]
162184

163-
# Get cached cross-signing keys
164-
cross_signing_keys = await self.get_cross_signing_keys_from_cache(
165-
device_keys_query, from_user_id
166-
)
167-
168185
# Now fetch any devices that we don't have in our cache
169186
@trace
170187
async def do_remote_query(destination):

0 commit comments

Comments
 (0)