diff --git a/crypto/backup/encryptedsessiondata.go b/crypto/backup/encryptedsessiondata.go index ccaea0c4..8ac74151 100644 --- a/crypto/backup/encryptedsessiondata.go +++ b/crypto/backup/encryptedsessiondata.go @@ -6,10 +6,10 @@ import ( "crypto/hmac" "crypto/rand" "crypto/sha256" - "encoding/base64" "encoding/json" "errors" + "go.mau.fi/util/jsonbytes" "golang.org/x/crypto/hkdf" "maunium.net/go/mautrix/crypto/aescbc" @@ -17,24 +17,6 @@ import ( var ErrInvalidMAC = errors.New("invalid MAC") -// UnpaddedBytes is a byte slice that is encoded and decoded using -// [base64.RawStdEncoding]. -type UnpaddedBytes []byte - -func (b UnpaddedBytes) MarshalJSON() ([]byte, error) { - return json.Marshal(base64.RawStdEncoding.EncodeToString(b)) -} - -func (b *UnpaddedBytes) UnmarshalJSON(data []byte) error { - var b64str string - err := json.Unmarshal(data, &b64str) - if err != nil { - return err - } - *b, err = base64.RawStdEncoding.DecodeString(b64str) - return err -} - // EncryptedSessionData is the encrypted session_data field of a key backup as // defined in [Section 11.12.3.2.2 of the Spec]. // @@ -43,9 +25,9 @@ func (b *UnpaddedBytes) UnmarshalJSON(data []byte) error { // // [Section 11.12.3.2.2 of the Spec]: https://spec.matrix.org/v1.9/client-server-api/#backup-algorithm-mmegolm_backupv1curve25519-aes-sha2 type EncryptedSessionData[T any] struct { - Ciphertext UnpaddedBytes `json:"ciphertext"` - Ephemeral EphemeralKey `json:"ephemeral"` - MAC UnpaddedBytes `json:"mac"` + Ciphertext jsonbytes.UnpaddedBytes `json:"ciphertext"` + Ephemeral EphemeralKey `json:"ephemeral"` + MAC jsonbytes.UnpaddedBytes `json:"mac"` } func calculateEncryptionParameters(sharedSecret []byte) (key, macKey, iv []byte, err error) { diff --git a/event/verification.go b/event/verification.go index 8540c737..60fcb9d4 100644 --- a/event/verification.go +++ b/event/verification.go @@ -7,6 +7,10 @@ package event import ( + "go.mau.fi/util/jsonbytes" + "go.mau.fi/util/jsontime" + "golang.org/x/exp/slices" + "maunium.net/go/mautrix/id" ) @@ -20,308 +24,304 @@ const ( VerificationMethodQRCodeScan VerificationMethod = "m.qr_code.scan.v1" ) -// VerificationRequestEventContent represents the content of a m.key.verification.request to_device event. -// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationrequest -type VerificationRequestEventContent struct { - // The device ID which is initiating the request. - FromDevice id.DeviceID `json:"from_device"` - // An opaque identifier for the verification request. Must be unique with respect to the devices involved. - TransactionID string `json:"transaction_id,omitempty"` - // The verification methods supported by the sender. - Methods []VerificationMethod `json:"methods"` - // The POSIX timestamp in milliseconds for when the request was made. - Timestamp int64 `json:"timestamp,omitempty"` - // The user that the event is sent to for in-room verification. - To id.UserID `json:"to,omitempty"` - // Original event ID for in-room verification. +type VerificationTransactionable interface { + GetTransactionID() id.VerificationTransactionID + SetTransactionID(id.VerificationTransactionID) +} + +// ToDeviceVerificationEvent contains the fields common to all to-device +// verification events. +type ToDeviceVerificationEvent struct { + // TransactionID is an opaque identifier for the verification request. Must + // be unique with respect to the devices involved. + TransactionID id.VerificationTransactionID `json:"transaction_id,omitempty"` +} + +var _ VerificationTransactionable = (*ToDeviceVerificationEvent)(nil) + +func (ve *ToDeviceVerificationEvent) GetTransactionID() id.VerificationTransactionID { + return ve.TransactionID +} + +func (ve *ToDeviceVerificationEvent) SetTransactionID(id id.VerificationTransactionID) { + ve.TransactionID = id +} + +// InRoomVerificationEvent contains the fields common to all in-room +// verification events. +type InRoomVerificationEvent struct { + // RelatesTo indicates the m.key.verification.request that this message is + // related to. Note that for encrypted messages, this property should be in + // the unencrypted portion of the event. RelatesTo *RelatesTo `json:"m.relates_to,omitempty"` } -func (vrec *VerificationRequestEventContent) SupportsVerificationMethod(meth VerificationMethod) bool { - for _, supportedMeth := range vrec.Methods { - if supportedMeth == meth { - return true - } +var _ Relatable = (*InRoomVerificationEvent)(nil) + +func (ve *InRoomVerificationEvent) GetRelatesTo() *RelatesTo { + if ve.RelatesTo == nil { + ve.RelatesTo = &RelatesTo{} } - return false + return ve.RelatesTo +} + +func (ve *InRoomVerificationEvent) OptionalGetRelatesTo() *RelatesTo { + return ve.RelatesTo +} + +func (ve *InRoomVerificationEvent) SetRelatesTo(rel *RelatesTo) { + ve.RelatesTo = rel +} + +// VerificationRequestEventContent represents the content of an +// [m.key.verification.request] to-device event as described in [Section +// 11.12.2.1] of the Spec. +// +// For the in-room version, use a standard [MessageEventContent] struct. +// +// [m.key.verification.request]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationrequest +// [Section 11.12.2.1]: https://spec.matrix.org/v1.9/client-server-api/#key-verification-framework +type VerificationRequestEventContent struct { + ToDeviceVerificationEvent + // FromDevice is the device ID which is initiating the request. + FromDevice id.DeviceID `json:"from_device"` + // Methods is a list of the verification methods supported by the sender. + Methods []VerificationMethod `json:"methods"` + // Timestamp is the time at which the request was made. + Timestamp jsontime.UnixMilli `json:"timestamp,omitempty"` +} + +// VerificationRequestEventContentFromMessage converts an in-room verification +// request message event to a [VerificationRequestEventContent]. +func VerificationRequestEventContentFromMessage(evt *Event) *VerificationRequestEventContent { + content := evt.Content.AsMessage() + return &VerificationRequestEventContent{ + ToDeviceVerificationEvent: ToDeviceVerificationEvent{ + TransactionID: id.VerificationTransactionID(evt.ID), + }, + Timestamp: jsontime.UMInt(evt.Timestamp), + FromDevice: content.FromDevice, + Methods: content.Methods, + } +} + +// SupportsVerificationMethod returns whether the given verification method is +// supported by the sender. +func (vrec *VerificationRequestEventContent) SupportsVerificationMethod(method VerificationMethod) bool { + return slices.Contains(vrec.Methods, method) +} + +// VerificationReadyEventContent represents the content of an +// [m.key.verification.ready] event (both the to-device and the in-room +// version) as described in [Section 11.12.2.1] of the Spec. +// +// [m.key.verification.ready]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationready +// [Section 11.12.2.1]: https://spec.matrix.org/v1.9/client-server-api/#key-verification-framework +type VerificationReadyEventContent struct { + ToDeviceVerificationEvent + InRoomVerificationEvent + + // FromDevice is the device ID which is initiating the request. + FromDevice id.DeviceID `json:"from_device"` + // Methods is a list of the verification methods supported by the sender. + Methods []VerificationMethod `json:"methods"` } type KeyAgreementProtocol string const ( - KeyAgreementCurve25519 KeyAgreementProtocol = "curve25519" - KeyAgreementCurve25519HKDFSHA256 KeyAgreementProtocol = "curve25519-hkdf-sha256" + KeyAgreementProtocolCurve25519 KeyAgreementProtocol = "curve25519" + KeyAgreementProtocolCurve25519HKDFSHA256 KeyAgreementProtocol = "curve25519-hkdf-sha256" ) type VerificationHashMethod string -const VerificationHashSHA256 VerificationHashMethod = "sha256" +const VerificationHashMethodSHA256 VerificationHashMethod = "sha256" type MACMethod string -const HKDFHMACSHA256 MACMethod = "hkdf-hmac-sha256" +const ( + MACMethodHKDFHMACSHA256 MACMethod = "hkdf-hmac-sha256" + MACMethodHKDFHMACSHA256V2 MACMethod = "hkdf-hmac-sha256.v2" +) type SASMethod string const ( - SASDecimal SASMethod = "decimal" - SASEmoji SASMethod = "emoji" + SASMethodDecimal SASMethod = "decimal" + SASMethodEmoji SASMethod = "emoji" ) -// VerificationStartEventContent represents the content of a m.key.verification.start to_device event. -// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationstartmsasv1 +// VerificationStartEventContent represents the content of an +// [m.key.verification.start] event (both the to-device and the in-room +// version) as described in [Section 11.12.2.1] of the Spec. +// +// This struct also contains the fields for an [m.key.verification.start] event +// using the [VerificationMethodSAS] method as described in [Section +// 11.12.2.2.2] and an [m.key.verification.start] using +// [VerificationMethodReciprocate] as described in [Section 11.12.2.4.2]. +// +// [m.key.verification.start]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationstart +// [Section 11.12.2.1]: https://spec.matrix.org/v1.9/client-server-api/#key-verification-framework +// [Section 11.12.2.2.2]: https://spec.matrix.org/v1.9/client-server-api/#verification-messages-specific-to-sas +// [Section 11.12.2.4.2]: https://spec.matrix.org/v1.9/client-server-api/#verification-messages-specific-to-qr-codes type VerificationStartEventContent struct { - // The device ID which is initiating the process. + ToDeviceVerificationEvent + InRoomVerificationEvent + + // FromDevice is the device ID which is initiating the request. FromDevice id.DeviceID `json:"from_device"` - // An opaque identifier for the verification process. Must be unique with respect to the devices involved. - TransactionID string `json:"transaction_id,omitempty"` - // The verification method to use. + // Method is the verification method to use. Method VerificationMethod `json:"method"` - // The key agreement protocols the sending device understands. - KeyAgreementProtocols []KeyAgreementProtocol `json:"key_agreement_protocols"` - // The hash methods the sending device understands. - Hashes []VerificationHashMethod `json:"hashes"` - // The message authentication codes that the sending device understands. + // NextMethod is an optional method to use to verify the other user's key. + // Applicable when the method chosen only verifies one user’s key. This + // field will never be present if the method verifies keys both ways. + NextMethod VerificationMethod `json:"next_method,omitempty"` + + // Hashes are the hash methods the sending device understands. This field + // is only applicable when the method is m.sas.v1. + Hashes []VerificationHashMethod `json:"hashes,omitempty"` + // KeyAgreementProtocols is the list of key agreement protocols the sending + // device understands. This field is only applicable when the method is + // m.sas.v1. + KeyAgreementProtocols []KeyAgreementProtocol `json:"key_agreement_protocols,omitempty"` + // MessageAuthenticationCodes is a list of the MAC methods that the sending + // device understands. This field is only applicable when the method is + // m.sas.v1. MessageAuthenticationCodes []MACMethod `json:"message_authentication_codes"` - // The SAS methods the sending device (and the sending device's user) understands. + // ShortAuthenticationString is a list of SAS methods the sending device + // (and the sending device's user) understands. This field is only + // applicable when the method is m.sas.v1. ShortAuthenticationString []SASMethod `json:"short_authentication_string"` - // The user that the event is sent to for in-room verification. - To id.UserID `json:"to,omitempty"` - // Original event ID for in-room verification. - RelatesTo *RelatesTo `json:"m.relates_to,omitempty"` + + // Secret is the shared secret from the QR code. This field is only + // applicable when the method is m.reciprocate.v1. + Secret jsonbytes.UnpaddedBytes `json:"secret,omitempty"` } func (vsec *VerificationStartEventContent) SupportsKeyAgreementProtocol(proto KeyAgreementProtocol) bool { - for _, supportedProto := range vsec.KeyAgreementProtocols { - if supportedProto == proto { - return true - } - } - return false + return slices.Contains(vsec.KeyAgreementProtocols, proto) } func (vsec *VerificationStartEventContent) SupportsHashMethod(alg VerificationHashMethod) bool { - for _, supportedAlg := range vsec.Hashes { - if supportedAlg == alg { - return true - } - } - return false + return slices.Contains(vsec.Hashes, alg) } func (vsec *VerificationStartEventContent) SupportsMACMethod(meth MACMethod) bool { - for _, supportedMeth := range vsec.MessageAuthenticationCodes { - if supportedMeth == meth { - return true - } - } - return false + return slices.Contains(vsec.MessageAuthenticationCodes, meth) } func (vsec *VerificationStartEventContent) SupportsSASMethod(meth SASMethod) bool { - for _, supportedMeth := range vsec.ShortAuthenticationString { - if supportedMeth == meth { - return true - } - } - return false + return slices.Contains(vsec.ShortAuthenticationString, meth) } -func (vsec *VerificationStartEventContent) GetRelatesTo() *RelatesTo { - if vsec.RelatesTo == nil { - vsec.RelatesTo = &RelatesTo{} - } - return vsec.RelatesTo -} - -func (vsec *VerificationStartEventContent) OptionalGetRelatesTo() *RelatesTo { - return vsec.RelatesTo -} - -func (vsec *VerificationStartEventContent) SetRelatesTo(rel *RelatesTo) { - vsec.RelatesTo = rel -} - -// VerificationReadyEventContent represents the content of a m.key.verification.ready event. -// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationready -type VerificationReadyEventContent struct { - // The device ID which accepted the process. - FromDevice id.DeviceID `json:"from_device"` - // An opaque identifier for the verification process. Must be unique with respect to the devices involved. - TransactionID string `json:"transaction_id,omitempty"` - // The verification methods supported by the sender. - Methods []VerificationMethod `json:"methods"` - // Original event ID for in-room verification. - RelatesTo *RelatesTo `json:"m.relates_to,omitempty"` -} - -var _ Relatable = (*VerificationReadyEventContent)(nil) - -func (vrec *VerificationReadyEventContent) GetRelatesTo() *RelatesTo { - if vrec.RelatesTo == nil { - vrec.RelatesTo = &RelatesTo{} - } - return vrec.RelatesTo -} - -func (vrec *VerificationReadyEventContent) OptionalGetRelatesTo() *RelatesTo { - return vrec.RelatesTo -} - -func (vrec *VerificationReadyEventContent) SetRelatesTo(rel *RelatesTo) { - vrec.RelatesTo = rel -} - -// VerificationDoneEventContent represents the content of a -// m.key.verification.done event as described in [Section 11.12.2.1] of the -// Matrix Spec. +// VerificationDoneEventContent represents the content of an +// [m.key.verification.done] event (both the to-device and the in-room version) +// as described in [Section 11.12.2.1] of the Spec. // +// This type is an alias for [VerificationRelatable] since there are no +// additional fields defined by the spec. +// +// [m.key.verification.done]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationdone // [Section 11.12.2.1]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationdone type VerificationDoneEventContent struct { - // The opaque identifier for the verification process/request. - TransactionID string `json:"transaction_id,omitempty"` - // Original event ID for in-room verification. - RelatesTo *RelatesTo `json:"m.relates_to,omitempty"` + ToDeviceVerificationEvent + InRoomVerificationEvent } type VerificationCancelCode string const ( - VerificationCancelByUser VerificationCancelCode = "m.user" - VerificationCancelByTimeout VerificationCancelCode = "m.timeout" - VerificationCancelUnknownTransaction VerificationCancelCode = "m.unknown_transaction" - VerificationCancelUnknownMethod VerificationCancelCode = "m.unknown_method" - VerificationCancelUnexpectedMessage VerificationCancelCode = "m.unexpected_message" - VerificationCancelKeyMismatch VerificationCancelCode = "m.key_mismatch" - VerificationCancelUserMismatch VerificationCancelCode = "m.user_mismatch" - VerificationCancelInvalidMessage VerificationCancelCode = "m.invalid_message" - VerificationCancelAccepted VerificationCancelCode = "m.accepted" - VerificationCancelSASMismatch VerificationCancelCode = "m.mismatched_sas" - VerificationCancelCommitmentMismatch VerificationCancelCode = "m.mismatched_commitment" + VerificationCancelCodeUser VerificationCancelCode = "m.user" + VerificationCancelCodeTimeout VerificationCancelCode = "m.timeout" + VerificationCancelCodeUnknownTransaction VerificationCancelCode = "m.unknown_transaction" + VerificationCancelCodeUnknownMethod VerificationCancelCode = "m.unknown_method" + VerificationCancelCodeUnexpectedMessage VerificationCancelCode = "m.unexpected_message" + VerificationCancelCodeKeyMismatch VerificationCancelCode = "m.key_mismatch" + VerificationCancelCodeUserMismatch VerificationCancelCode = "m.user_mismatch" + VerificationCancelCodeInvalidMessage VerificationCancelCode = "m.invalid_message" + VerificationCancelCodeAccepted VerificationCancelCode = "m.accepted" + VerificationCancelCodeSASMismatch VerificationCancelCode = "m.mismatched_sas" + VerificationCancelCodeCommitmentMismatch VerificationCancelCode = "m.mismatched_commitment" ) -// VerificationCancelEventContent represents the content of a m.key.verification.cancel to_device event. -// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationcancel +// VerificationCancelEventContent represents the content of an +// [m.key.verification.cancel] event (both the to-device and the in-room +// version) as described in [Section 11.12.2.1] of the Spec. +// +// [m.key.verification.cancel]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationcancel +// [Section 11.12.2.1]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationdone type VerificationCancelEventContent struct { - // The opaque identifier for the verification process/request. - TransactionID string `json:"transaction_id,omitempty"` - // A human readable description of the code. The client should only rely on this string if it does not understand the code. - Reason string `json:"reason"` - // The error code for why the process/request was cancelled by the user. + ToDeviceVerificationEvent + InRoomVerificationEvent + + // Code is the error code for why the process/request was cancelled by the + // user. Code VerificationCancelCode `json:"code"` - // The user that the event is sent to for in-room verification. - To id.UserID `json:"to,omitempty"` - // Original event ID for in-room verification. - RelatesTo *RelatesTo `json:"m.relates_to,omitempty"` + // Reason is a human readable description of the code. The client should + // only rely on this string if it does not understand the code. + Reason string `json:"reason"` } -func (vcec *VerificationCancelEventContent) GetRelatesTo() *RelatesTo { - if vcec.RelatesTo == nil { - vcec.RelatesTo = &RelatesTo{} - } - return vcec.RelatesTo -} - -func (vcec *VerificationCancelEventContent) OptionalGetRelatesTo() *RelatesTo { - return vcec.RelatesTo -} - -func (vcec *VerificationCancelEventContent) SetRelatesTo(rel *RelatesTo) { - vcec.RelatesTo = rel -} - -// VerificationAcceptEventContent represents the content of a m.key.verification.accept to_device event. -// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationaccept +// VerificationAcceptEventContent represents the content of an +// [m.key.verification.accept] event (both the to-device and the in-room +// version) as described in [Section 11.12.2.2.2] of the Spec. +// +// [m.key.verification.accept]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationaccept +// [Section 11.12.2.2.2]: https://spec.matrix.org/v1.9/client-server-api/#verification-messages-specific-to-sas type VerificationAcceptEventContent struct { - // An opaque identifier for the verification process. Must be the same as the one used for the m.key.verification.start message. - TransactionID string `json:"transaction_id,omitempty"` - // The verification method to use. - Method VerificationMethod `json:"method"` - // The key agreement protocol the device is choosing to use, out of the options in the m.key.verification.start message. - KeyAgreementProtocol KeyAgreementProtocol `json:"key_agreement_protocol"` - // The hash method the device is choosing to use, out of the options in the m.key.verification.start message. + ToDeviceVerificationEvent + InRoomVerificationEvent + + // Commitment is the hash 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. + Commitment jsonbytes.UnpaddedBytes `json:"commitment"` + // Hash is the hash method the device is choosing to use, out of the + // options in the m.key.verification.start message. Hash VerificationHashMethod `json:"hash"` - // The message authentication code the device is choosing to use, out of the options in the m.key.verification.start message. + // KeyAgreementProtocol is the key agreement protocol the device is + // choosing to use, out of the options in the m.key.verification.start + // message. + KeyAgreementProtocol KeyAgreementProtocol `json:"key_agreement_protocol"` + // MessageAuthenticationCode is the message authentication code the device + // is choosing to use, out of the options in the m.key.verification.start + // message. MessageAuthenticationCode MACMethod `json:"message_authentication_code"` - // 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. + // ShortAuthenticationString is a list of SAS methods both devices involved + // in the verification process understand. Must be a subset of the options + // in the m.key.verification.start message. ShortAuthenticationString []SASMethod `json:"short_authentication_string"` - // 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. - Commitment string `json:"commitment"` - // The user that the event is sent to for in-room verification. - To id.UserID `json:"to,omitempty"` - // Original event ID for in-room verification. - RelatesTo *RelatesTo `json:"m.relates_to,omitempty"` } -func (vaec *VerificationAcceptEventContent) GetRelatesTo() *RelatesTo { - if vaec.RelatesTo == nil { - vaec.RelatesTo = &RelatesTo{} - } - return vaec.RelatesTo -} - -func (vaec *VerificationAcceptEventContent) OptionalGetRelatesTo() *RelatesTo { - return vaec.RelatesTo -} - -func (vaec *VerificationAcceptEventContent) SetRelatesTo(rel *RelatesTo) { - vaec.RelatesTo = rel -} - -// VerificationKeyEventContent represents the content of a m.key.verification.key to_device event. -// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationkey +// VerificationKeyEventContent represents the content of an +// [m.key.verification.key] event (both the to-device and the in-room version) +// as described in [Section 11.12.2.2.2] of the Spec. +// +// [m.key.verification.key]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationkey +// [Section 11.12.2.2.2]: https://spec.matrix.org/v1.9/client-server-api/#verification-messages-specific-to-sas type VerificationKeyEventContent struct { - // An opaque identifier for the verification process. Must be the same as the one used for the m.key.verification.start message. - TransactionID string `json:"transaction_id,omitempty"` - // The device's ephemeral public key, encoded as unpadded base64. - Key string `json:"key"` - // The user that the event is sent to for in-room verification. - To id.UserID `json:"to,omitempty"` - // Original event ID for in-room verification. - RelatesTo *RelatesTo `json:"m.relates_to,omitempty"` + ToDeviceVerificationEvent + InRoomVerificationEvent + + // Key is the device’s ephemeral public key. + Key jsonbytes.UnpaddedBytes `json:"key"` } -func (vkec *VerificationKeyEventContent) GetRelatesTo() *RelatesTo { - if vkec.RelatesTo == nil { - vkec.RelatesTo = &RelatesTo{} - } - return vkec.RelatesTo -} - -func (vkec *VerificationKeyEventContent) OptionalGetRelatesTo() *RelatesTo { - return vkec.RelatesTo -} - -func (vkec *VerificationKeyEventContent) SetRelatesTo(rel *RelatesTo) { - vkec.RelatesTo = rel -} - -// VerificationMacEventContent represents the content of a m.key.verification.mac to_device event. -// https://spec.matrix.org/v1.2/client-server-api/#mkeyverificationmac +// VerificationMacEventContent represents the content of an +// [m.key.verification.mac] event (both the to-device and the in-room version) +// as described in [Section 11.12.2.2.2] of the Spec. +// +// [m.key.verification.mac]: https://spec.matrix.org/v1.9/client-server-api/#mkeyverificationmac +// [Section 11.12.2.2.2]: https://spec.matrix.org/v1.9/client-server-api/#verification-messages-specific-to-sas type VerificationMacEventContent struct { - // An opaque identifier for the verification process. Must be the same as the one used for the m.key.verification.start message. - TransactionID string `json:"transaction_id,omitempty"` - // 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. - Mac map[id.KeyID]string `json:"mac"` - // The MAC of the comma-separated, sorted, list of key IDs given in the mac property, encoded as unpadded base64. - Keys string `json:"keys"` - // The user that the event is sent to for in-room verification. - To id.UserID `json:"to,omitempty"` - // Original event ID for in-room verification. - RelatesTo *RelatesTo `json:"m.relates_to,omitempty"` -} + ToDeviceVerificationEvent + InRoomVerificationEvent -func (vmec *VerificationMacEventContent) GetRelatesTo() *RelatesTo { - if vmec.RelatesTo == nil { - vmec.RelatesTo = &RelatesTo{} - } - return vmec.RelatesTo -} - -func (vmec *VerificationMacEventContent) OptionalGetRelatesTo() *RelatesTo { - return vmec.RelatesTo -} - -func (vmec *VerificationMacEventContent) SetRelatesTo(rel *RelatesTo) { - vmec.RelatesTo = rel + // Keys is the MAC of the comma-separated, sorted, list of key IDs given in + // the MAC property. + Keys jsonbytes.UnpaddedBytes `json:"keys"` + // MAC is a map of the key ID to the MAC of the key, using the algorithm in + // the verification process. + MAC map[id.KeyID]jsonbytes.UnpaddedBytes `json:"mac"` }