MCPcopy Create free account
hub / github.com/daodst/chat / QueryDeviceKeys

Function QueryDeviceKeys

federationapi/routing/keys.go:39–83  ·  view source on GitHub ↗

QueryDeviceKeys returns device keys for users on this server. https://matrix.org/docs/spec/server_server/latest#post-matrix-federation-v1-user-keys-query

(
	httpReq *http.Request, request *gomatrixserverlib.FederationRequest, keyAPI api.FederationKeyAPI, thisServer gomatrixserverlib.ServerName,
)

Source from the content-addressed store, hash-verified

37// QueryDeviceKeys returns device keys for users on this server.
38// https://matrix.org/docs/spec/server_server/latest#post-matrix-federation-v1-user-keys-query
39func QueryDeviceKeys(
40 httpReq *http.Request, request *gomatrixserverlib.FederationRequest, keyAPI api.FederationKeyAPI, thisServer gomatrixserverlib.ServerName,
41) util.JSONResponse {
42 var qkr queryKeysRequest
43 err := json.Unmarshal(request.Content(), &qkr)
44 if err != nil {
45 return util.JSONResponse{
46 Code: http.StatusBadRequest,
47 JSON: jsonerror.BadJSON("The request body could not be decoded into valid JSON. " + err.Error()),
48 }
49 }
50 // make sure we only query users on our domain
51 for userID := range qkr.DeviceKeys {
52 _, serverName, err := gomatrixserverlib.SplitID('@', userID)
53 if err != nil {
54 delete(qkr.DeviceKeys, userID)
55 continue // ignore invalid users
56 }
57 if serverName != thisServer {
58 delete(qkr.DeviceKeys, userID)
59 continue
60 }
61 }
62
63 var queryRes api.QueryKeysResponse
64 keyAPI.QueryKeys(httpReq.Context(), &api.QueryKeysRequest{
65 UserToDevices: qkr.DeviceKeys,
66 }, &queryRes)
67 if queryRes.Error != nil {
68 util.GetLogger(httpReq.Context()).WithError(queryRes.Error).Error("Failed to QueryKeys")
69 return jsonerror.InternalServerError()
70 }
71 return util.JSONResponse{
72 Code: 200,
73 JSON: struct {
74 DeviceKeys interface{} `json:"device_keys"`
75 MasterKeys interface{} `json:"master_keys"`
76 SelfSigningKeys interface{} `json:"self_signing_keys"`
77 }{
78 queryRes.DeviceKeys,
79 queryRes.MasterKeys,
80 queryRes.SelfSigningKeys,
81 },
82 }
83}
84
85type claimOTKsRequest struct {
86 OneTimeKeys map[string]map[string]string `json:"one_time_keys"`

Callers 1

SetupFunction · 0.85

Calls 3

ContextMethod · 0.80
QueryKeysMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected