1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#pragma once
#include "Olm.h"
#include "MatrixClient.h"
#include "mtx/responses/crypto.hpp"
#include <QObject>
class QTimer;
using sas_ptr = std::unique_ptr<mtx::crypto::SAS>;
class TimelineModel;
class DeviceVerificationFlow : public QObject
{
Q_OBJECT
// Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
Q_PROPERTY(QString tranId READ getTransactionId WRITE setTransactionId)
Q_PROPERTY(bool sender READ getSender WRITE setSender)
Q_PROPERTY(QString userId READ getUserId WRITE setUserId)
Q_PROPERTY(QString deviceId READ getDeviceId WRITE setDeviceId)
Q_PROPERTY(Method method READ getMethod WRITE setMethod)
Q_PROPERTY(Type type READ getType WRITE setType)
Q_PROPERTY(std::vector<int> sasList READ getSasList CONSTANT)
public:
enum Type
{
ToDevice,
RoomMsg
};
Q_ENUM(Type)
enum Method
{
Decimal,
Emoji
};
Q_ENUM(Method)
enum Error
{
UnknownMethod,
MismatchedCommitment,
MismatchedSAS,
KeyMismatch,
Timeout,
User
};
Q_ENUM(Error)
DeviceVerificationFlow(
QObject *parent = nullptr,
DeviceVerificationFlow::Type = DeviceVerificationFlow::Type::ToDevice,
TimelineModel *model = nullptr);
// getters
QString getTransactionId();
QString getUserId();
QString getDeviceId();
Method getMethod();
Type getType();
std::vector<int> getSasList();
bool getSender();
// setters
void setTransactionId(QString transaction_id_);
void setUserId(QString userID);
void setDeviceId(QString deviceID);
void setMethod(Method method_);
void setType(Type type_);
void setSender(bool sender_);
void setEventId(std::string event_id);
void callback_fn(const mtx::responses::QueryKeys &res,
mtx::http::RequestErr err,
std::string user_id);
nlohmann::json canonical_json;
public slots:
//! sends a verification request
void sendVerificationRequest();
//! accepts a verification request
void sendVerificationReady();
//! completes the verification flow();
void sendVerificationDone();
//! accepts a verification
void acceptVerificationRequest();
//! starts the verification flow
void startVerificationRequest();
//! cancels a verification flow
void cancelVerification(DeviceVerificationFlow::Error error_code);
//! sends the verification key
void sendVerificationKey();
//! sends the mac of the keys
void sendVerificationMac();
//! Completes the verification flow
void acceptDevice();
//! unverifies a device
void unverify();
signals:
void verificationRequestAccepted(Method method);
void deviceVerified();
void timedout();
void verificationCanceled();
void refreshProfile();
void deleteFlow();
private:
// general
QString userId;
QString deviceId;
Method method;
Type type;
bool sender;
QTimer *timeout = nullptr;
sas_ptr sas;
bool isMacVerified = false;
std::string mac_method;
std::string commitment;
mtx::identifiers::User toClient;
std::vector<int> sasList;
std::map<std::string, std::string> device_keys;
// for to_device messages
std::string transaction_id;
// for room messages
std::optional<std::string> room_id;
std::optional<std::string> event_id;
TimelineModel *model_;
mtx::common::RelatesTo relation;
};
|