nheko/src/DeviceVerificationFlow.h

133 lines
3.9 KiB
C
Raw Normal View History

2020-08-30 19:06:53 +02:00
#pragma once
#include "Olm.h"
2020-07-17 22:16:30 +02:00
#include "MatrixClient.h"
2020-06-23 00:05:56 +02:00
#include "mtx/responses/crypto.hpp"
#include <QObject>
class QTimer;
using sas_ptr = std::unique_ptr<mtx::crypto::SAS>;
class TimelineModel;
2020-07-28 23:55:47 +02: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-28 23:55:47 +02:00
Q_PROPERTY(Type type READ getType WRITE setType)
2020-07-17 22:16:30 +02:00
Q_PROPERTY(std::vector<int> sasList READ getSasList CONSTANT)
public:
2020-07-17 22:16:30 +02:00
enum Type
{
ToDevice,
RoomMsg
};
2020-07-28 23:55:47 +02:00
Q_ENUM(Type)
2020-07-17 22:16:30 +02:00
enum Method
{
Decimal,
Emoji
};
Q_ENUM(Method)
2020-07-17 22:16:30 +02:00
2020-06-26 11:40:37 +02:00
enum Error
{
UnknownMethod,
MismatchedCommitment,
MismatchedSAS,
KeyMismatch,
Timeout,
User
};
Q_ENUM(Error)
2020-07-17 22:16:30 +02:00
DeviceVerificationFlow(
QObject *parent = nullptr,
2020-08-18 07:59:02 +02:00
DeviceVerificationFlow::Type = DeviceVerificationFlow::Type::ToDevice,
TimelineModel *model = nullptr);
2020-07-28 23:55:47 +02:00
// getters
QString getTransactionId();
QString getUserId();
QString getDeviceId();
Method getMethod();
2020-07-28 23:55:47 +02:00
Type getType();
std::vector<int> getSasList();
bool getSender();
2020-07-28 23:55:47 +02:00
// setters
void setTransactionId(QString transaction_id_);
void setUserId(QString userID);
void setDeviceId(QString deviceID);
void setMethod(Method method_);
2020-07-28 23:55:47 +02:00
void setType(Type type_);
void setSender(bool sender_);
2020-07-28 23:55:47 +02:00
void setEventId(std::string event_id);
2020-07-05 18:03:27 +02:00
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();
2020-06-23 00:05:56 +02: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 11:40:37 +02: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 18:03:27 +02:00
//! unverifies a device
void unverify();
signals:
void verificationRequestAccepted(Method method);
void deviceVerified();
void timedout();
void verificationCanceled();
2020-07-05 18:03:27 +02:00
void refreshProfile();
void deleteFlow();
private:
2020-07-28 23:55:47 +02:00
// general
QString userId;
QString deviceId;
Method method;
2020-07-17 22:16:30 +02: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 00:05:56 +02:00
std::map<std::string, std::string> device_keys;
2020-07-28 23:55:47 +02: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 05:05:15 +02:00
TimelineModel *model_;
2020-08-30 13:02:28 +02:00
mtx::common::RelatesTo relation;
};