6#include "events/keyverificationevent.h"
7#include "events/roommessageevent.h"
9#include <QtCore/QObject>
10#include <QtCore/QPointer>
11#include <QtQmlIntegration/qqmlintegration.h>
32
33
34
53 WAITINGFORVERIFICATION,
67 REMOTE_UNEXPECTED_MESSAGE,
69 REMOTE_UNKNOWN_TRANSACTION,
71 REMOTE_UNKNOWN_METHOD,
77 REMOTE_INVALID_MESSAGE,
79 REMOTE_SESSION_ACCEPTED,
80 MISMATCHED_COMMITMENT,
81 REMOTE_MISMATCHED_COMMITMENT,
83 REMOTE_MISMATCHED_SAS,
87 Q_PROPERTY(QString remoteDeviceId MEMBER m_remoteDeviceId CONSTANT)
88 Q_PROPERTY(QString remoteUserId MEMBER m_remoteUserId CONSTANT)
89 Q_PROPERTY(QVector<EmojiEntry> sasEmojis READ sasEmojis NOTIFY sasEmojisChanged)
90 Q_PROPERTY(State state READ state NOTIFY stateChanged)
91 Q_PROPERTY(Error error READ error NOTIFY errorChanged)
93 Q_PROPERTY(
bool userVerification READ userVerification CONSTANT)
96 KeyVerificationSession(QString remoteUserId,
97 const KeyVerificationRequestEvent& event,
98 Connection* connection,
bool encrypted);
101 KeyVerificationSession(QString userId, QString deviceId,
102 Connection* connection);
105 KeyVerificationSession(
const RoomMessageEvent *event, Room *room);
108 explicit KeyVerificationSession(Room *room);
110 void handleEvent(
const KeyVerificationEvent& baseEvent);
112 QVector<EmojiEntry> sasEmojis()
const;
117 QString remoteDeviceId()
const;
118 QString transactionId()
const;
119 bool userVerification()
const;
121 void setRequestEventId(
const QString &eventId);
130 void cancelVerification(Error error);
134 void sasEmojisChanged();
142 KeyVerificationSession(QString remoteUserId, Connection* connection, QString remoteDeviceId,
143 bool encrypted, QStringList methods, QDateTime startTimestamp,
144 QString transactionId, Room* room =
nullptr, QString requestEventId = {});
145 KeyVerificationSession(QString remoteUserId, Connection* connection, Room* room,
146 QString remoteDeviceId = {}, QString transactionId = {});
148 Connection*
const m_connection;
149 QPointer<Room> m_room;
150 const QString m_remoteUserId;
151 QString m_remoteDeviceId;
152 QString m_transactionId;
153 bool m_encrypted =
false;
154 QStringList m_remoteSupportedMethods{};
155 QStringList m_commonMacCodes{};
157 CStructPtr<OlmSAS> olmDataHolder = makeOlmData();
158 OlmSAS* olmData = olmDataHolder.get();
159 QVector<EmojiEntry> m_sasEmojis;
160 bool startSentByUs =
false;
161 State m_state = INCOMING;
162 Error m_error = NONE;
163 QString m_startEvent{};
164 QByteArray m_commitment{};
165 bool macReceived =
false;
166 bool m_verified =
false;
167 QString m_pendingEdKeyId{};
168 QString m_pendingMasterKey{};
169 QString m_requestEventId{};
171 static CStructPtr<OlmSAS> makeOlmData();
172 void handleReady(
const KeyVerificationReadyEvent& event);
173 void handleStart(
const KeyVerificationStartEvent& event);
174 void handleKey(
const KeyVerificationKeyEvent& event);
175 void handleMac(
const KeyVerificationMacEvent& event);
176 void handleCancel(Error error);
177 void setupTimeout(std::chrono::milliseconds timeout);
178 void setState(State state);
179 void setError(Error error);
180 static QString errorToString(Error error);
181 static Error stringToError(
const QString& error);
183 void sendEvent(
const QString &userId,
const QString &deviceId,
const KeyVerificationEvent &event,
bool encrypted);
185 QByteArray macInfo(
bool verifying,
const QString& key =
"KEY_IDS"_L1);
186 QString calculateMac(
const QString& input,
bool verifying,
const QString& keyId=
"KEY_IDS"_L1);