This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Include cross-signing signatures when syncing remote devices for the first time #11234
Merged
+277
−86
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a1a07c4
Factor out 'do_remote_query'
erikjohnston 93f1892
Add cross signing keys to result
erikjohnston b5e5a69
Add test
erikjohnston ec41579
Newsfile
erikjohnston 8fe1670
Update synapse/handlers/e2e_keys.py
erikjohnston f59ced2
Update docstring
erikjohnston 0d9abc5
Apply suggestions from code review
erikjohnston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix long-standing bug where cross signing keys were not included in the response to `/r0/keys/query` the first time a remote user was queried. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
|
||
from signedjson import key as key, sign as sign | ||
|
||
from twisted.internet import defer | ||
|
||
from synapse.api.constants import RoomEncryptionAlgorithms | ||
from synapse.api.errors import Codes, SynapseError | ||
|
||
|
@@ -630,3 +632,152 @@ def test_upload_signatures(self): | |
], | ||
other_master_key["signatures"][local_user]["ed25519:" + usersigning_pubkey], | ||
) | ||
|
||
def test_query_devices_remote_no_sync(self): | ||
"""Tests that querying keys for a remote user that we don't share a room | ||
with returns the cross signing keys correctly. | ||
""" | ||
|
||
remote_user_id = "@test:other" | ||
local_user_id = "@test:test" | ||
|
||
remote_master_key = "85T7JXPFBAySB/jwby4S3lBPTqY3+Zg53nYuGmu1ggY" | ||
remote_self_signing_key = "QeIiFEjluPBtI7WQdG365QKZcFs9kqmHir6RBD0//nQ" | ||
|
||
self.hs.get_federation_client().query_client_keys = mock.Mock( | ||
return_value=defer.succeed( | ||
anoadragon453 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
"device_keys": {remote_user_id: {}}, | ||
"master_keys": { | ||
remote_user_id: { | ||
"user_id": remote_user_id, | ||
"usage": ["master"], | ||
"keys": {"ed25519:" + remote_master_key: remote_master_key}, | ||
}, | ||
}, | ||
"self_signing_keys": { | ||
remote_user_id: { | ||
"user_id": remote_user_id, | ||
"usage": ["self_signing"], | ||
"keys": { | ||
"ed25519:" | ||
+ remote_self_signing_key: remote_self_signing_key | ||
}, | ||
} | ||
}, | ||
} | ||
) | ||
) | ||
|
||
e2e_handler = self.hs.get_e2e_keys_handler() | ||
|
||
query_result = self.get_success( | ||
e2e_handler.query_devices( | ||
{ | ||
"device_keys": {remote_user_id: []}, | ||
}, | ||
timeout=10, | ||
from_user_id=local_user_id, | ||
from_device_id="some_device_id", | ||
) | ||
) | ||
|
||
self.assertEqual(query_result["failures"], {}) | ||
self.assertEqual( | ||
query_result["master_keys"], | ||
{ | ||
remote_user_id: { | ||
"user_id": remote_user_id, | ||
"usage": ["master"], | ||
"keys": {"ed25519:" + remote_master_key: remote_master_key}, | ||
}, | ||
}, | ||
) | ||
self.assertEqual( | ||
query_result["self_signing_keys"], | ||
{ | ||
remote_user_id: { | ||
"user_id": remote_user_id, | ||
"usage": ["self_signing"], | ||
"keys": { | ||
"ed25519:" + remote_self_signing_key: remote_self_signing_key | ||
}, | ||
} | ||
}, | ||
) | ||
|
||
def test_query_devices_remote_sync(self): | ||
"""Tests that querying keys for a remote user that we share a room with, | ||
but haven't yet fetched the keys for, returns the cross signing keys | ||
correctly. | ||
""" | ||
|
||
remote_user_id = "@test:other" | ||
local_user_id = "@test:test" | ||
|
||
self.store.get_rooms_for_user = mock.Mock( | ||
return_value=defer.succeed({"some_room_id"}) | ||
) | ||
|
||
remote_master_key = "85T7JXPFBAySB/jwby4S3lBPTqY3+Zg53nYuGmu1ggY" | ||
remote_self_signing_key = "QeIiFEjluPBtI7WQdG365QKZcFs9kqmHir6RBD0//nQ" | ||
|
||
self.hs.get_federation_client().query_user_devices = mock.Mock( | ||
return_value=defer.succeed( | ||
{ | ||
"user_id": remote_user_id, | ||
"stream_id": 1, | ||
"devices": [], | ||
"master_key": { | ||
"user_id": remote_user_id, | ||
"usage": ["master"], | ||
"keys": {"ed25519:" + remote_master_key: remote_master_key}, | ||
}, | ||
"self_signing_key": { | ||
"user_id": remote_user_id, | ||
"usage": ["self_signing"], | ||
"keys": { | ||
"ed25519:" | ||
+ remote_self_signing_key: remote_self_signing_key | ||
}, | ||
}, | ||
} | ||
) | ||
) | ||
|
||
e2e_handler = self.hs.get_e2e_keys_handler() | ||
|
||
query_result = self.get_success( | ||
e2e_handler.query_devices( | ||
{ | ||
"device_keys": {remote_user_id: []}, | ||
}, | ||
timeout=10, | ||
from_user_id=local_user_id, | ||
from_device_id="some_device_id", | ||
) | ||
) | ||
|
||
self.assertEqual(query_result["failures"], {}) | ||
self.assertEqual( | ||
query_result["master_keys"], | ||
{ | ||
remote_user_id: { | ||
"user_id": remote_user_id, | ||
"usage": ["master"], | ||
"keys": {"ed25519:" + remote_master_key: remote_master_key}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems odd to me that we duplicate key contents here, but that does seem to be what the example spec says for the most part: https://spec.matrix.org/unstable/server-server-api/#get_matrixfederationv1userdevicesuserid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷 |
||
} | ||
}, | ||
) | ||
self.assertEqual( | ||
query_result["self_signing_keys"], | ||
{ | ||
remote_user_id: { | ||
"user_id": remote_user_id, | ||
"usage": ["self_signing"], | ||
"keys": { | ||
"ed25519:" + remote_self_signing_key: remote_self_signing_key | ||
}, | ||
} | ||
}, | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is an out parameter? Feels a bit icky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, yes. The alternative is to return a bunch of dicts, but that is then a bit convoluted to handle when using
defer.gatherResults
. I mean its fine, but I didn't really want to rewrite it too much