4949
5050class E2eKeysHandler :
5151 def __init__ (self , hs : "HomeServer" ):
52+ self .config = hs .config
5253 self .store = hs .get_datastores ().main
5354 self .federation = hs .get_federation_client ()
5455 self .device_handler = hs .get_device_handler ()
@@ -431,13 +432,17 @@ async def get_cross_signing_keys_from_cache(
431432 @trace
432433 @cancellable
433434 async def query_local_devices (
434- self , query : Mapping [str , Optional [List [str ]]]
435+ self ,
436+ query : Mapping [str , Optional [List [str ]]],
437+ include_displaynames : bool = True ,
435438 ) -> Dict [str , Dict [str , dict ]]:
436439 """Get E2E device keys for local users
437440
438441 Args:
439442 query: map from user_id to a list
440443 of devices to query (None for all devices)
444+ include_displaynames: Whether to include device displaynames in the returned
445+ device details.
441446
442447 Returns:
443448 A map from user_id -> device_id -> device details
@@ -469,7 +474,9 @@ async def query_local_devices(
469474 # make sure that each queried user appears in the result dict
470475 result_dict [user_id ] = {}
471476
472- results = await self .store .get_e2e_device_keys_for_cs_api (local_query )
477+ results = await self .store .get_e2e_device_keys_for_cs_api (
478+ local_query , include_displaynames
479+ )
473480
474481 # Build the result structure
475482 for user_id , device_keys in results .items ():
@@ -482,11 +489,33 @@ async def query_local_devices(
482489 async def on_federation_query_client_keys (
483490 self , query_body : Dict [str , Dict [str , Optional [List [str ]]]]
484491 ) -> JsonDict :
485- """Handle a device key query from a federated server"""
492+ """Handle a device key query from a federated server:
493+
494+ Handles the path: GET /_matrix/federation/v1/users/keys/query
495+
496+ Args:
497+ query_body: The body of the query request. Should contain a key
498+ "device_keys" that map to a dictionary of user ID's -> list of
499+ device IDs. If the list of device IDs is empty, all devices of
500+ that user will be queried.
501+
502+ Returns:
503+ A json dictionary containing the following:
504+ - device_keys: A dictionary containing the requested device information.
505+ - master_keys: An optional dictionary of user ID -> master cross-signing
506+ key info.
507+ - self_signing_key: An optional dictionary of user ID -> self-signing
508+ key info.
509+ """
486510 device_keys_query : Dict [str , Optional [List [str ]]] = query_body .get (
487511 "device_keys" , {}
488512 )
489- res = await self .query_local_devices (device_keys_query )
513+ res = await self .query_local_devices (
514+ device_keys_query ,
515+ include_displaynames = (
516+ self .config .federation .allow_device_name_lookup_over_federation
517+ ),
518+ )
490519 ret = {"device_keys" : res }
491520
492521 # add in the cross-signing keys
0 commit comments