mirror of
https://github.com/element-hq/element-android
synced 2024-11-29 05:58:50 +03:00
Convert KeyVerificationStart to data class
This commit is contained in:
parent
4ac7331f3d
commit
0a2ffdbdf1
4 changed files with 40 additions and 73 deletions
|
@ -27,75 +27,36 @@ import timber.log.Timber
|
||||||
* Sent by Alice to initiate an interactive key verification.
|
* Sent by Alice to initiate an interactive key verification.
|
||||||
*/
|
*/
|
||||||
@JsonClass(generateAdapter = true)
|
@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<String>? = null,
|
||||||
|
@Json(name = "hashes") override val hashes: List<String>? = null,
|
||||||
|
@Json(name = "message_authentication_codes") override val messageAuthenticationCodes: List<String>? = null,
|
||||||
|
@Json(name = "short_authentication_string") override val shortAuthenticationStrings: List<String>? = null
|
||||||
|
) : SendToDeviceObject, VerificationInfoStart {
|
||||||
|
|
||||||
override fun toCanonicalJson(): String? {
|
override fun toCanonicalJson(): String? {
|
||||||
return JsonCanonicalizer.getCanonicalJson(KeyVerificationStart::class.java, this)
|
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<String>? = 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<String>? = 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<String>? = 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<String>? = null
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val VERIF_METHOD_SAS = "m.sas.v1"
|
const val VERIF_METHOD_SAS = "m.sas.v1"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isValid(): Boolean {
|
override fun isValid(): Boolean {
|
||||||
if (transactionID.isNullOrBlank()
|
if ((transactionID.isNullOrBlank()
|
||||||
|| fromDevice.isNullOrBlank()
|
|| fromDevice.isNullOrBlank()
|
||||||
|| method != VERIF_METHOD_SAS
|
|| method != VERIF_METHOD_SAS
|
||||||
|| keyAgreementProtocols.isNullOrEmpty()
|
|| keyAgreementProtocols.isNullOrEmpty()
|
||||||
|| hashes.isNullOrEmpty()
|
|| hashes.isNullOrEmpty())
|
||||||
|| hashes?.contains("sha256") == false
|
|| !hashes.contains("sha256")
|
||||||
|| messageAuthenticationCodes.isNullOrEmpty()
|
|| messageAuthenticationCodes.isNullOrEmpty()
|
||||||
|| (messageAuthenticationCodes?.contains(SASVerificationTransaction.SAS_MAC_SHA256) == false
|
|| (!messageAuthenticationCodes.contains(SASVerificationTransaction.SAS_MAC_SHA256)
|
||||||
&& messageAuthenticationCodes?.contains(SASVerificationTransaction.SAS_MAC_SHA256_LONGKDF) == false)
|
&& !messageAuthenticationCodes.contains(SASVerificationTransaction.SAS_MAC_SHA256_LONGKDF))
|
||||||
|| shortAuthenticationStrings.isNullOrEmpty()
|
|| shortAuthenticationStrings.isNullOrEmpty() || !shortAuthenticationStrings.contains(SasMode.DECIMAL)) {
|
||||||
|| shortAuthenticationStrings?.contains(SasMode.DECIMAL) == false) {
|
|
||||||
Timber.e("## received invalid verification request")
|
Timber.e("## received invalid verification request")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,14 +239,8 @@ internal class DefaultSasVerificationService @Inject constructor(
|
||||||
if (!startReq.isValid()) {
|
if (!startReq.isValid()) {
|
||||||
Timber.e("## SAS received invalid verification request")
|
Timber.e("## SAS received invalid verification request")
|
||||||
if (startReq.transactionID != null) {
|
if (startReq.transactionID != null) {
|
||||||
// cancelTransaction(
|
|
||||||
// startReq.transactionID!!,
|
|
||||||
// otherUserId!!,
|
|
||||||
// startReq.fromDevice ?: event.getSenderKey()!!,
|
|
||||||
// CancelCode.UnknownMethod
|
|
||||||
// )
|
|
||||||
sasTransportToDeviceFactory.createTransport(null).cancelTransaction(
|
sasTransportToDeviceFactory.createTransport(null).cancelTransaction(
|
||||||
startReq.transactionID ?: "",
|
startReq.transactionID,
|
||||||
otherUserId!!,
|
otherUserId!!,
|
||||||
startReq.fromDevice ?: event.getSenderKey()!!,
|
startReq.fromDevice ?: event.getSenderKey()!!,
|
||||||
CancelCode.UnknownMethod
|
CancelCode.UnknownMethod
|
||||||
|
|
|
@ -118,15 +118,14 @@ internal class SasTransportToDevice(
|
||||||
hashes: List<String>,
|
hashes: List<String>,
|
||||||
messageAuthenticationCodes: List<String>,
|
messageAuthenticationCodes: List<String>,
|
||||||
shortAuthenticationStrings: List<String>): VerificationInfoStart {
|
shortAuthenticationStrings: List<String>): VerificationInfoStart {
|
||||||
return KeyVerificationStart().apply {
|
return KeyVerificationStart(
|
||||||
this.fromDevice = fromDevice
|
fromDevice,
|
||||||
this.method = method
|
method,
|
||||||
this.transactionID = transactionID
|
transactionID,
|
||||||
this.keyAgreementProtocols = keyAgreementProtocols
|
keyAgreementProtocols,
|
||||||
this.hashes = hashes
|
hashes,
|
||||||
this.messageAuthenticationCodes = messageAuthenticationCodes
|
messageAuthenticationCodes,
|
||||||
this.shortAuthenticationStrings = shortAuthenticationStrings
|
shortAuthenticationStrings)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,23 @@ package im.vector.matrix.android.internal.crypto.verification
|
||||||
internal interface VerificationInfoStart : VerificationInfo {
|
internal interface VerificationInfoStart : VerificationInfo {
|
||||||
|
|
||||||
val method: String?
|
val method: String?
|
||||||
|
/**
|
||||||
|
* Alice’s device ID
|
||||||
|
*/
|
||||||
val fromDevice: String?
|
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?
|
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<String>?
|
val keyAgreementProtocols: List<String>?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue