From 1fcd768f88f7e84978d19283c9fa6205624f2544 Mon Sep 17 00:00:00 2001 From: CH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com> Date: Sat, 18 Jul 2020 01:46:30 +0530 Subject: Adding Room Key Verification Stuff --- src/ui/UserProfile.cpp | 34 ++++++++++++++++++++++++++++++++++ src/ui/UserProfile.h | 4 ++++ 2 files changed, 38 insertions(+) (limited to 'src/ui') diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 6ae04d0b..3499384c 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -6,6 +6,8 @@ #include "Utils.h" #include "mtx/responses/crypto.hpp" +#include // only for debugging + UserProfile::UserProfile(QString roomid, QString userid, QObject *parent) : QObject(parent) , roomid_(roomid) @@ -74,6 +76,12 @@ UserProfile::avatarUrl() return cache::avatarUrl(roomid_, userid_); } +bool +UserProfile::getUserStatus() +{ + return isUserVerified; +} + void UserProfile::callback_fn(const mtx::responses::QueryKeys &res, mtx::http::RequestErr err, @@ -100,6 +108,7 @@ UserProfile::callback_fn(const mtx::responses::QueryKeys &res, // TODO: Verify signatures and ignore those that don't pass. verification::Status verified = verification::Status::UNVERIFIED; + isUserVerified = device_verified->is_user_verified; if (device_verified.has_value()) { if (std::find(device_verified->cross_verified.begin(), device_verified->cross_verified.end(), @@ -174,4 +183,29 @@ UserProfile::startChat() if (utils::localUser() != this->userid_) req.invite = {this->userid_.toStdString()}; emit ChatPage::instance()->createRoom(req); +} + +void +UserProfile::verifyUser() +{ + std::cout << "Checking if to start to device verification or room message verification" + << std::endl; + 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(), + (this->userid()).toStdString()) != room_members.end()) { + std::cout << "FOUND A ENCRYPTED ROOM WITH THIS USER : " << room_id + << std::endl; + return; + } + } + } + + std::cout << "DIDN'T FIND A ENCRYPTED ROOM WITH THIS USER" << std::endl; } \ No newline at end of file diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index 4e048400..3f9cbe6f 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -81,6 +81,7 @@ class UserProfile : public QObject Q_PROPERTY(QString userid READ userid CONSTANT) Q_PROPERTY(QString avatarUrl READ avatarUrl CONSTANT) Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT) + Q_PROPERTY(bool isUserVerified READ getUserStatus CONSTANT) public: UserProfile(QString roomid, QString userid, QObject *parent = 0); @@ -89,17 +90,20 @@ public: QString userid(); QString displayName(); QString avatarUrl(); + bool getUserStatus(); Q_INVOKABLE void fetchDeviceList(const QString &userID); Q_INVOKABLE void banUser(); // Q_INVOKABLE void ignoreUser(); Q_INVOKABLE void kickUser(); Q_INVOKABLE void startChat(); + Q_INVOKABLE void verifyUser(); private: QString roomid_, userid_; std::optional cross_verified; DeviceInfoModel deviceList_; + bool isUserVerified = false; void callback_fn(const mtx::responses::QueryKeys &res, mtx::http::RequestErr err, -- cgit 1.5.1