Improve fetching of device keys after login

This commit is contained in:
Nicolas Werner 2021-11-08 16:26:16 +01:00
parent acb5ed6160
commit ff560a09f5
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
4 changed files with 23 additions and 6 deletions

View file

@ -4101,10 +4101,11 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query
(void)status;
emit verificationStatusChanged(user);
}
}
} else {
emit verificationStatusChanged(user_id);
}
}
}
void
Cache::markUserKeysOutOfDate(const std::vector<std::string> &user_ids)
@ -4311,9 +4312,10 @@ Cache::markDeviceVerified(const std::string &user_id, const std::string &key)
(void)status;
emit verificationStatusChanged(user);
}
}
} else {
emit verificationStatusChanged(user_id);
}
}
void
Cache::markDeviceUnverified(const std::string &user_id, const std::string &key)

View file

@ -526,6 +526,8 @@ ChatPage::tryInitialSync()
for (const auto &entry : res.one_time_key_counts)
nhlog::net()->info("uploaded {} {} one-time keys", entry.second, entry.first);
cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
startInitialSync();
});
}
@ -1143,7 +1145,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
if (!decrypted.empty()) {
cache::storeSecret(secretName, decrypted);
if (deviceKeys &&
if (deviceKeys && deviceKeys->device_keys.count(http::client()->device_id()) &&
secretName == mtx::secret_storage::secrets::cross_signing_self_signing) {
auto myKey = deviceKeys->device_keys.at(http::client()->device_id());
if (myKey.user_id == http::client()->user_id().to_string() &&

View file

@ -4,6 +4,8 @@
#include "SelfVerificationStatus.h"
#include <QApplication>
#include "Cache_p.h"
#include "ChatPage.h"
#include "Logging.h"
@ -18,12 +20,13 @@
SelfVerificationStatus::SelfVerificationStatus(QObject *o)
: QObject(o)
{
connect(MainWindow::instance(), &MainWindow::reload, this, [this] {
connect(ChatPage::instance(), &ChatPage::contentLoaded, this, [this] {
connect(cache::client(),
&Cache::selfVerificationStatusChanged,
this,
&SelfVerificationStatus::invalidate,
Qt::UniqueConnection);
cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
});
}
@ -268,8 +271,16 @@ SelfVerificationStatus::invalidate()
auto keys = cache::client()->userKeys(http::client()->user_id().to_string());
if (!keys || keys->device_keys.find(http::client()->device_id()) == keys->device_keys.end()) {
QTimer::singleShot(500, [] {
if (keys && (keys->seen_device_ids.count(http::client()->device_id()) ||
keys->seen_device_keys.count(olm::client()->identity_keys().curve25519))) {
emit ChatPage::instance()->dropToLoginPageCb(
tr("Identity key changed. This breaks E2EE, so logging out."));
return;
}
cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
QTimer::singleShot(1'000, [] {
cache::client()->query_keys(http::client()->user_id().to_string(),
[](const UserKeyCache &, mtx::http::RequestErr) {});
});

View file

@ -188,6 +188,7 @@ UserProfile::fetchDeviceList(const QString &userID)
nhlog::net()->warn("failed to query device keys: {},{}",
mtx::errors::to_string(err->matrix_error.errcode),
static_cast<int>(err->status_code));
return;
}
// Ensure local key cache is up to date
@ -201,6 +202,7 @@ UserProfile::fetchDeviceList(const QString &userID)
nhlog::net()->warn("failed to query device keys: {},{}",
mtx::errors::to_string(err->matrix_error.errcode),
static_cast<int>(err->status_code));
return;
}
emit verificationStatiChanged();