Debian Codegraph @

event/verification.go

raw
1 // Copyright (c) 2020 Nikos Filippakis
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 package event
8
9 import (
10 "maunium.net/go/mautrix/id"
11 )
12
13 type VerificationMethod string
14
15 const VerificationMethodSAS VerificationMethod = "m.sas.v1"
16
17 // VerificationRequestEventContent represents the content of a m.key.verification.request to_device event.
18 // https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationrequest
19 type VerificationRequestEventContent struct {
20 // The device ID which is initiating the request.
21 FromDevice id.DeviceID `json:"from_device"`
22 // An opaque identifier for the verification request. Must be unique with respect to the devices involved.
23 TransactionID string `json:"transaction_id,omitempty"`
24 // The verification methods supported by the sender.
25 Methods []VerificationMethod `json:"methods"`
26 // The POSIX timestamp in milliseconds for when the request was made.
27 Timestamp int64 `json:"timestamp,omitempty"`
28 // The user that the event is sent to for in-room verification.
29 To id.UserID `json:"to,omitempty"`
30 // Original event ID for in-room verification.
31 RelatesTo *RelatesTo `json:"m.relates_to,omitempty"`
32 }
33
34 func (vrec *VerificationRequestEventContent) SupportsVerificationMethod(meth VerificationMethod) bool {
35 for _, supportedMeth := range vrec.Methods {
36 if supportedMeth == meth {
37 return true
38 }
39 }
40 return false
41 }
42
43 type KeyAgreementProtocol string
44
45 const (
46 KeyAgreementCurve25519 KeyAgreementProtocol = "curve25519"
47 KeyAgreementCurve25519HKDFSHA256 KeyAgreementProtocol = "curve25519-hkdf-sha256"
48 )
49
50 type VerificationHashMethod string
51
52 const VerificationHashSHA256 VerificationHashMethod = "sha256"
53
54 type MACMethod string
55
56 const HKDFHMACSHA256 MACMethod = "hkdf-hmac-sha256"
57
58 type SASMethod string
59
60 const (
61 SASDecimal SASMethod = "decimal"
62 SASEmoji SASMethod = "emoji"
63 )
64
65 // VerificationStartEventContent represents the content of a m.key.verification.start to_device event.
66 // https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationstartmsasv1
67 type VerificationStartEventContent struct {
68 // The device ID which is initiating the process.
69 FromDevice id.DeviceID `json:"from_device"`
70 // An opaque identifier for the verification process. Must be unique with respect to the devices involved.
71 TransactionID string `json:"transaction_id,omitempty"`
72 // The verification method to use.
73 Method VerificationMethod `json:"method"`
74 // The key agreement protocols the sending device understands.
75 KeyAgreementProtocols []KeyAgreementProtocol `json:"key_agreement_protocols"`
76 // The hash methods the sending device understands.
77 Hashes []VerificationHashMethod `json:"hashes"`
78 // The message authentication codes that the sending device understands.
79 MessageAuthenticationCodes []MACMethod `json:"message_authentication_codes"`
80 // The SAS methods the sending device (and the sending device's user) understands.
81 ShortAuthenticationString []SASMethod `json:"short_authentication_string"`
82 // The user that the event is sent to for in-room verification.
83 To id.UserID `json:"to,omitempty"`
84 // Original event ID for in-room verification.
85 RelatesTo *RelatesTo `json:"m.relates_to,omitempty"`
86 }
87
88 func (vsec *VerificationStartEventContent) SupportsKeyAgreementProtocol(proto KeyAgreementProtocol) bool {
89 for _, supportedProto := range vsec.KeyAgreementProtocols {
90 if supportedProto == proto {
91 return true
92 }
93 }
94 return false
95 }
96
97 func (vsec *VerificationStartEventContent) SupportsHashMethod(alg VerificationHashMethod) bool {
98 for _, supportedAlg := range vsec.Hashes {
99 if supportedAlg == alg {
100 return true
101 }
102 }
103 return false
104 }
105
106 func (vsec *VerificationStartEventContent) SupportsMACMethod(meth MACMethod) bool {
107 for _, supportedMeth := range vsec.MessageAuthenticationCodes {
108 if supportedMeth == meth {
109 return true
110 }
111 }
112 return false
113 }
114
115 func (vsec *VerificationStartEventContent) SupportsSASMethod(meth SASMethod) bool {
116 for _, supportedMeth := range vsec.ShortAuthenticationString {
117 if supportedMeth == meth {
118 return true
119 }
120 }
121 return false
122 }
123
124 func (vsec *VerificationStartEventContent) GetRelatesTo() *RelatesTo {
125 if vsec.RelatesTo == nil {
126 vsec.RelatesTo = &RelatesTo{}
127 }
128 return vsec.RelatesTo
129 }
130
131 func (vsec *VerificationStartEventContent) OptionalGetRelatesTo() *RelatesTo {
132 return vsec.RelatesTo
133 }
134
135 func (vsec *VerificationStartEventContent) SetRelatesTo(rel *RelatesTo) {
136 vsec.RelatesTo = rel
137 }
138
139 // VerificationReadyEventContent represents the content of a m.key.verification.ready event.
140 // https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationready
141 type VerificationReadyEventContent struct {
142 // The device ID which accepted the process.
143 FromDevice id.DeviceID `json:"from_device"`
144 // The verification methods supported by the sender.
145 Methods []VerificationMethod `json:"methods"`
146 // Original event ID for in-room verification.
147 RelatesTo *RelatesTo `json:"m.relates_to,omitempty"`
148 }
149
150 var _ Relatable = (*VerificationReadyEventContent)(nil)
151
152 func (vrec *VerificationReadyEventContent) GetRelatesTo() *RelatesTo {
153 if vrec.RelatesTo == nil {
154 vrec.RelatesTo = &RelatesTo{}
155 }
156 return vrec.RelatesTo
157 }
158
159 func (vrec *VerificationReadyEventContent) OptionalGetRelatesTo() *RelatesTo {
160 return vrec.RelatesTo
161 }
162
163 func (vrec *VerificationReadyEventContent) SetRelatesTo(rel *RelatesTo) {
164 vrec.RelatesTo = rel
165 }
166
167 // VerificationAcceptEventContent represents the content of a m.key.verification.accept to_device event.
168 // https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationaccept
169 type VerificationAcceptEventContent struct {
170 // An opaque identifier for the verification process. Must be the same as the one used for the m.key.verification.start message.
171 TransactionID string `json:"transaction_id,omitempty"`
172 // The verification method to use.
173 Method VerificationMethod `json:"method"`
174 // The key agreement protocol the device is choosing to use, out of the options in the m.key.verification.start message.
175 KeyAgreementProtocol KeyAgreementProtocol `json:"key_agreement_protocol"`
176 // The hash method the device is choosing to use, out of the options in the m.key.verification.start message.
177 Hash VerificationHashMethod `json:"hash"`
178 // The message authentication code the device is choosing to use, out of the options in the m.key.verification.start message.
179 MessageAuthenticationCode MACMethod `json:"message_authentication_code"`
180 // The SAS methods both devices involved in the verification process understand. Must be a subset of the options in the m.key.verification.start message.
181 ShortAuthenticationString []SASMethod `json:"short_authentication_string"`
182 // 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.
183 Commitment string `json:"commitment"`
184 // The user that the event is sent to for in-room verification.
185 To id.UserID `json:"to,omitempty"`
186 // Original event ID for in-room verification.
187 RelatesTo *RelatesTo `json:"m.relates_to,omitempty"`
188 }
189
190 func (vaec *VerificationAcceptEventContent) GetRelatesTo() *RelatesTo {
191 if vaec.RelatesTo == nil {
192 vaec.RelatesTo = &RelatesTo{}
193 }
194 return vaec.RelatesTo
195 }
196
197 func (vaec *VerificationAcceptEventContent) OptionalGetRelatesTo() *RelatesTo {
198 return vaec.RelatesTo
199 }
200
201 func (vaec *VerificationAcceptEventContent) SetRelatesTo(rel *RelatesTo) {
202 vaec.RelatesTo = rel
203 }
204
205 // VerificationKeyEventContent represents the content of a m.key.verification.key to_device event.
206 // https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationkey
207 type VerificationKeyEventContent struct {
208 // An opaque identifier for the verification process. Must be the same as the one used for the m.key.verification.start message.
209 TransactionID string `json:"transaction_id,omitempty"`
210 // The device's ephemeral public key, encoded as unpadded base64.
211 Key string `json:"key"`
212 // The user that the event is sent to for in-room verification.
213 To id.UserID `json:"to,omitempty"`
214 // Original event ID for in-room verification.
215 RelatesTo *RelatesTo `json:"m.relates_to,omitempty"`
216 }
217
218 func (vkec *VerificationKeyEventContent) GetRelatesTo() *RelatesTo {
219 if vkec.RelatesTo == nil {
220 vkec.RelatesTo = &RelatesTo{}
221 }
222 return vkec.RelatesTo
223 }
224
225 func (vkec *VerificationKeyEventContent) OptionalGetRelatesTo() *RelatesTo {
226 return vkec.RelatesTo
227 }
228
229 func (vkec *VerificationKeyEventContent) SetRelatesTo(rel *RelatesTo) {
230 vkec.RelatesTo = rel
231 }
232
233 // VerificationMacEventContent represents the content of a m.key.verification.mac to_device event.
234 // https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationmac
235 type VerificationMacEventContent struct {
236 // An opaque identifier for the verification process. Must be the same as the one used for the m.key.verification.start message.
237 TransactionID string `json:"transaction_id,omitempty"`
238 // A map of the key ID to the MAC of the key, using the algorithm in the verification process. The MAC is encoded as unpadded base64.
239 Mac map[id.KeyID]string `json:"mac"`
240 // The MAC of the comma-separated, sorted, list of key IDs given in the mac property, encoded as unpadded base64.
241 Keys string `json:"keys"`
242 // The user that the event is sent to for in-room verification.
243 To id.UserID `json:"to,omitempty"`
244 // Original event ID for in-room verification.
245 RelatesTo *RelatesTo `json:"m.relates_to,omitempty"`
246 }
247
248 func (vmec *VerificationMacEventContent) GetRelatesTo() *RelatesTo {
249 if vmec.RelatesTo == nil {
250 vmec.RelatesTo = &RelatesTo{}
251 }
252 return vmec.RelatesTo
253 }
254
255 func (vmec *VerificationMacEventContent) OptionalGetRelatesTo() *RelatesTo {
256 return vmec.RelatesTo
257 }
258
259 func (vmec *VerificationMacEventContent) SetRelatesTo(rel *RelatesTo) {
260 vmec.RelatesTo = rel
261 }
262
263 type VerificationCancelCode string
264
265 const (
266 VerificationCancelByUser VerificationCancelCode = "m.user"
267 VerificationCancelByTimeout VerificationCancelCode = "m.timeout"
268 VerificationCancelUnknownTransaction VerificationCancelCode = "m.unknown_transaction"
269 VerificationCancelUnknownMethod VerificationCancelCode = "m.unknown_method"
270 VerificationCancelUnexpectedMessage VerificationCancelCode = "m.unexpected_message"
271 VerificationCancelKeyMismatch VerificationCancelCode = "m.key_mismatch"
272 VerificationCancelUserMismatch VerificationCancelCode = "m.user_mismatch"
273 VerificationCancelInvalidMessage VerificationCancelCode = "m.invalid_message"
274 VerificationCancelAccepted VerificationCancelCode = "m.accepted"
275 VerificationCancelSASMismatch VerificationCancelCode = "m.mismatched_sas"
276 VerificationCancelCommitmentMismatch VerificationCancelCode = "m.mismatched_commitment"
277 )
278
279 // VerificationCancelEventContent represents the content of a m.key.verification.cancel to_device event.
280 // https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationcancel
281 type VerificationCancelEventContent struct {
282 // The opaque identifier for the verification process/request.
283 TransactionID string `json:"transaction_id,omitempty"`
284 // A human readable description of the code. The client should only rely on this string if it does not understand the code.
285 Reason string `json:"reason"`
286 // The error code for why the process/request was cancelled by the user.
287 Code VerificationCancelCode `json:"code"`
288 // The user that the event is sent to for in-room verification.
289 To id.UserID `json:"to,omitempty"`
290 // Original event ID for in-room verification.
291 RelatesTo *RelatesTo `json:"m.relates_to,omitempty"`
292 }
293
294 func (vcec *VerificationCancelEventContent) GetRelatesTo() *RelatesTo {
295 if vcec.RelatesTo == nil {
296 vcec.RelatesTo = &RelatesTo{}
297 }
298 return vcec.RelatesTo
299 }
300
301 func (vcec *VerificationCancelEventContent) OptionalGetRelatesTo() *RelatesTo {
302 return vcec.RelatesTo
303 }
304
305 func (vcec *VerificationCancelEventContent) SetRelatesTo(rel *RelatesTo) {
306 vcec.RelatesTo = rel
307 }