fix: missing null check
It seems `device_keys` in the reply of `/keys/query` is not required. While synapse always sent it, conduit did not, which resulted in an error.
This commit is contained in:
parent
7155500594
commit
56817df437
|
|
@ -1663,74 +1663,77 @@ sort order of ${prevState.sortOrder}. This should never happen...''');
|
||||||
final response = await queryKeys(outdatedLists, timeout: 10000);
|
final response = await queryKeys(outdatedLists, timeout: 10000);
|
||||||
if (!isLogged()) return;
|
if (!isLogged()) return;
|
||||||
|
|
||||||
for (final rawDeviceKeyListEntry in response.deviceKeys.entries) {
|
if (response.deviceKeys != null) {
|
||||||
final userId = rawDeviceKeyListEntry.key;
|
for (final rawDeviceKeyListEntry in response.deviceKeys.entries) {
|
||||||
if (!userDeviceKeys.containsKey(userId)) {
|
final userId = rawDeviceKeyListEntry.key;
|
||||||
_userDeviceKeys[userId] = DeviceKeysList(userId, this);
|
if (!userDeviceKeys.containsKey(userId)) {
|
||||||
}
|
_userDeviceKeys[userId] = DeviceKeysList(userId, this);
|
||||||
final oldKeys =
|
}
|
||||||
Map<String, DeviceKeys>.from(_userDeviceKeys[userId].deviceKeys);
|
final oldKeys = Map<String, DeviceKeys>.from(
|
||||||
_userDeviceKeys[userId].deviceKeys = {};
|
_userDeviceKeys[userId].deviceKeys);
|
||||||
for (final rawDeviceKeyEntry in rawDeviceKeyListEntry.value.entries) {
|
_userDeviceKeys[userId].deviceKeys = {};
|
||||||
final deviceId = rawDeviceKeyEntry.key;
|
for (final rawDeviceKeyEntry
|
||||||
|
in rawDeviceKeyListEntry.value.entries) {
|
||||||
|
final deviceId = rawDeviceKeyEntry.key;
|
||||||
|
|
||||||
// Set the new device key for this device
|
// Set the new device key for this device
|
||||||
final entry = DeviceKeys.fromMatrixDeviceKeys(
|
final entry = DeviceKeys.fromMatrixDeviceKeys(
|
||||||
rawDeviceKeyEntry.value, this, oldKeys[deviceId]?.lastActive);
|
rawDeviceKeyEntry.value, this, oldKeys[deviceId]?.lastActive);
|
||||||
if (entry.isValid) {
|
if (entry.isValid) {
|
||||||
// is this a new key or the same one as an old one?
|
// is this a new key or the same one as an old one?
|
||||||
// better store an update - the signatures might have changed!
|
// better store an update - the signatures might have changed!
|
||||||
if (!oldKeys.containsKey(deviceId) ||
|
if (!oldKeys.containsKey(deviceId) ||
|
||||||
oldKeys[deviceId].ed25519Key == entry.ed25519Key) {
|
oldKeys[deviceId].ed25519Key == entry.ed25519Key) {
|
||||||
if (oldKeys.containsKey(deviceId)) {
|
if (oldKeys.containsKey(deviceId)) {
|
||||||
// be sure to save the verified status
|
// be sure to save the verified status
|
||||||
entry.setDirectVerified(oldKeys[deviceId].directVerified);
|
entry.setDirectVerified(oldKeys[deviceId].directVerified);
|
||||||
entry.blocked = oldKeys[deviceId].blocked;
|
entry.blocked = oldKeys[deviceId].blocked;
|
||||||
entry.validSignatures = oldKeys[deviceId].validSignatures;
|
entry.validSignatures = oldKeys[deviceId].validSignatures;
|
||||||
|
}
|
||||||
|
_userDeviceKeys[userId].deviceKeys[deviceId] = entry;
|
||||||
|
if (deviceId == deviceID &&
|
||||||
|
entry.ed25519Key == fingerprintKey) {
|
||||||
|
// Always trust the own device
|
||||||
|
entry.setDirectVerified(true);
|
||||||
|
}
|
||||||
|
if (database != null) {
|
||||||
|
dbActions.add(() => database.storeUserDeviceKey(
|
||||||
|
id,
|
||||||
|
userId,
|
||||||
|
deviceId,
|
||||||
|
json.encode(entry.toJson()),
|
||||||
|
entry.directVerified,
|
||||||
|
entry.blocked,
|
||||||
|
entry.lastActive.millisecondsSinceEpoch,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else if (oldKeys.containsKey(deviceId)) {
|
||||||
|
// This shouldn't ever happen. The same device ID has gotten
|
||||||
|
// a new public key. So we ignore the update. TODO: ask krille
|
||||||
|
// if we should instead use the new key with unknown verified / blocked status
|
||||||
|
_userDeviceKeys[userId].deviceKeys[deviceId] =
|
||||||
|
oldKeys[deviceId];
|
||||||
}
|
}
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId] = entry;
|
} else {
|
||||||
if (deviceId == deviceID &&
|
Logs().w('Invalid device ${entry.userId}:${entry.deviceId}');
|
||||||
entry.ed25519Key == fingerprintKey) {
|
|
||||||
// Always trust the own device
|
|
||||||
entry.setDirectVerified(true);
|
|
||||||
}
|
|
||||||
if (database != null) {
|
|
||||||
dbActions.add(() => database.storeUserDeviceKey(
|
|
||||||
id,
|
|
||||||
userId,
|
|
||||||
deviceId,
|
|
||||||
json.encode(entry.toJson()),
|
|
||||||
entry.directVerified,
|
|
||||||
entry.blocked,
|
|
||||||
entry.lastActive.millisecondsSinceEpoch,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else if (oldKeys.containsKey(deviceId)) {
|
|
||||||
// This shouldn't ever happen. The same device ID has gotten
|
|
||||||
// a new public key. So we ignore the update. TODO: ask krille
|
|
||||||
// if we should instead use the new key with unknown verified / blocked status
|
|
||||||
_userDeviceKeys[userId].deviceKeys[deviceId] =
|
|
||||||
oldKeys[deviceId];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Logs().w('Invalid device ${entry.userId}:${entry.deviceId}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// delete old/unused entries
|
|
||||||
if (database != null) {
|
|
||||||
for (final oldDeviceKeyEntry in oldKeys.entries) {
|
|
||||||
final deviceId = oldDeviceKeyEntry.key;
|
|
||||||
if (!_userDeviceKeys[userId].deviceKeys.containsKey(deviceId)) {
|
|
||||||
// we need to remove an old key
|
|
||||||
dbActions.add(
|
|
||||||
() => database.removeUserDeviceKey(id, userId, deviceId));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// delete old/unused entries
|
||||||
_userDeviceKeys[userId].outdated = false;
|
if (database != null) {
|
||||||
if (database != null) {
|
for (final oldDeviceKeyEntry in oldKeys.entries) {
|
||||||
dbActions
|
final deviceId = oldDeviceKeyEntry.key;
|
||||||
.add(() => database.storeUserDeviceKeysInfo(id, userId, false));
|
if (!_userDeviceKeys[userId].deviceKeys.containsKey(deviceId)) {
|
||||||
|
// we need to remove an old key
|
||||||
|
dbActions.add(
|
||||||
|
() => database.removeUserDeviceKey(id, userId, deviceId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_userDeviceKeys[userId].outdated = false;
|
||||||
|
if (database != null) {
|
||||||
|
dbActions.add(
|
||||||
|
() => database.storeUserDeviceKeysInfo(id, userId, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// next we parse and persist the cross signing keys
|
// next we parse and persist the cross signing keys
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue