libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
keyverificationsession.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2022 Tobias Fella <fella@posteo.de>
2
// SPDX-License-Identifier: LGPL-2.1-or-later
3
4
#
pragma
once
5
6
#
include
"quotient_export.h"
7
8
#
include
<
QtCore
/
QObject
>
9
#
include
<
QtCore
/
QPointer
>
10
#
include
<
QtQmlIntegration
/
qqmlintegration
.
h
>
11
12
#
include
"util.h"
13
14
class
QTimer;
15
16
namespace
Quotient
{
17
class
Connection;
18
class
Room;
19
20
struct
QUOTIENT_API
EmojiEntry
{
21
Q_GADGET
22
//! \brief Unicode of the emoji
23
Q_PROPERTY
(
QString
emoji
MEMBER
emoji
CONSTANT
)
24
//! \brief Textual description of the emoji
25
//! This follows https://spec.matrix.org/v1.11/client-server-api/#sas-method-emoji
26
Q_PROPERTY
(
QString
description
MEMBER
description
CONSTANT
)
27
28
public
:
29
QString
emoji
;
30
QString
description
;
31
friend
bool
operator
==(
const
EmojiEntry
&,
const
EmojiEntry
&) =
default
;
32
};
33
34
/** A key verification session. Listen for incoming sessions by connecting to Connection::newKeyVerificationSession.
35
Start a new session using Connection::startKeyVerificationSession.
36
The object is delete after finished is emitted.
37
*/
38
class
QUOTIENT_API
KeyVerificationSession
:
public
QObject
39
{
40
Q_OBJECT
41
QML_ELEMENT
42
QML_UNCREATABLE
(
""
)
43
44
public
:
45
enum
State
{
46
CREATED
,
//! The verification request has been newly created by us
47
DECL_DEPRECATED_ENUMERATOR
(
WAITINGFORREADY
,
CREATED
),
48
REQUESTED
,
//! The verification request was received from the other party
49
DECL_DEPRECATED_ENUMERATOR
(
INCOMING
,
REQUESTED
),
50
READY
,
//! The verification request is ready to start a verification flow
51
TRANSITIONED
,
//! The verification request has transitioned into a concrete verification flow, e.g. into the emoji based SAS verification
52
DONE
,
//! The verification flow that was started with this request has finished
53
CANCELLED
,
//! The verification process has been cancelled
54
CANCELED
=
CANCELLED
,
55
NOTFOUND
,
//! The verification session was not found
56
};
57
Q_ENUM
(
State
)
58
59
enum
SasState
{
60
SASSTARTED
,
//! The verification has been started, the protocols that should be used have been proposed and can be accepted
61
SASACCEPTED
,
//! The verification has been accepted and both sides agreed to a set of protocols that will be used for the verification process
62
SASKEYSEXCHANGED
,
//! The public keys have been exchanged and the short auth string can be presented to the user
63
SASCONFIRMED
,
//! The verification process has been confirmed from our side, we’re waiting for the other side to confirm as well
64
SASDONE
,
//! The verification process has been successfully concluded
65
SASCANCELLED
,
//! The verification process has been cancelled
66
SASNOTFOUND
,
//! The verification session is not found / not transitioned to SAS
67
};
68
Q_ENUM
(
SasState
)
69
70
//! \brief The matrix id of the user we're verifying.
71
//! For device verification this is our own id.
72
Q_PROPERTY
(
QString
remoteUserId
MEMBER
m_remoteUserId
CONSTANT
)
73
74
//! \brief The device id of the device we're verifying
75
//! Does not have a specified value when verifying a different user
76
Q_PROPERTY
(
QString
remoteDeviceId
MEMBER
m_remoteDeviceId
CONSTANT
)
77
78
//! \brief The current state of the verification session
79
//! Clients should use this to adapt their UI to the current stage of the verification
80
Q_PROPERTY
(
State
state
MEMBER
m_state
NOTIFY
stateChanged
)
81
82
//! \brief The current state of the sas verification
83
//! Clients should use this to adapt their UI to the current stage of the verification
84
Q_PROPERTY
(
SasState
sasState
MEMBER
m_sasState
NOTIFY
sasStateChanged
)
85
86
//! \brief The sas emoji that should be shown to the user.
87
//! Only has a specified value when the session is in TRANSITIONED state
88
Q_PROPERTY
(
QList
<
EmojiEntry
>
sasEmojis
READ
sasEmojis
NOTIFY
sasEmojisChanged
)
89
90
KeyVerificationSession
(
const
QString
&
remoteUserId
,
const
QString
&
verificationId
,
const
QString
&
remoteDeviceId
,
Quotient
::
Connection
*
connection
);
91
KeyVerificationSession
(
Room
*
room
,
Quotient
::
Connection
*
connection
,
const
QString
&
verificationId
= {});
92
93
//! \brief Accept an incoming verification session
94
Q_INVOKABLE
void
accept
();
95
//! \deprecated Use KeyVerificationSession::accept instead
96
Q_INVOKABLE
void
sendReady
();
97
98
//! \brief Confirm that the emojis shown to the user match
99
//! This will mark the remote session / user as verified and send an m.key.verification.mac event
100
//! Only call this after the user has confirmed the correctness of the emoji!
101
Q_INVOKABLE
void
confirm
();
102
//! \deprecated Use KeyVerificationSession::confirm instead
103
Q_INVOKABLE
void
sendMac
();
104
105
//! \brief Start a SAS verification
106
Q_INVOKABLE
void
startSas
();
107
//! \deprecated Use KeyVerificationSession::startSas instead
108
Q_INVOKABLE
void
sendStartSas
();
109
110
Q_INVOKABLE
void
cancelVerification
();
111
112
QVector
<
EmojiEntry
>
sasEmojis
();
113
QString
remoteUser
()
const
;
114
QString
remoteDeviceId
()
const
;
115
QString
verificationId
()
const
;
116
117
static
KeyVerificationSession
*
requestDeviceVerification
(
const
QString
&
userId
,
const
QString
&
deviceId
,
Connection
*
connection
);
118
static
KeyVerificationSession
*
requestUserVerification
(
Room
*
room
,
Connection
*
connection
);
119
static
KeyVerificationSession
*
selfVerification
(
const
QString
&
verificationId
,
Connection
*
connection
);
120
121
static
KeyVerificationSession
*
processIncomingUserVerification
(
Room
*
room
,
const
QString
&
eventId
);
122
123
Quotient
::
Room
*
room
()
const
;
124
125
//! \internal
126
void
startMonitoring
();
127
128
private
:
129
QString
m_remoteUserId
;
130
QString
m_verificationId
;
131
QString
m_remoteDeviceId
;
132
QPointer
<
Quotient
::
Connection
>
m_connection
;
133
QPointer
<
Quotient
::
Room
>
m_room
;
134
State
m_state
=
REQUESTED
;
135
SasState
m_sasState
=
SASNOTFOUND
;
136
bool
weStarted
=
false
;
137
QTimer
*
m_processTimer
=
nullptr
;
138
139
void
setState
(
State
state
);
140
void
setSasState
(
SasState
state
);
141
void
setVerificationId
(
const
QString
&
verificationId
);
142
bool
sasMonitorStarted
=
false
;
143
144
friend
class
Quotient
::
Connection
;
145
Q_SIGNALS
:
146
void
stateChanged
();
147
void
sasStateChanged
();
148
void
sasEmojisChanged
();
149
};
150
151
}
// namespace Quotient
152
Q_DECLARE_METATYPE
(
Quotient
::
EmojiEntry
)
Quotient::KeyVerificationSession
Definition
keyverificationsession.h:39
Quotient
Definition
accountregistry.h:13
QUOTIENT_API
#define QUOTIENT_API
Definition
quotient_export.h:22
Quotient::EmojiEntry
Definition
keyverificationsession.h:20
DECL_DEPRECATED_ENUMERATOR
#define DECL_DEPRECATED_ENUMERATOR(Deprecated, Recommended)
Definition
util.h:22
Quotient
keyverificationsession.h
Generated by
1.9.8