diff --git a/resources/qml/device-verification/DeviceVerification.qml b/resources/qml/device-verification/DeviceVerification.qml index f40a7b8f..94cb1e33 100644 --- a/resources/qml/device-verification/DeviceVerification.qml +++ b/resources/qml/device-verification/DeviceVerification.qml @@ -579,7 +579,6 @@ ApplicationWindow { onClicked: { dialog.close(); deviceVerificationList.remove(flow.tranId); - delete flow; } } } diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index f8cb31a2..909d81eb 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -52,8 +52,6 @@ #include "blurhash.hpp" -#include // only for debugging - // TODO: Needs to be updated with an actual secret. static const std::string STORAGE_SECRET_KEY("secret"); @@ -1471,7 +1469,6 @@ ChatPage::query_keys( static_cast(err->status_code)); return; } - std::cout << "Over here " << user_id << std::endl; cache::setUserCache(std::move(user_id), std::move(UserCache{res, true})); cb(res, err); diff --git a/src/DeviceVerificationFlow.cpp b/src/DeviceVerificationFlow.cpp index 8c230887..dd828421 100644 --- a/src/DeviceVerificationFlow.cpp +++ b/src/DeviceVerificationFlow.cpp @@ -7,6 +7,7 @@ #include #include +#include static constexpr int TIMEOUT = 2 * 60 * 1000; // 2 minutes @@ -75,7 +76,14 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow::Error::UnknownMethod); return; } - this->canonical_json = nlohmann::json(msg); + if (!sender) + this->canonical_json = nlohmann::json(msg); + else { + if (utils::localUser().toStdString() < + this->toClient.to_string()) { + this->canonical_json = nlohmann::json(msg); + } + } this->acceptVerificationRequest(); } else { this->cancelVerification(DeviceVerificationFlow::Error::UnknownMethod); @@ -124,6 +132,7 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, if (msg.relates_to.value().event_id != this->relation.event_id) return; } + this->deleteLater(); emit verificationCanceled(); }); @@ -226,6 +235,11 @@ DeviceVerificationFlow::DeviceVerificationFlow(QObject *, &ChatPage::recievedDeviceVerificationReady, this, [this](const mtx::events::msg::KeyVerificationReady &msg) { + if (!sender) { + this->deleteLater(); + emit verificationCanceled(); + return; + } if (msg.transaction_id.has_value()) { if (msg.transaction_id.value() != this->transaction_id) return; diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp index b210e157..6326e98e 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp @@ -298,6 +298,13 @@ EventStore::handleSync(const mtx::responses::Timeline &events) msg->content, msg->sender); } } + // only the key.verification.ready sent by localuser's other device is of + // significance as it is used for detecting accepted request + if (auto msg = std::get_if< + mtx::events::RoomEvent>( + event)) { + ChatPage::instance()->recievedDeviceVerificationReady(msg->content); + } } } diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 48a3ffa3..59be3464 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -161,16 +161,17 @@ UserProfile::fetchDeviceList(const QString &userID) for (auto sign_key : luk.value().keys) { // checking if the signatures are empty as "at" could // cause exceptions - if (!mk.value().signatures.empty()) { - auto signs = - mk.value().signatures.at(local_user_id); + auto signs = mk->signatures; + if (!signs.empty() && + signs.find(local_user_id) != signs.end()) { + auto sign = signs.at(local_user_id); try { isUserVerified = isUserVerified || (olm::client()->ed25519_verify_sig( sign_key.second, json(mk.value()), - signs.at(sign_key.first))); + sign.at(sign_key.first))); } catch (std::out_of_range) { isUserVerified = isUserVerified || false;