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

Commit

Permalink
don't crash if the user doesn't have cross-signing keys
Browse files Browse the repository at this point in the history
  • Loading branch information
uhoreg committed Jul 19, 2019
1 parent 37b622b commit 8a22a9e
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions synapse/storage/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,24 @@ def get_devices_by_remote(self, destination, from_stream_id, limit):
self_signing_key_by_user = {}
for user in users:
cross_signing_key = yield self.get_e2e_cross_signing_key(user, "master")
key_id, verify_key = get_verify_key_from_cross_signing_key(cross_signing_key)
master_key_by_user[user] = {
"key_info": cross_signing_key,
"pubkey": verify_key.version
}
if cross_signing_key:
key_id, verify_key = get_verify_key_from_cross_signing_key(
cross_signing_key
)
master_key_by_user[user] = {
"key_info": cross_signing_key,
"pubkey": verify_key.version
}

cross_signing_key = yield self.get_e2e_cross_signing_key(user, "self_signing")
key_id, verify_key = get_verify_key_from_cross_signing_key(cross_signing_key)
self_signing_key_by_user[user] = {
"key_info": cross_signing_key,
"pubkey": verify_key.version
}
if cross_signing_key:
key_id, verify_key = get_verify_key_from_cross_signing_key(
cross_signing_key
)
self_signing_key_by_user[user] = {
"key_info": cross_signing_key,
"pubkey": verify_key.version
}

# if we have exceeded the limit, we need to exclude any results with the
# same stream_id as the last row.
Expand All @@ -162,8 +168,11 @@ def get_devices_by_remote(self, destination, from_stream_id, limit):
# Stop processing updates
break

if update[1] == master_key_by_user[update[0]]["pubkey"] or \
update[1] == self_signing_key_by_user[update[0]]["pubkey"]:
# skip over cross-signing keys
if (update[0] in master_key_by_user
and update[1] == master_key_by_user[update[0]]["pubkey"]) \
or (update[0] in master_key_by_user
and update[1] == self_signing_key_by_user[update[0]]["pubkey"]):
continue

key = (update[0], update[1])
Expand All @@ -177,11 +186,13 @@ def get_devices_by_remote(self, destination, from_stream_id, limit):
# update list with the master/self-signing key by user maps
cross_signing_keys_by_user = {}
for user_id, device_id, stream in updates:
if device_id == master_key_by_user[user_id]["pubkey"]:
if device_id == master_key_by_user.get(user_id, {}) \
.get("pubkey", None):
result = cross_signing_keys_by_user.setdefault(user_id, {})
result["master_key"] = \
master_key_by_user[user_id]["key_info"]
elif device_id == self_signing_key_by_user[user_id]["pubkey"]:
elif device_id == self_signing_key_by_user.get(user_id, {}) \
.get("pubkey", None):
result = cross_signing_keys_by_user.setdefault(user_id, {})
result["self_signing_key"] = \
self_signing_key_by_user[user_id]["key_info"]
Expand Down

0 comments on commit 8a22a9e

Please sign in to comment.