diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationStart.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationStart.kt index 47c2a62d92..d1e0ff9049 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationStart.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationStart.kt @@ -27,75 +27,36 @@ import timber.log.Timber * Sent by Alice to initiate an interactive key verification. */ @JsonClass(generateAdapter = true) -class KeyVerificationStart : SendToDeviceObject, VerificationInfoStart { +data class KeyVerificationStart( + @Json(name = "from_device") override val fromDevice: String? = null, + override val method: String? = null, + @Json(name = "transaction_id") override val transactionID: String? = null, + @Json(name = "key_agreement_protocols") override val keyAgreementProtocols: List? = null, + @Json(name = "hashes") override val hashes: List? = null, + @Json(name = "message_authentication_codes") override val messageAuthenticationCodes: List? = null, + @Json(name = "short_authentication_string") override val shortAuthenticationStrings: List? = null +) : SendToDeviceObject, VerificationInfoStart { override fun toCanonicalJson(): String? { return JsonCanonicalizer.getCanonicalJson(KeyVerificationStart::class.java, this) } - /** - * Alice’s device ID - */ - @Json(name = "from_device") - override var fromDevice: String? = null - - override var method: String? = null - - /** - * String to identify the transaction. - * This string must be unique for the pair of users performing verification for the duration that the transaction is valid. - * Alice’s device should record this ID and use it in future messages in this transaction. - */ - @Json(name = "transaction_id") - override var transactionID: String? = null - - /** - * An array of key agreement protocols that Alice’s client understands. - * Must include “curve25519”. - * Other methods may be defined in the future - */ - @Json(name = "key_agreement_protocols") - override var keyAgreementProtocols: List? = null - - /** - * An array of hashes that Alice’s client understands. - * Must include “sha256”. Other methods may be defined in the future. - */ - override var hashes: List? = null - - /** - * An array of message authentication codes that Alice’s client understands. - * Must include “hkdf-hmac-sha256”. - * Other methods may be defined in the future. - */ - @Json(name = "message_authentication_codes") - override var messageAuthenticationCodes: List? = null - - /** - * An array of short authentication string methods that Alice’s client (and Alice) understands. - * Must include “decimal”. - * This document also describes the “emoji” method. - * Other methods may be defined in the future - */ - @Json(name = "short_authentication_string") - override var shortAuthenticationStrings: List? = null companion object { const val VERIF_METHOD_SAS = "m.sas.v1" } override fun isValid(): Boolean { - if (transactionID.isNullOrBlank() - || fromDevice.isNullOrBlank() - || method != VERIF_METHOD_SAS - || keyAgreementProtocols.isNullOrEmpty() - || hashes.isNullOrEmpty() - || hashes?.contains("sha256") == false + if ((transactionID.isNullOrBlank() + || fromDevice.isNullOrBlank() + || method != VERIF_METHOD_SAS + || keyAgreementProtocols.isNullOrEmpty() + || hashes.isNullOrEmpty()) + || !hashes.contains("sha256") || messageAuthenticationCodes.isNullOrEmpty() - || (messageAuthenticationCodes?.contains(SASVerificationTransaction.SAS_MAC_SHA256) == false - && messageAuthenticationCodes?.contains(SASVerificationTransaction.SAS_MAC_SHA256_LONGKDF) == false) - || shortAuthenticationStrings.isNullOrEmpty() - || shortAuthenticationStrings?.contains(SasMode.DECIMAL) == false) { + || (!messageAuthenticationCodes.contains(SASVerificationTransaction.SAS_MAC_SHA256) + && !messageAuthenticationCodes.contains(SASVerificationTransaction.SAS_MAC_SHA256_LONGKDF)) + || shortAuthenticationStrings.isNullOrEmpty() || !shortAuthenticationStrings.contains(SasMode.DECIMAL)) { Timber.e("## received invalid verification request") return false } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt index 2546f1f492..d7e01c2fde 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/DefaultSasVerificationService.kt @@ -239,14 +239,8 @@ internal class DefaultSasVerificationService @Inject constructor( if (!startReq.isValid()) { Timber.e("## SAS received invalid verification request") if (startReq.transactionID != null) { -// cancelTransaction( -// startReq.transactionID!!, -// otherUserId!!, -// startReq.fromDevice ?: event.getSenderKey()!!, -// CancelCode.UnknownMethod -// ) sasTransportToDeviceFactory.createTransport(null).cancelTransaction( - startReq.transactionID ?: "", + startReq.transactionID, otherUserId!!, startReq.fromDevice ?: event.getSenderKey()!!, CancelCode.UnknownMethod diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportToDevice.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportToDevice.kt index f1b472ae75..bce23de1cd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportToDevice.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/SasTransportToDevice.kt @@ -118,15 +118,14 @@ internal class SasTransportToDevice( hashes: List, messageAuthenticationCodes: List, shortAuthenticationStrings: List): VerificationInfoStart { - return KeyVerificationStart().apply { - this.fromDevice = fromDevice - this.method = method - this.transactionID = transactionID - this.keyAgreementProtocols = keyAgreementProtocols - this.hashes = hashes - this.messageAuthenticationCodes = messageAuthenticationCodes - this.shortAuthenticationStrings = shortAuthenticationStrings - } + return KeyVerificationStart( + fromDevice, + method, + transactionID, + keyAgreementProtocols, + hashes, + messageAuthenticationCodes, + shortAuthenticationStrings) } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoStart.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoStart.kt index f1cbd3f9f1..2248a239fb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoStart.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationInfoStart.kt @@ -18,10 +18,23 @@ package im.vector.matrix.android.internal.crypto.verification internal interface VerificationInfoStart : VerificationInfo { val method: String? + /** + * Alice’s device ID + */ val fromDevice: String? + /** + * String to identify the transaction. + * This string must be unique for the pair of users performing verification for the duration that the transaction is valid. + * Alice’s device should record this ID and use it in future messages in this transaction. + */ val transactionID: String? + /** + * An array of key agreement protocols that Alice’s client understands. + * Must include “curve25519”. + * Other methods may be defined in the future + */ val keyAgreementProtocols: List? /**