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

Commit

Permalink
Support unprefixed versions of fallback key property names. (#11541)
Browse files Browse the repository at this point in the history
  • Loading branch information
uhoreg authored Dec 9, 2021
1 parent b3bcacf commit b47d10d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/11541.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support unprefixed versions of fallback key property names.
4 changes: 3 additions & 1 deletion synapse/handlers/e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ async def upload_keys_for_user(
log_kv(
{"message": "Did not update one_time_keys", "reason": "no keys given"}
)
fallback_keys = keys.get("org.matrix.msc2732.fallback_keys", None)
fallback_keys = keys.get("fallback_keys") or keys.get(
"org.matrix.msc2732.fallback_keys"
)
if fallback_keys and isinstance(fallback_keys, dict):
log_kv(
{
Expand Down
3 changes: 3 additions & 0 deletions synapse/rest/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ async def encode_response(
response[
"org.matrix.msc2732.device_unused_fallback_key_types"
] = sync_result.device_unused_fallback_key_types
response[
"device_unused_fallback_key_types"
] = sync_result.device_unused_fallback_key_types

if joined:
response["rooms"][Membership.JOIN] = joined
Expand Down
30 changes: 25 additions & 5 deletions tests/handlers/test_e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ def test_claim_one_time_key(self):
def test_fallback_key(self):
local_user = "@boris:" + self.hs.hostname
device_id = "xyz"
fallback_key = {"alg1:k1": "key1"}
fallback_key2 = {"alg1:k2": "key2"}
fallback_key = {"alg1:k1": "fallback_key1"}
fallback_key2 = {"alg1:k2": "fallback_key2"}
fallback_key3 = {"alg1:k2": "fallback_key3"}
otk = {"alg1:k2": "key2"}

# we shouldn't have any unused fallback keys yet
Expand All @@ -175,7 +176,7 @@ def test_fallback_key(self):
self.handler.upload_keys_for_user(
local_user,
device_id,
{"org.matrix.msc2732.fallback_keys": fallback_key},
{"fallback_keys": fallback_key},
)
)

Expand Down Expand Up @@ -220,7 +221,7 @@ def test_fallback_key(self):
self.handler.upload_keys_for_user(
local_user,
device_id,
{"org.matrix.msc2732.fallback_keys": fallback_key},
{"fallback_keys": fallback_key},
)
)

Expand All @@ -234,7 +235,7 @@ def test_fallback_key(self):
self.handler.upload_keys_for_user(
local_user,
device_id,
{"org.matrix.msc2732.fallback_keys": fallback_key2},
{"fallback_keys": fallback_key2},
)
)

Expand Down Expand Up @@ -271,6 +272,25 @@ def test_fallback_key(self):
{"failures": {}, "one_time_keys": {local_user: {device_id: fallback_key2}}},
)

# using the unstable prefix should also set the fallback key
self.get_success(
self.handler.upload_keys_for_user(
local_user,
device_id,
{"org.matrix.msc2732.fallback_keys": fallback_key3},
)
)

res = self.get_success(
self.handler.claim_one_time_keys(
{"one_time_keys": {local_user: {device_id: "alg1"}}}, timeout=None
)
)
self.assertEqual(
res,
{"failures": {}, "one_time_keys": {local_user: {device_id: fallback_key3}}},
)

def test_replace_master_key(self):
"""uploading a new signing key should make the old signing key unavailable"""
local_user = "@boris:" + self.hs.hostname
Expand Down

0 comments on commit b47d10d

Please sign in to comment.