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; (void)status;
emit verificationStatusChanged(user); emit verificationStatusChanged(user);
} }
} } else {
emit verificationStatusChanged(user_id); emit verificationStatusChanged(user_id);
} }
} }
}
void void
Cache::markUserKeysOutOfDate(const std::vector<std::string> &user_ids) 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; (void)status;
emit verificationStatusChanged(user); emit verificationStatusChanged(user);
} }
} } else {
emit verificationStatusChanged(user_id); emit verificationStatusChanged(user_id);
} }
}
void void
Cache::markDeviceUnverified(const std::string &user_id, const std::string &key) 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) for (const auto &entry : res.one_time_key_counts)
nhlog::net()->info("uploaded {} {} one-time keys", entry.second, entry.first); nhlog::net()->info("uploaded {} {} one-time keys", entry.second, entry.first);
cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
startInitialSync(); startInitialSync();
}); });
} }
@ -1143,7 +1145,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
if (!decrypted.empty()) { if (!decrypted.empty()) {
cache::storeSecret(secretName, decrypted); 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) { secretName == mtx::secret_storage::secrets::cross_signing_self_signing) {
auto myKey = deviceKeys->device_keys.at(http::client()->device_id()); auto myKey = deviceKeys->device_keys.at(http::client()->device_id());
if (myKey.user_id == http::client()->user_id().to_string() && if (myKey.user_id == http::client()->user_id().to_string() &&

View file

@ -4,6 +4,8 @@
#include "SelfVerificationStatus.h" #include "SelfVerificationStatus.h"
#include <QApplication>
#include "Cache_p.h" #include "Cache_p.h"
#include "ChatPage.h" #include "ChatPage.h"
#include "Logging.h" #include "Logging.h"
@ -18,12 +20,13 @@
SelfVerificationStatus::SelfVerificationStatus(QObject *o) SelfVerificationStatus::SelfVerificationStatus(QObject *o)
: QObject(o) : QObject(o)
{ {
connect(MainWindow::instance(), &MainWindow::reload, this, [this] { connect(ChatPage::instance(), &ChatPage::contentLoaded, this, [this] {
connect(cache::client(), connect(cache::client(),
&Cache::selfVerificationStatusChanged, &Cache::selfVerificationStatusChanged,
this, this,
&SelfVerificationStatus::invalidate, &SelfVerificationStatus::invalidate,
Qt::UniqueConnection); 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()); 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()) { 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()}); cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
QTimer::singleShot(1'000, [] {
cache::client()->query_keys(http::client()->user_id().to_string(), cache::client()->query_keys(http::client()->user_id().to_string(),
[](const UserKeyCache &, mtx::http::RequestErr) {}); [](const UserKeyCache &, mtx::http::RequestErr) {});
}); });

View file

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