mirror of
https://github.com/matrix-org/dendrite
synced 2025-01-05 17:58:42 +00:00
Add MasterKey & SelfSigningKey to update
Avoid panic if signatures are not present
This commit is contained in:
parent
f13ac2a935
commit
2c81b34884
2 changed files with 48 additions and 42 deletions
|
@ -308,8 +308,12 @@ func (a *KeyInternalAPI) PerformUploadDeviceSignatures(ctx context.Context, req
|
||||||
|
|
||||||
// Finally, generate a notification that we updated the signatures.
|
// Finally, generate a notification that we updated the signatures.
|
||||||
for userID := range req.Signatures {
|
for userID := range req.Signatures {
|
||||||
|
masterKey := queryRes.MasterKeys[userID]
|
||||||
|
selfSigningKey := queryRes.SelfSigningKeys[userID]
|
||||||
update := eduserverAPI.CrossSigningKeyUpdate{
|
update := eduserverAPI.CrossSigningKeyUpdate{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
|
MasterKey: &masterKey,
|
||||||
|
SelfSigningKey: &selfSigningKey,
|
||||||
}
|
}
|
||||||
if err := a.Producer.ProduceSigningKeyUpdate(update); err != nil {
|
if err := a.Producer.ProduceSigningKeyUpdate(update); err != nil {
|
||||||
res.Error = &api.KeyError{
|
res.Error = &api.KeyError{
|
||||||
|
|
|
@ -243,49 +243,45 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
||||||
}
|
}
|
||||||
domain := string(serverName)
|
domain := string(serverName)
|
||||||
// query local devices
|
// query local devices
|
||||||
if serverName == a.ThisServer {
|
deviceKeys, err := a.DB.DeviceKeysForUser(ctx, userID, deviceIDs)
|
||||||
deviceKeys, err := a.DB.DeviceKeysForUser(ctx, userID, deviceIDs)
|
if err != nil {
|
||||||
if err != nil {
|
res.Error = &api.KeyError{
|
||||||
res.Error = &api.KeyError{
|
Err: fmt.Sprintf("failed to query local device keys: %s", err),
|
||||||
Err: fmt.Sprintf("failed to query local device keys: %s", err),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
// pull out display names after we have the keys so we handle wildcards correctly
|
|
||||||
var dids []string
|
|
||||||
for _, dk := range deviceKeys {
|
|
||||||
dids = append(dids, dk.DeviceID)
|
|
||||||
}
|
|
||||||
var queryRes userapi.QueryDeviceInfosResponse
|
|
||||||
err = a.UserAPI.QueryDeviceInfos(ctx, &userapi.QueryDeviceInfosRequest{
|
|
||||||
DeviceIDs: dids,
|
|
||||||
}, &queryRes)
|
|
||||||
if err != nil {
|
|
||||||
util.GetLogger(ctx).Warnf("Failed to QueryDeviceInfos for device IDs, display names will be missing")
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.DeviceKeys[userID] == nil {
|
|
||||||
res.DeviceKeys[userID] = make(map[string]json.RawMessage)
|
|
||||||
}
|
|
||||||
for _, dk := range deviceKeys {
|
|
||||||
if len(dk.KeyJSON) == 0 {
|
|
||||||
continue // don't include blank keys
|
|
||||||
}
|
|
||||||
// inject display name if known (either locally or remotely)
|
|
||||||
displayName := dk.DisplayName
|
|
||||||
if queryRes.DeviceInfo[dk.DeviceID].DisplayName != "" {
|
|
||||||
displayName = queryRes.DeviceInfo[dk.DeviceID].DisplayName
|
|
||||||
}
|
|
||||||
dk.KeyJSON, _ = sjson.SetBytes(dk.KeyJSON, "unsigned", struct {
|
|
||||||
DisplayName string `json:"device_display_name,omitempty"`
|
|
||||||
}{displayName})
|
|
||||||
res.DeviceKeys[userID][dk.DeviceID] = dk.KeyJSON
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
domainToDeviceKeys[domain] = make(map[string][]string)
|
|
||||||
domainToDeviceKeys[domain][userID] = append(domainToDeviceKeys[domain][userID], deviceIDs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pull out display names after we have the keys so we handle wildcards correctly
|
||||||
|
var dids []string
|
||||||
|
for _, dk := range deviceKeys {
|
||||||
|
dids = append(dids, dk.DeviceID)
|
||||||
|
}
|
||||||
|
var queryRes userapi.QueryDeviceInfosResponse
|
||||||
|
err = a.UserAPI.QueryDeviceInfos(ctx, &userapi.QueryDeviceInfosRequest{
|
||||||
|
DeviceIDs: dids,
|
||||||
|
}, &queryRes)
|
||||||
|
if err != nil {
|
||||||
|
util.GetLogger(ctx).Warnf("Failed to QueryDeviceInfos for device IDs, display names will be missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.DeviceKeys[userID] == nil {
|
||||||
|
res.DeviceKeys[userID] = make(map[string]json.RawMessage)
|
||||||
|
}
|
||||||
|
for _, dk := range deviceKeys {
|
||||||
|
if len(dk.KeyJSON) == 0 {
|
||||||
|
continue // don't include blank keys
|
||||||
|
}
|
||||||
|
// inject display name if known (either locally or remotely)
|
||||||
|
displayName := dk.DisplayName
|
||||||
|
if queryRes.DeviceInfo[dk.DeviceID].DisplayName != "" {
|
||||||
|
displayName = queryRes.DeviceInfo[dk.DeviceID].DisplayName
|
||||||
|
}
|
||||||
|
dk.KeyJSON, _ = sjson.SetBytes(dk.KeyJSON, "unsigned", struct {
|
||||||
|
DisplayName string `json:"device_display_name,omitempty"`
|
||||||
|
}{displayName})
|
||||||
|
res.DeviceKeys[userID][dk.DeviceID] = dk.KeyJSON
|
||||||
|
}
|
||||||
|
|
||||||
// work out if our cross-signing request for this user was
|
// work out if our cross-signing request for this user was
|
||||||
// satisfied, if not add them to the list of things to fetch
|
// satisfied, if not add them to the list of things to fetch
|
||||||
if _, ok := res.MasterKeys[userID]; !ok {
|
if _, ok := res.MasterKeys[userID]; !ok {
|
||||||
|
@ -326,8 +322,14 @@ func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysReques
|
||||||
if err = json.Unmarshal(key, &deviceKey); err != nil {
|
if err = json.Unmarshal(key, &deviceKey); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if deviceKey.Signatures == nil {
|
||||||
|
deviceKey.Signatures = map[string]map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{}
|
||||||
|
}
|
||||||
for sourceUserID, forSourceUser := range sigMap {
|
for sourceUserID, forSourceUser := range sigMap {
|
||||||
for sourceKeyID, sourceSig := range forSourceUser {
|
for sourceKeyID, sourceSig := range forSourceUser {
|
||||||
|
if _, ok := deviceKey.Signatures[sourceUserID]; !ok {
|
||||||
|
deviceKey.Signatures[sourceUserID] = map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{}
|
||||||
|
}
|
||||||
deviceKey.Signatures[sourceUserID][sourceKeyID] = sourceSig
|
deviceKey.Signatures[sourceUserID][sourceKeyID] = sourceSig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue