@@ -43,12 +43,8 @@ class DeviceKeyLookupResult:
43
43
44
44
# the key data from e2e_device_keys_json. Typically includes fields like
45
45
# "algorithm", "keys" (including the curve25519 identity key and the ed25519 signing
46
- # key) and "signatures" (a signature of the structure by the ed25519 key)
47
- key_json = attr .ib (type = Optional [str ])
48
-
49
- # cross-signing sigs on this device.
50
- # dict from (signing user_id)->(signing device_id)->sig
51
- signatures = attr .ib (type = Optional [Dict [str , Dict [str , str ]]], factory = dict )
46
+ # key) and "signatures" (a map from (user id) to (key id/device_id) to signature.)
47
+ keys = attr .ib (type = Optional [JsonDict ])
52
48
53
49
54
50
class EndToEndKeyWorkerStore (SQLBaseStore ):
@@ -70,15 +66,9 @@ async def get_e2e_device_keys_for_federation_query(
70
66
for device_id , device in user_devices .items ():
71
67
result = {"device_id" : device_id }
72
68
73
- key_json = device .key_json
74
- if key_json :
75
- result ["keys" ] = db_to_json (key_json )
76
-
77
- if device .signatures :
78
- for sig_user_id , sigs in device .signatures .items ():
79
- result ["keys" ].setdefault ("signatures" , {}).setdefault (
80
- sig_user_id , {}
81
- ).update (sigs )
69
+ keys = device .keys
70
+ if keys :
71
+ result ["keys" ] = keys
82
72
83
73
device_display_name = device .display_name
84
74
if device_display_name :
@@ -114,16 +104,11 @@ async def get_e2e_device_keys_for_cs_api(
114
104
for user_id , device_keys in results .items ():
115
105
rv [user_id ] = {}
116
106
for device_id , device_info in device_keys .items ():
117
- r = db_to_json ( device_info .key_json )
107
+ r = device_info .keys
118
108
r ["unsigned" ] = {}
119
109
display_name = device_info .display_name
120
110
if display_name is not None :
121
111
r ["unsigned" ]["device_display_name" ] = display_name
122
- if device_info .signatures :
123
- for sig_user_id , sigs in device_info .signatures .items ():
124
- r .setdefault ("signatures" , {}).setdefault (
125
- sig_user_id , {}
126
- ).update (sigs )
127
112
rv [user_id ][device_id ] = r
128
113
129
114
return rv
@@ -140,6 +125,9 @@ async def get_e2e_device_keys_and_signatures(
140
125
Any cross-signatures made on the keys by the owner of the device are also
141
126
included.
142
127
128
+ The cross-signatures are added to the `signatures` field within the `keys`
129
+ object in the response.
130
+
143
131
Args:
144
132
query_list: List of pairs of user_ids and device_ids. Device id can be None
145
133
to indicate "all devices for this user"
@@ -170,7 +158,7 @@ async def get_e2e_device_keys_and_signatures(
170
158
(user_id , device_id )
171
159
for user_id , dev in result .items ()
172
160
for device_id , d in dev .items ()
173
- if d is not None
161
+ if d is not None and d . keys is not None
174
162
)
175
163
176
164
for batch in batch_iter (signature_query , 50 ):
@@ -183,8 +171,9 @@ async def get_e2e_device_keys_and_signatures(
183
171
# add each cross-signing signature to the correct device in the result dict.
184
172
for (user_id , key_id , device_id , signature ) in cross_sigs_result :
185
173
target_device_result = result [user_id ][device_id ]
186
- target_device_signatures = target_device_result .signatures
187
-
174
+ target_device_signatures = target_device_result .keys .setdefault (
175
+ "signatures" , {}
176
+ )
188
177
signing_user_signatures = target_device_signatures .setdefault (
189
178
user_id , {}
190
179
)
@@ -240,7 +229,7 @@ def _get_e2e_device_keys_txn(
240
229
if include_deleted_devices :
241
230
deleted_devices .remove ((user_id , device_id ))
242
231
result .setdefault (user_id , {})[device_id ] = DeviceKeyLookupResult (
243
- display_name , key_json
232
+ display_name , db_to_json ( key_json ) if key_json else None
244
233
)
245
234
246
235
if include_deleted_devices :
0 commit comments