mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Fix a few embarrassing bugs with device list updates
This commit is contained in:
parent
9540d704e0
commit
f23fd5f822
1 changed files with 14 additions and 8 deletions
|
@ -3588,25 +3588,31 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query
|
||||||
updateToWrite.self_signing_keys = update.self_signing_keys;
|
updateToWrite.self_signing_keys = update.self_signing_keys;
|
||||||
updateToWrite.user_signing_keys = update.user_signing_keys;
|
updateToWrite.user_signing_keys = update.user_signing_keys;
|
||||||
|
|
||||||
// If we have keys for the device already, only update the signatures.
|
auto oldDeviceKeys = std::move(updateToWrite.device_keys);
|
||||||
|
updateToWrite.device_keys.clear();
|
||||||
|
|
||||||
|
// Don't insert keys, which we have seen once already
|
||||||
for (const auto &[device_id, device_keys] : update.device_keys) {
|
for (const auto &[device_id, device_keys] : update.device_keys) {
|
||||||
if (updateToWrite.device_keys.count(device_id) &&
|
if (oldDeviceKeys.count(device_id) &&
|
||||||
updateToWrite.device_keys.at(device_id).keys ==
|
oldDeviceKeys.at(device_id).keys == device_keys.keys) {
|
||||||
device_keys.keys) {
|
// this is safe, since the keys are the same
|
||||||
updateToWrite.device_keys.at(device_id).signatures =
|
updateToWrite.device_keys[device_id] = device_keys;
|
||||||
device_keys.signatures;
|
|
||||||
} else {
|
} else {
|
||||||
bool keyReused = false;
|
bool keyReused = false;
|
||||||
for (const auto &[key_id, key] : device_keys.keys) {
|
for (const auto &[key_id, key] : device_keys.keys) {
|
||||||
(void)key_id;
|
(void)key_id;
|
||||||
if (updateToWrite.seen_device_keys.count(key)) {
|
if (updateToWrite.seen_device_keys.count(key)) {
|
||||||
|
nhlog::crypto()->warn(
|
||||||
|
"Key '{}' reused by ({}: {})",
|
||||||
|
key,
|
||||||
|
user,
|
||||||
|
device_id);
|
||||||
keyReused = true;
|
keyReused = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!updateToWrite.device_keys.count(device_id) &&
|
if (!keyReused && !oldDeviceKeys.count(device_id))
|
||||||
!keyReused)
|
|
||||||
updateToWrite.device_keys[device_id] = device_keys;
|
updateToWrite.device_keys[device_id] = device_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue