aboutsummaryrefslogtreecommitdiff
path: root/lib/events/keyverificationevent.h
blob: a9f6396838630775a18638aca513c873c5a6f607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
// SPDX-License-Identifier: LGPL-2.1-or-later

#pragma once

#include "event.h"

namespace Quotient {

/// Requests a key verification with another user's devices.
/// Typically sent as a to-device event.
class QUOTIENT_API KeyVerificationRequestEvent : public Event {
public:
    DEFINE_EVENT_TYPEID("m.key.verification.request", KeyVerificationRequestEvent)

    explicit KeyVerificationRequestEvent(const QJsonObject& obj);

    /// The device ID which is initiating the request.
    QString fromDevice() const;

    /// An opaque identifier for the verification request. Must
    /// be unique with respect to the devices involved.
    QString transactionId() const;

    /// The verification methods supported by the sender.
    QStringList methods() const;

    /// The POSIX timestamp in milliseconds for when the request was
    /// made. If the request is in the future by more than 5 minutes or
    /// more than 10 minutes in the past, the message should be ignored
    /// by the receiver.
    uint64_t timestamp() const;
};
REGISTER_EVENT_TYPE(KeyVerificationRequestEvent)

class QUOTIENT_API KeyVerificationReadyEvent : public Event {
public:
    DEFINE_EVENT_TYPEID("m.key.verification.ready", KeyVerificationReadyEvent)

    explicit KeyVerificationReadyEvent(const QJsonObject& obj);

    /// The device ID which is accepting the request.
    QString fromDevice() const;

    /// The transaction id of the verification request
    QString transactionId() const;

    /// The verification methods supported by the sender.
    QStringList methods() const;
};
REGISTER_EVENT_TYPE(KeyVerificationReadyEvent)


/// Begins a key verification process.
class QUOTIENT_API KeyVerificationStartEvent : public Event {
public:
    DEFINE_EVENT_TYPEID("m.key.verification.start", KeyVerificationStartEvent)

    explicit KeyVerificationStartEvent(const QJsonObject &obj);

    /// The device ID which is initiating the process.
    QString fromDevice() const;

    /// An opaque identifier for the verification request. Must
    /// be unique with respect to the devices involved.
    QString transactionId() const;

    /// The verification method to use.
    QString method() const;

    /// Optional method to use to verify the other user's key with.
    Omittable<QString> nextMethod() const;

    // SAS.V1 methods

    /// The key agreement protocols the sending device understands.
    /// \note Only exist if method is m.sas.v1
    QStringList keyAgreementProtocols() const;

    /// The hash methods the sending device understands.
    /// \note Only exist if method is m.sas.v1
    QStringList hashes() const;

    /// The message authentication codes that the sending device understands.
    /// \note Only exist if method is m.sas.v1
    QStringList messageAuthenticationCodes() const;

    /// The SAS methods the sending device (and the sending device's
    /// user) understands.
    /// \note Only exist if method is m.sas.v1
    QString shortAuthenticationString() const;
};
REGISTER_EVENT_TYPE(KeyVerificationStartEvent)

/// Accepts a previously sent m.key.verification.start message.
/// Typically sent as a to-device event.
class QUOTIENT_API KeyVerificationAcceptEvent : public Event {
public:
    DEFINE_EVENT_TYPEID("m.key.verification.accept", KeyVerificationAcceptEvent)

    explicit KeyVerificationAcceptEvent(const QJsonObject& obj);

    /// An opaque identifier for the verification process.
    QString transactionId() const;

    /// The verification method to use. Must be 'm.sas.v1'.
    QString method() const;

    /// The key agreement protocol the device is choosing to use, out of
    /// the options in the m.key.verification.start message.
    QString keyAgreementProtocol() const;

    /// The hash method the device is choosing to use, out of the
    /// options in the m.key.verification.start message.
    QString hashData() const;

    /// The message authentication code the device is choosing to use, out
    /// of the options in the m.key.verification.start message.
    QString messageAuthenticationCode() const;

    /// The SAS methods both devices involved in the verification process understand.
    QStringList shortAuthenticationString() const;

    /// The hash (encoded as unpadded base64) of the concatenation of the
    /// device's ephemeral public key (encoded as unpadded base64) and the
    /// canonical JSON representation of the m.key.verification.start message.
    QString commitment() const;
};
REGISTER_EVENT_TYPE(KeyVerificationAcceptEvent)

class QUOTIENT_API KeyVerificationCancelEvent : public Event {
public:
    DEFINE_EVENT_TYPEID("m.key.verification.cancel", KeyVerificationCancelEvent)

    explicit KeyVerificationCancelEvent(const QJsonObject &obj);

    /// An opaque identifier for the verification process.
    QString transactionId() const;

    /// A human readable description of the code. The client should only
    /// rely on this string if it does not understand the code.
    QString reason() const;

    /// The error code for why the process/request was cancelled by the user.
    QString code() const;
};
REGISTER_EVENT_TYPE(KeyVerificationCancelEvent)

/// Sends the ephemeral public key for a device to the partner device.
/// Typically sent as a to-device event.
class QUOTIENT_API KeyVerificationKeyEvent : public Event {
public:
    DEFINE_EVENT_TYPEID("m.key.verification.key", KeyVerificationKeyEvent)

    explicit KeyVerificationKeyEvent(const QJsonObject &obj);

    /// An opaque identifier for the verification process. 
    QString transactionId() const;

    /// The device's ephemeral public key, encoded as unpadded base64.
    QString key() const;
};
REGISTER_EVENT_TYPE(KeyVerificationKeyEvent)

/// Sends the MAC of a device's key to the partner device.
class QUOTIENT_API KeyVerificationMacEvent : public Event {
public:
    DEFINE_EVENT_TYPEID("m.key.verification.mac", KeyVerificationMacEvent)

    explicit KeyVerificationMacEvent(const QJsonObject &obj);

    /// An opaque identifier for the verification process. 
    QString transactionId() const;

    /// The device's ephemeral public key, encoded as unpadded base64.
    QString keys() const;

    QHash<QString, QString> mac() const;
};
REGISTER_EVENT_TYPE(KeyVerificationMacEvent)

class QUOTIENT_API KeyVerificationDoneEvent : public Event {
public:
    DEFINE_EVENT_TYPEID("m.key.verification.done", KeyVerificationRequestEvent)

    explicit KeyVerificationDoneEvent(const QJsonObject& obj);

    /// The same transactionId as before
    QString transactionId() const;
};
REGISTER_EVENT_TYPE(KeyVerificationDoneEvent)

} // namespace Quotient