matrixion/src/DeviceVerificationFlow.h

133 lines
3.8 KiB
C
Raw Normal View History

2020-08-30 20:06:53 +03:00
#pragma once
#include <QObject>
#include <mtx/responses/crypto.hpp>
#include "CacheCryptoStructs.h"
2020-07-17 23:16:30 +03:00
#include "MatrixClient.h"
#include "Olm.h"
class QTimer;
using sas_ptr = std::unique_ptr<mtx::crypto::SAS>;
class TimelineModel;
2020-07-29 00:55:47 +03:00
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)
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)
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
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-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
QString getTransactionId();
QString getUserId();
QString getDeviceId();
Method getMethod();
2020-07-29 00:55:47 +03:00
Type getType();
std::vector<int> getSasList();
bool getSender();
2020-07-29 00:55:47 +03:00
// setters
void setTransactionId(QString transaction_id_);
void setUserId(QString userID);
void setDeviceId(QString deviceID);
void setMethod(Method method_);
2020-07-29 00:55:47 +03:00
void setType(Type type_);
void setSender(bool sender_);
2020-07-29 00:55:47 +03:00
void setEventId(std::string event_id);
void callback_fn(const UserKeyCache &res, mtx::http::RequestErr err, std::string user_id);
nlohmann::json canonical_json;
public slots:
//! 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();
//! accepts a verification
void acceptVerificationRequest();
//! starts the verification flow
void startVerificationRequest();
//! cancels a verification flow
2020-06-26 12:40:37 +03:00
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();
2020-07-05 19:03:27 +03:00
//! unverifies a device
void unverify();
signals:
void verificationRequestAccepted(Method method);
void deviceVerified();
void timedout();
void verificationCanceled();
2020-07-05 19:03:27 +03:00
void refreshProfile();
void deleteFlow();
private:
2020-07-29 00:55:47 +03:00
// general
QString userId;
QString deviceId;
Method method;
2020-07-17 23:16:30 +03:00
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;
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;
};