Check both directions of changes

This commit is contained in:
Neil Alexander 2022-03-01 10:35:50 +00:00
parent 3788512b0e
commit 812c3605c1
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -192,13 +192,20 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
// Check if anything actually changed compared to what we have in the database.
changed := false
for purpose, keydata := range toStore {
if _, ok := existingKeys[purpose]; !ok {
// A new key purpose has been specified that we didn't know before.
for _, purpose := range []gomatrixserverlib.CrossSigningKeyPurpose{
gomatrixserverlib.CrossSigningKeyPurposeMaster,
gomatrixserverlib.CrossSigningKeyPurposeSelfSigning,
gomatrixserverlib.CrossSigningKeyPurposeUserSigning,
} {
old, gotOld := existingKeys[purpose]
new, gotNew := toStore[purpose]
if gotOld != gotNew {
// A new key purpose has been specified that we didn't know before,
// or one has been removed.
changed = true
break
}
if !bytes.Equal(existingKeys[purpose], keydata) {
if !bytes.Equal(old, new) {
// One of the existing keys for a purpose we already knew about has
// changed.
changed = true