summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-10-05 22:12:10 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-10-05 22:12:10 +0200
commitbca29a4227a871caac21236c29430b69264018ce (patch)
treedc5bf6b5ecc0ceed9d31d1210fc45693ad295b14 /src/timeline
parentDon't fail on missing key for a device and /rotate-megolm-session command (diff)
downloadnheko-bca29a4227a871caac21236c29430b69264018ce.tar.xz
Make steps in verification flow explicit
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/EventStore.cpp16
-rw-r--r--src/timeline/TimelineModel.cpp4
-rw-r--r--src/timeline/TimelineViewManager.cpp194
-rw-r--r--src/timeline/TimelineViewManager.h25
4 files changed, 100 insertions, 139 deletions
diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp

index 29b3c239..dc92a37f 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp
@@ -299,7 +299,7 @@ EventStore::handleSync(const mtx::responses::Timeline &events) mtx::events::msg::KeyVerificationReady>>(d_event)) { auto msg = std::get_if<mtx::events::RoomEvent< mtx::events::msg::KeyVerificationReady>>(d_event); - ChatPage::instance()->recievedDeviceVerificationReady( + ChatPage::instance()->receivedDeviceVerificationReady( msg->content); } } @@ -328,43 +328,43 @@ EventStore::handle_room_verification(mtx::events::collections::TimelineEvents ev auto msg = std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationCancel>>(event); last_verification_cancel_event = msg; - ChatPage::instance()->recievedDeviceVerificationCancel(msg.content); + ChatPage::instance()->receivedDeviceVerificationCancel(msg.content); return; } else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationAccept>>( &event)) { auto msg = std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationAccept>>(event); - ChatPage::instance()->recievedDeviceVerificationAccept(msg.content); + ChatPage::instance()->receivedDeviceVerificationAccept(msg.content); return; } else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationKey>>( &event)) { auto msg = std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationKey>>(event); - ChatPage::instance()->recievedDeviceVerificationKey(msg.content); + ChatPage::instance()->receivedDeviceVerificationKey(msg.content); return; } else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationMac>>( &event)) { auto msg = std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationMac>>(event); - ChatPage::instance()->recievedDeviceVerificationMac(msg.content); + ChatPage::instance()->receivedDeviceVerificationMac(msg.content); return; } else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationReady>>( &event)) { auto msg = std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationReady>>(event); - ChatPage::instance()->recievedDeviceVerificationReady(msg.content); + ChatPage::instance()->receivedDeviceVerificationReady(msg.content); return; } else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationDone>>( &event)) { auto msg = std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationDone>>(event); - ChatPage::instance()->recievedDeviceVerificationDone(msg.content); + ChatPage::instance()->receivedDeviceVerificationDone(msg.content); return; } else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationStart>>( &event)) { auto msg = std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationStart>>(event); - ChatPage::instance()->recievedDeviceVerificationStart(msg.content, msg.sender); + ChatPage::instance()->receivedDeviceVerificationStart(msg.content, msg.sender); return; } } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 5e8952fc..e8d381df 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -254,7 +254,7 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj &EventStore::startDMVerification, this, [this](mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> msg) { - ChatPage::instance()->recievedRoomDeviceVerificationRequest(msg, this); + ChatPage::instance()->receivedRoomDeviceVerificationRequest(msg, this); }); connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) { this->updateFlowEventId(event_id); @@ -793,7 +793,7 @@ TimelineModel::viewDecryptedRawMessage(QString id) const void TimelineModel::openUserProfile(QString userid) { - emit openProfile(new UserProfile(room_id_, userid, this)); + emit openProfile(new UserProfile(room_id_, userid, manager_, this)); } void diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 03dd4773..250cd5f0 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp
@@ -29,22 +29,6 @@ Q_DECLARE_METATYPE(std::vector<DeviceInfo>) namespace msgs = mtx::events::msg; void -DeviceVerificationList::add(QString tran_id) -{ - this->deviceVerificationList.push_back(tran_id); -} -void -DeviceVerificationList::remove(QString tran_id) -{ - this->deviceVerificationList.removeOne(tran_id); -} -bool -DeviceVerificationList::exist(QString tran_id) -{ - return this->deviceVerificationList.contains(tran_id); -} - -void TimelineViewManager::updateEncryptedDescriptions() { auto decrypt = settings->decryptSidebar(); @@ -134,7 +118,8 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin qmlRegisterType<DelegateChoice>("im.nheko", 1, 0, "DelegateChoice"); qmlRegisterType<DelegateChooser>("im.nheko", 1, 0, "DelegateChooser"); - qmlRegisterType<DeviceVerificationFlow>("im.nheko", 1, 0, "DeviceVerificationFlow"); + qmlRegisterUncreatableType<DeviceVerificationFlow>( + "im.nheko", 1, 0, "DeviceVerificationFlow", "Can't create verification flow from QML!"); qmlRegisterUncreatableType<UserProfile>( "im.nheko", 1, @@ -163,7 +148,6 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin 0, "EmojiCategory", "Error: Only enums"); - this->dvList = new DeviceVerificationList; #ifdef USE_QUICK_VIEW view = new QQuickView(); @@ -183,7 +167,6 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin }); #endif container->setMinimumSize(200, 200); - view->rootContext()->setContextProperty("deviceVerificationList", this->dvList); updateColorPalette(); view->engine()->addImageProvider("MxcImage", imgProvider); view->engine()->addImageProvider("colorimage", colorImgProvider); @@ -197,102 +180,55 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin &TimelineViewManager::updateEncryptedDescriptions); connect( dynamic_cast<ChatPage *>(parent), - &ChatPage::recievedRoomDeviceVerificationRequest, + &ChatPage::receivedRoomDeviceVerificationRequest, this, [this](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &message, TimelineModel *model) { - if (!(this->dvList->exist(QString::fromStdString(message.event_id)))) { - auto flow = new DeviceVerificationFlow( - this, DeviceVerificationFlow::Type::RoomMsg, model); - if (std::find(message.content.methods.begin(), - message.content.methods.end(), - mtx::events::msg::VerificationMethods::SASv1) != - message.content.methods.end()) { - flow->setEventId(message.event_id); - emit newDeviceVerificationRequest( - std::move(flow), - QString::fromStdString(message.event_id), - QString::fromStdString(message.sender), - QString::fromStdString(message.content.from_device), - true); - } else { - flow->cancelVerification( - DeviceVerificationFlow::Error::UnknownMethod); - } - } - }); - connect( - dynamic_cast<ChatPage *>(parent), - &ChatPage::recievedDeviceVerificationRequest, - this, - [this](const mtx::events::msg::KeyVerificationRequest &msg, std::string sender) { - if (!(this->dvList->exist(QString::fromStdString(msg.transaction_id.value())))) { - auto flow = new DeviceVerificationFlow(this); - if (std::find(msg.methods.begin(), - msg.methods.end(), - mtx::events::msg::VerificationMethods::SASv1) != - msg.methods.end()) { - emit newDeviceVerificationRequest( - std::move(flow), - QString::fromStdString(msg.transaction_id.value()), - QString::fromStdString(sender), - QString::fromStdString(msg.from_device)); - } else { - flow->cancelVerification( - DeviceVerificationFlow::Error::UnknownMethod); - } - } - }); - connect( - dynamic_cast<ChatPage *>(parent), - &ChatPage::recievedDeviceVerificationStart, - this, - [this](const mtx::events::msg::KeyVerificationStart &msg, std::string sender) { - if (msg.transaction_id.has_value()) { - if (!(this->dvList->exist( - QString::fromStdString(msg.transaction_id.value())))) { - auto flow = new DeviceVerificationFlow(this); - flow->canonical_json = nlohmann::json(msg); - if ((std::find(msg.key_agreement_protocols.begin(), - msg.key_agreement_protocols.end(), - "curve25519-hkdf-sha256") != - msg.key_agreement_protocols.end()) && - (std::find(msg.hashes.begin(), msg.hashes.end(), "sha256") != - msg.hashes.end()) && - (std::find(msg.message_authentication_codes.begin(), - msg.message_authentication_codes.end(), - "hmac-sha256") != - msg.message_authentication_codes.end())) { - if (std::find(msg.short_authentication_string.begin(), - msg.short_authentication_string.end(), - mtx::events::msg::SASMethods::Emoji) != - msg.short_authentication_string.end()) { - flow->setMethod( - DeviceVerificationFlow::Method::Emoji); - } else if (std::find( - msg.short_authentication_string.begin(), - msg.short_authentication_string.end(), - mtx::events::msg::SASMethods::Decimal) != - msg.short_authentication_string.end()) { - flow->setMethod( - DeviceVerificationFlow::Method::Decimal); - } else { - flow->cancelVerification( - DeviceVerificationFlow::Error::UnknownMethod); - return; - } - emit newDeviceVerificationRequest( - std::move(flow), - QString::fromStdString(msg.transaction_id.value()), - QString::fromStdString(sender), - QString::fromStdString(msg.from_device)); - } else { - flow->cancelVerification( - DeviceVerificationFlow::Error::UnknownMethod); - } + auto event_id = QString::fromStdString(message.event_id); + if (!this->dvList.contains(event_id)) { + if (auto flow = DeviceVerificationFlow::NewInRoomVerification( + this, + model, + message.content, + QString::fromStdString(message.sender), + event_id)) { + dvList[event_id] = flow; + emit newDeviceVerificationRequest(flow.data()); } } }); + connect(dynamic_cast<ChatPage *>(parent), + &ChatPage::receivedDeviceVerificationRequest, + this, + [this](const mtx::events::msg::KeyVerificationRequest &msg, std::string sender) { + if (!msg.transaction_id) + return; + + auto txnid = QString::fromStdString(msg.transaction_id.value()); + if (!this->dvList.contains(txnid)) { + if (auto flow = DeviceVerificationFlow::NewToDeviceVerification( + this, msg, QString::fromStdString(sender), txnid)) { + dvList[txnid] = flow; + emit newDeviceVerificationRequest(flow.data()); + } + } + }); + connect(dynamic_cast<ChatPage *>(parent), + &ChatPage::receivedDeviceVerificationStart, + this, + [this](const mtx::events::msg::KeyVerificationStart &msg, std::string sender) { + if (!msg.transaction_id) + return; + + auto txnid = QString::fromStdString(msg.transaction_id.value()); + if (!this->dvList.contains(txnid)) { + if (auto flow = DeviceVerificationFlow::NewToDeviceVerification( + this, msg, QString::fromStdString(sender), txnid)) { + dvList[txnid] = flow; + emit newDeviceVerificationRequest(flow.data()); + } + } + }); connect(parent, &ChatPage::loggedOut, this, [this]() { isInitialSync_ = true; emit initialSyncChanged(true); @@ -429,6 +365,46 @@ TimelineViewManager::openRoomSettings() const } void +TimelineViewManager::verifyUser(QString userid) +{ + auto joined_rooms = cache::joinedRooms(); + auto room_infos = cache::getRoomInfo(joined_rooms); + + for (std::string room_id : joined_rooms) { + if ((room_infos[QString::fromStdString(room_id)].member_count == 2) && + cache::isRoomEncrypted(room_id)) { + auto room_members = cache::roomMembers(room_id); + if (std::find(room_members.begin(), + room_members.end(), + (userid).toStdString()) != room_members.end()) { + auto model = models.value(QString::fromStdString(room_id)); + auto flow = DeviceVerificationFlow::InitiateUserVerification( + this, model.data(), userid); + connect(model.data(), + &TimelineModel::updateFlowEventId, + this, + [this, flow](std::string eventId) { + dvList[QString::fromStdString(eventId)] = flow; + }); + emit newDeviceVerificationRequest(flow.data()); + return; + } + } + } + + emit ChatPage::instance()->showNotification( + tr("No share room with this user found. Create an " + "encrypted room with this user and try again.")); +} +void +TimelineViewManager::verifyDevice(QString userid, QString deviceid) +{ + auto flow = DeviceVerificationFlow::InitiateDeviceVerification(this, userid, deviceid); + this->dvList[flow->transactionId()] = flow; + emit newDeviceVerificationRequest(flow.data()); +} + +void TimelineViewManager::updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids) { diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index 4779d3cd..12e49080 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h
@@ -24,20 +24,6 @@ class ColorImageProvider; class UserSettings; class ChatPage; -class DeviceVerificationList : public QObject -{ - Q_OBJECT -public: - Q_INVOKABLE void add(QString tran_id); - Q_INVOKABLE void remove(QString tran_id); - Q_INVOKABLE bool exist(QString tran_id); -signals: - void updateProfile(QString userId); - -private: - QVector<QString> deviceVerificationList; -}; - class TimelineViewManager : public QObject { Q_OBJECT @@ -77,6 +63,9 @@ public: Q_INVOKABLE void openLeaveRoomDialog() const; Q_INVOKABLE void openRoomSettings() const; + void verifyUser(QString userid); + void verifyDevice(QString userid, QString deviceid); + signals: void clearRoomMessageCount(QString roomid); void updateRoomsLastMessage(QString roomid, const DescInfo &info); @@ -84,11 +73,7 @@ signals: void initialSyncChanged(bool isInitialSync); void replyingEventChanged(QString replyingEvent); void replyClosed(); - void newDeviceVerificationRequest(DeviceVerificationFlow *flow, - QString transactionId, - QString userId, - QString deviceId, - bool isRequest = false); + void newDeviceVerificationRequest(DeviceVerificationFlow *flow); void inviteUsers(QStringList users); void showRoomList(); void narrowViewChanged(); @@ -180,7 +165,7 @@ private: QSharedPointer<UserSettings> settings; QHash<QString, QColor> userColors; - DeviceVerificationList *dvList; + QHash<QString, QSharedPointer<DeviceVerificationFlow>> dvList; }; Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationAccept) Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationCancel)