mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
Expose signatures via /keys/query
This commit is contained in:
parent
9c7305f3d2
commit
3998cb1470
|
|
@ -300,12 +300,38 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
||||||
|
|
||||||
// attempt to satisfy key queries from the local database first as we should get device updates pushed to us
|
// attempt to satisfy key queries from the local database first as we should get device updates pushed to us
|
||||||
domainToDeviceKeys = a.remoteKeysFromDatabase(ctx, res, domainToDeviceKeys)
|
domainToDeviceKeys = a.remoteKeysFromDatabase(ctx, res, domainToDeviceKeys)
|
||||||
if len(domainToDeviceKeys) == 0 && len(domainToCrossSigningKeys) == 0 {
|
if len(domainToDeviceKeys) > 0 || len(domainToCrossSigningKeys) > 0 {
|
||||||
return // nothing to query
|
// perform key queries for remote devices
|
||||||
|
a.queryRemoteKeys(ctx, req.Timeout, res, domainToDeviceKeys, domainToCrossSigningKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform key queries for remote devices
|
// Finally, append signatures that we know about
|
||||||
a.queryRemoteKeys(ctx, req.Timeout, res, domainToDeviceKeys, domainToCrossSigningKeys)
|
// TODO: This is horrible because we need to round-trip the signature from
|
||||||
|
// JSON, add the signatures and marshal it again, for some reason?
|
||||||
|
for userID, forUserID := range res.DeviceKeys {
|
||||||
|
for keyID, key := range forUserID {
|
||||||
|
sigMap, err := a.DB.CrossSigningSigsForTarget(ctx, userID, gomatrixserverlib.KeyID(keyID))
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Errorf("a.DB.CrossSigningSigsForTarget failed")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(sigMap) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var deviceKey gomatrixserverlib.DeviceKeys
|
||||||
|
if err = json.Unmarshal(key, &deviceKey); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for sourceUserID, forSourceUser := range sigMap {
|
||||||
|
for sourceKeyID, sourceSig := range forSourceUser {
|
||||||
|
deviceKey.Signatures[sourceUserID][sourceKeyID] = sourceSig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if js, err := json.Marshal(deviceKey); err == nil {
|
||||||
|
res.DeviceKeys[userID][keyID] = js
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *KeyInternalAPI) remoteKeysFromDatabase(
|
func (a *KeyInternalAPI) remoteKeysFromDatabase(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue