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

Modify StoreKeyFetcher to read from server_keys_json. #15417

Merged
merged 8 commits into from
Apr 20, 2023
2 changes: 1 addition & 1 deletion synapse/rest/key/v2/remote_key_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async def query_keys(
for key_id in key_ids:
store_queries.append((server_name, key_id, None))

cached = await self.store.get_server_keys_json(store_queries)
cached = await self.store.get_server_keys_json_for_remote(store_queries)

json_results: Set[bytes] = set()

Expand Down
4 changes: 3 additions & 1 deletion synapse/storage/databases/main/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,18 @@ async def store_server_keys_json(
desc="store_server_keys_json",
)

async def get_server_keys_json(
async def get_server_keys_json_for_remote(
self, server_keys: Iterable[Tuple[str, Optional[str], Optional[str]]]
) -> Dict[Tuple[str, Optional[str], Optional[str]], List[Dict[str, Any]]]:
"""Retrieve the key json for a list of server_keys and key ids.
If no keys are found for a given server, key_id and source then
that server, key_id, and source triplet entry will be an empty list.
The JSON is returned as a byte array so that it can be efficiently
clokep marked this conversation as resolved.
Show resolved Hide resolved
used in an HTTP response.

Args:
server_keys: List of (server_name, key_id, source) triplets.

Returns:
A mapping from (server_name, key_id, source) triplets to a list of dicts
"""
Expand Down
10 changes: 7 additions & 3 deletions tests/crypto/test_keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ async def get_json(destination: str, path: str, **kwargs: Any) -> JsonDict:
# check that the perspectives store is correctly updated
lookup_triplet = (SERVER_NAME, testverifykey_id, None)
key_json = self.get_success(
self.hs.get_datastores().main.get_server_keys_json([lookup_triplet])
self.hs.get_datastores().main.get_server_keys_json_for_remote([lookup_triplet])
)
res_keys = key_json[lookup_triplet]
self.assertEqual(len(res_keys), 1)
Expand Down Expand Up @@ -582,7 +582,9 @@ def test_get_keys_from_perspectives(self) -> None:
# check that the perspectives store is correctly updated
lookup_triplet = (SERVER_NAME, testverifykey_id, None)
key_json = self.get_success(
self.hs.get_datastores().main.get_server_keys_json([lookup_triplet])
self.hs.get_datastores().main.get_server_keys_json_for_remote(
[lookup_triplet]
)
)
res_keys = key_json[lookup_triplet]
self.assertEqual(len(res_keys), 1)
Expand Down Expand Up @@ -703,7 +705,9 @@ def test_get_perspectives_own_key(self) -> None:
# check that the perspectives store is correctly updated
lookup_triplet = (SERVER_NAME, testverifykey_id, None)
key_json = self.get_success(
self.hs.get_datastores().main.get_server_keys_json([lookup_triplet])
self.hs.get_datastores().main.get_server_keys_json_for_remote(
[lookup_triplet]
)
)
res_keys = key_json[lookup_triplet]
self.assertEqual(len(res_keys), 1)
Expand Down