diff --git a/src/Cache.cpp b/src/Cache.cpp index 280e00ed..0fdf8dd3 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -4101,8 +4101,9 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query (void)status; emit verificationStatusChanged(user); } + } else { + emit verificationStatusChanged(user_id); } - emit verificationStatusChanged(user_id); } } @@ -4311,8 +4312,9 @@ Cache::markDeviceVerified(const std::string &user_id, const std::string &key) (void)status; emit verificationStatusChanged(user); } + } else { + emit verificationStatusChanged(user_id); } - emit verificationStatusChanged(user_id); } void diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 0b8f2301..77a8edcf 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -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() && diff --git a/src/encryption/SelfVerificationStatus.cpp b/src/encryption/SelfVerificationStatus.cpp index 3ddbc7e6..c4f4f196 100644 --- a/src/encryption/SelfVerificationStatus.cpp +++ b/src/encryption/SelfVerificationStatus.cpp @@ -4,6 +4,8 @@ #include "SelfVerificationStatus.h" +#include + #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, [] { - cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()}); + 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) {}); }); diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index b5a16f43..72b1d8e6 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -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(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(err->status_code)); + return; } emit verificationStatiChanged();