6 #include "events/keyverificationevent.h"
7 #include "events/roommessageevent.h"
9 #include <QtCore/QObject>
10 #include <QtCore/QPointer>
23 Q_PROPERTY(QString emoji MEMBER emoji CONSTANT)
24 Q_PROPERTY(QString description MEMBER description CONSTANT)
27 friend bool operator==(
const EmojiEntry&,
const EmojiEntry&) =
default;
50 WAITINGFORVERIFICATION,
64 REMOTE_UNEXPECTED_MESSAGE,
66 REMOTE_UNKNOWN_TRANSACTION,
68 REMOTE_UNKNOWN_METHOD,
74 REMOTE_INVALID_MESSAGE,
76 REMOTE_SESSION_ACCEPTED,
77 MISMATCHED_COMMITMENT,
78 REMOTE_MISMATCHED_COMMITMENT,
80 REMOTE_MISMATCHED_SAS,
84 Q_PROPERTY(QString remoteDeviceId MEMBER m_remoteDeviceId CONSTANT)
85 Q_PROPERTY(QString remoteUserId MEMBER m_remoteUserId CONSTANT)
86 Q_PROPERTY(QVector<EmojiEntry> sasEmojis READ sasEmojis NOTIFY sasEmojisChanged)
87 Q_PROPERTY(State state READ state NOTIFY stateChanged)
88 Q_PROPERTY(Error error READ error NOTIFY errorChanged)
90 Q_PROPERTY(
bool userVerification READ userVerification CONSTANT)
93 KeyVerificationSession(QString remoteUserId,
94 const KeyVerificationRequestEvent& event,
95 Connection* connection,
bool encrypted);
98 KeyVerificationSession(QString userId, QString deviceId,
99 Connection* connection);
102 KeyVerificationSession(
const RoomMessageEvent *event, Room *room);
105 explicit KeyVerificationSession(Room *room);
107 void handleEvent(
const KeyVerificationEvent& baseEvent);
109 QVector<EmojiEntry> sasEmojis()
const;
114 QString remoteDeviceId()
const;
115 QString transactionId()
const;
116 bool userVerification()
const;
118 void setRequestEventId(
const QString &eventId);
127 void cancelVerification(Error error);
131 void sasEmojisChanged();
139 KeyVerificationSession(QString remoteUserId, Connection* connection, QString remoteDeviceId,
140 bool encrypted, QStringList methods, QDateTime startTimestamp,
141 QString transactionId, Room* room =
nullptr, QString requestEventId = {});
142 KeyVerificationSession(QString remoteUserId, Connection* connection, Room* room,
143 QString remoteDeviceId = {}, QString transactionId = {});
145 Connection*
const m_connection;
146 QPointer<Room> m_room;
147 const QString m_remoteUserId;
148 QString m_remoteDeviceId;
149 QString m_transactionId;
150 bool m_encrypted =
false;
151 QStringList m_remoteSupportedMethods{};
152 QStringList m_commonMacCodes{};
154 CStructPtr<OlmSAS> olmDataHolder = makeOlmData();
155 OlmSAS* olmData = olmDataHolder.get();
156 QVector<EmojiEntry> m_sasEmojis;
157 bool startSentByUs =
false;
158 State m_state = INCOMING;
159 Error m_error = NONE;
160 QString m_startEvent{};
161 QString m_commitment{};
162 bool macReceived =
false;
163 bool m_verified =
false;
164 QString m_pendingEdKeyId{};
165 QString m_pendingMasterKey{};
166 QString m_requestEventId{};
168 static CStructPtr<OlmSAS> makeOlmData();
169 void handleReady(
const KeyVerificationReadyEvent& event);
170 void handleStart(
const KeyVerificationStartEvent& event);
171 void handleKey(
const KeyVerificationKeyEvent& event);
172 void handleMac(
const KeyVerificationMacEvent& event);
173 void setupTimeout(std::chrono::milliseconds timeout);
174 void setState(State state);
175 void setError(Error error);
176 static QString errorToString(Error error);
177 static Error stringToError(
const QString& error);
179 void sendEvent(
const QString &userId,
const QString &deviceId,
const KeyVerificationEvent &event,
bool encrypted);
181 QByteArray macInfo(
bool verifying,
const QString& key =
"KEY_IDS"_L1);
182 QString calculateMac(
const QString& input,
bool verifying,
const QString& keyId=
"KEY_IDS"_L1);
186 Q_DECLARE_METATYPE(Quotient::EmojiEntry)