2020-08-30 19:57:14 +03:00
|
|
|
ith#pragma once
|
2020-03-13 23:05:18 +03:00
|
|
|
|
2020-06-17 21:28:35 +03:00
|
|
|
#include "Olm.h"
|
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
#include "MatrixClient.h"
|
2020-06-23 01:05:56 +03:00
|
|
|
#include "mtx/responses/crypto.hpp"
|
2020-03-13 23:05:18 +03:00
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
class QTimer;
|
|
|
|
|
2020-06-20 15:20:43 +03:00
|
|
|
using sas_ptr = std::unique_ptr<mtx::crypto::SAS>;
|
|
|
|
|
2020-07-29 00:55:47 +03:00
|
|
|
struct TimelineModel;
|
|
|
|
|
2020-03-13 23:05:18 +03:00
|
|
|
class DeviceVerificationFlow : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
// Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
|
2020-06-17 21:28:35 +03:00
|
|
|
Q_PROPERTY(QString tranId READ getTransactionId WRITE setTransactionId)
|
|
|
|
Q_PROPERTY(bool sender READ getSender WRITE setSender)
|
2020-06-07 14:35:32 +03:00
|
|
|
Q_PROPERTY(QString userId READ getUserId WRITE setUserId)
|
|
|
|
Q_PROPERTY(QString deviceId READ getDeviceId WRITE setDeviceId)
|
|
|
|
Q_PROPERTY(Method method READ getMethod WRITE setMethod)
|
2020-07-29 00:55:47 +03:00
|
|
|
Q_PROPERTY(Type type READ getType WRITE setType)
|
2020-07-17 23:16:30 +03:00
|
|
|
Q_PROPERTY(std::vector<int> sasList READ getSasList CONSTANT)
|
2020-03-13 23:05:18 +03:00
|
|
|
|
|
|
|
public:
|
2020-07-17 23:16:30 +03:00
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
ToDevice,
|
|
|
|
RoomMsg
|
|
|
|
};
|
2020-07-29 00:55:47 +03:00
|
|
|
Q_ENUM(Type)
|
2020-07-17 23:16:30 +03:00
|
|
|
|
2020-03-13 23:05:18 +03:00
|
|
|
enum Method
|
|
|
|
{
|
|
|
|
Decimal,
|
|
|
|
Emoji
|
|
|
|
};
|
|
|
|
Q_ENUM(Method)
|
2020-07-17 23:16:30 +03:00
|
|
|
|
2020-06-26 12:40:37 +03:00
|
|
|
enum Error
|
|
|
|
{
|
|
|
|
UnknownMethod,
|
|
|
|
MismatchedCommitment,
|
|
|
|
MismatchedSAS,
|
|
|
|
KeyMismatch,
|
|
|
|
Timeout,
|
|
|
|
User
|
|
|
|
};
|
|
|
|
Q_ENUM(Error)
|
2020-03-13 23:05:18 +03:00
|
|
|
|
2020-07-17 23:16:30 +03:00
|
|
|
DeviceVerificationFlow(
|
|
|
|
QObject *parent = nullptr,
|
2020-08-18 08:59:02 +03:00
|
|
|
DeviceVerificationFlow::Type = DeviceVerificationFlow::Type::ToDevice,
|
|
|
|
TimelineModel *model = nullptr);
|
2020-07-29 00:55:47 +03:00
|
|
|
// getters
|
2020-06-17 21:28:35 +03:00
|
|
|
QString getTransactionId();
|
2020-06-07 14:35:32 +03:00
|
|
|
QString getUserId();
|
|
|
|
QString getDeviceId();
|
|
|
|
Method getMethod();
|
2020-07-29 00:55:47 +03:00
|
|
|
Type getType();
|
2020-06-20 15:20:43 +03:00
|
|
|
std::vector<int> getSasList();
|
2020-06-17 21:28:35 +03:00
|
|
|
bool getSender();
|
2020-07-29 00:55:47 +03:00
|
|
|
// setters
|
|
|
|
void setTransactionId(QString transaction_id_);
|
2020-06-07 14:35:32 +03:00
|
|
|
void setUserId(QString userID);
|
|
|
|
void setDeviceId(QString deviceID);
|
|
|
|
void setMethod(Method method_);
|
2020-07-29 00:55:47 +03:00
|
|
|
void setType(Type type_);
|
2020-06-17 21:28:35 +03:00
|
|
|
void setSender(bool sender_);
|
2020-07-29 00:55:47 +03:00
|
|
|
void setEventId(std::string event_id);
|
|
|
|
|
2020-07-05 19:03:27 +03:00
|
|
|
void callback_fn(const mtx::responses::QueryKeys &res,
|
|
|
|
mtx::http::RequestErr err,
|
|
|
|
std::string user_id);
|
2020-03-13 23:05:18 +03:00
|
|
|
|
2020-06-20 15:20:43 +03:00
|
|
|
nlohmann::json canonical_json;
|
|
|
|
|
2020-03-13 23:05:18 +03:00
|
|
|
public slots:
|
2020-06-04 16:44:15 +03:00
|
|
|
//! sends a verification request
|
|
|
|
void sendVerificationRequest();
|
2020-06-23 01:05:56 +03:00
|
|
|
//! accepts a verification request
|
|
|
|
void sendVerificationReady();
|
|
|
|
//! completes the verification flow();
|
|
|
|
void sendVerificationDone();
|
2020-06-04 16:44:15 +03:00
|
|
|
//! accepts a verification
|
2020-03-13 23:05:18 +03:00
|
|
|
void acceptVerificationRequest();
|
2020-06-04 16:44:15 +03:00
|
|
|
//! starts the verification flow
|
|
|
|
void startVerificationRequest();
|
2020-03-13 23:05:18 +03:00
|
|
|
//! cancels a verification flow
|
2020-06-26 12:40:37 +03:00
|
|
|
void cancelVerification(DeviceVerificationFlow::Error error_code);
|
2020-06-09 19:36:41 +03:00
|
|
|
//! sends the verification key
|
|
|
|
void sendVerificationKey();
|
|
|
|
//! sends the mac of the keys
|
|
|
|
void sendVerificationMac();
|
2020-03-13 23:05:18 +03:00
|
|
|
//! Completes the verification flow
|
|
|
|
void acceptDevice();
|
2020-07-05 19:03:27 +03:00
|
|
|
//! unverifies a device
|
|
|
|
void unverify();
|
2020-03-13 23:05:18 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void verificationRequestAccepted(Method method);
|
|
|
|
void deviceVerified();
|
|
|
|
void timedout();
|
|
|
|
void verificationCanceled();
|
2020-07-05 19:03:27 +03:00
|
|
|
void refreshProfile();
|
2020-03-13 23:05:18 +03:00
|
|
|
|
|
|
|
private:
|
2020-07-29 00:55:47 +03:00
|
|
|
// general
|
2020-06-07 14:35:32 +03:00
|
|
|
QString userId;
|
|
|
|
QString deviceId;
|
|
|
|
Method method;
|
2020-07-17 23:16:30 +03:00
|
|
|
Type type;
|
2020-06-17 21:28:35 +03:00
|
|
|
bool sender;
|
2020-03-13 23:05:18 +03:00
|
|
|
QTimer *timeout = nullptr;
|
2020-06-20 15:20:43 +03:00
|
|
|
sas_ptr sas;
|
2020-06-25 20:59:50 +03:00
|
|
|
bool isMacVerified = false;
|
2020-06-20 15:20:43 +03:00
|
|
|
std::string mac_method;
|
|
|
|
std::string commitment;
|
2020-06-07 14:35:32 +03:00
|
|
|
mtx::identifiers::User toClient;
|
2020-06-20 15:20:43 +03:00
|
|
|
std::vector<int> sasList;
|
2020-06-23 01:05:56 +03:00
|
|
|
std::map<std::string, std::string> device_keys;
|
2020-07-29 00:55:47 +03:00
|
|
|
// for to_device messages
|
|
|
|
std::string transaction_id;
|
|
|
|
// for room messages
|
|
|
|
std::optional<std::string> room_id;
|
|
|
|
std::optional<std::string> event_id;
|
2020-08-09 06:05:15 +03:00
|
|
|
TimelineModel *model_;
|
2020-08-30 14:02:28 +03:00
|
|
|
mtx::common::RelatesTo relation;
|
2020-03-13 23:05:18 +03:00
|
|
|
};
|