2020-03-13 23:05:18 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-06-17 21:28:35 +03:00
|
|
|
#include "Olm.h"
|
|
|
|
|
2020-06-07 14:35:32 +03:00
|
|
|
#include <MatrixClient.h>
|
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-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-06-20 15:20:43 +03:00
|
|
|
Q_PROPERTY(std::vector<int> sasList READ getSasList)
|
2020-03-13 23:05:18 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum Method
|
|
|
|
{
|
|
|
|
Decimal,
|
|
|
|
Emoji
|
|
|
|
};
|
|
|
|
Q_ENUM(Method)
|
|
|
|
|
|
|
|
DeviceVerificationFlow(QObject *parent = nullptr);
|
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-06-20 15:20:43 +03:00
|
|
|
std::vector<int> getSasList();
|
2020-06-17 21:28:35 +03:00
|
|
|
void setTransactionId(QString transaction_id_);
|
|
|
|
bool getSender();
|
2020-06-07 14:35:32 +03:00
|
|
|
void setUserId(QString userID);
|
|
|
|
void setDeviceId(QString deviceID);
|
|
|
|
void setMethod(Method method_);
|
2020-06-17 21:28:35 +03:00
|
|
|
void setSender(bool sender_);
|
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();
|
|
|
|
//! 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
|
|
|
|
void cancelVerification();
|
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();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void verificationRequestAccepted(Method method);
|
|
|
|
void deviceVerified();
|
|
|
|
void timedout();
|
|
|
|
void verificationCanceled();
|
|
|
|
|
|
|
|
private:
|
2020-06-07 14:35:32 +03:00
|
|
|
QString userId;
|
|
|
|
QString deviceId;
|
|
|
|
Method method;
|
2020-06-17 21:28:35 +03:00
|
|
|
bool sender;
|
2020-06-04 16:44:15 +03:00
|
|
|
|
2020-03-13 23:05:18 +03:00
|
|
|
QTimer *timeout = nullptr;
|
2020-06-20 15:20:43 +03:00
|
|
|
sas_ptr sas;
|
|
|
|
std::string mac_method;
|
2020-06-04 16:44:15 +03:00
|
|
|
std::string transaction_id;
|
2020-06-20 15:20:43 +03:00
|
|
|
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-03-13 23:05:18 +03:00
|
|
|
};
|