mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 21:48:50 +03:00
Code review
This commit is contained in:
parent
6137a88a6f
commit
5f3dc73440
36 changed files with 140 additions and 142 deletions
|
@ -20,8 +20,8 @@ import com.squareup.moshi.JsonClass
|
|||
import im.vector.matrix.android.api.session.events.model.RelationType
|
||||
import im.vector.matrix.android.api.session.events.model.toContent
|
||||
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
|
||||
import im.vector.matrix.android.internal.crypto.verification.AcceptVerifInfoFactory
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoAccept
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoAcceptFactory
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoAccept
|
||||
import timber.log.Timber
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
|
@ -32,7 +32,7 @@ internal data class MessageVerificationAcceptContent(
|
|||
@Json(name = "short_authentication_string") override val shortAuthenticationStrings: List<String>?,
|
||||
@Json(name = "m.relates_to") val relatesTo: RelationDefaultContent?,
|
||||
@Json(name = "commitment") override var commitment: String? = null
|
||||
) : VerifInfoAccept {
|
||||
) : VerificationInfoAccept {
|
||||
|
||||
override val transactionID: String?
|
||||
get() = relatesTo?.eventId
|
||||
|
@ -52,14 +52,14 @@ internal data class MessageVerificationAcceptContent(
|
|||
|
||||
override fun toEventContent() = this.toContent()
|
||||
|
||||
companion object : AcceptVerifInfoFactory {
|
||||
companion object : VerificationInfoAcceptFactory {
|
||||
|
||||
override fun create(tid: String,
|
||||
keyAgreementProtocol: String,
|
||||
hash: String,
|
||||
commitment: String,
|
||||
messageAuthenticationCode: String,
|
||||
shortAuthenticationStrings: List<String>): VerifInfoAccept {
|
||||
shortAuthenticationStrings: List<String>): VerificationInfoAccept {
|
||||
return MessageVerificationAcceptContent(
|
||||
hash,
|
||||
keyAgreementProtocol,
|
||||
|
|
|
@ -21,7 +21,7 @@ import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
|||
import im.vector.matrix.android.api.session.events.model.RelationType
|
||||
import im.vector.matrix.android.api.session.events.model.toContent
|
||||
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoCancel
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoCancel
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal data class MessageVerificationCancelContent(
|
||||
|
@ -29,7 +29,7 @@ internal data class MessageVerificationCancelContent(
|
|||
@Json(name = "reason") override val reason: String? = null,
|
||||
@Json(name = "m.relates_to") val relatesTo: RelationDefaultContent?
|
||||
|
||||
) : VerifInfoCancel {
|
||||
) : VerificationInfoCancel {
|
||||
|
||||
override val transactionID: String?
|
||||
get() = relatesTo?.eventId
|
||||
|
|
|
@ -20,8 +20,8 @@ import com.squareup.moshi.JsonClass
|
|||
import im.vector.matrix.android.api.session.events.model.RelationType
|
||||
import im.vector.matrix.android.api.session.events.model.toContent
|
||||
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoKey
|
||||
import im.vector.matrix.android.internal.crypto.verification.KeyVerifInfoFactory
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoKey
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoKeyFactory
|
||||
import timber.log.Timber
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
|
@ -31,7 +31,7 @@ internal data class MessageVerificationKeyContent(
|
|||
*/
|
||||
@Json(name = "key") override val key: String? = null,
|
||||
@Json(name = "m.relates_to") val relatesTo: RelationDefaultContent?
|
||||
) : VerifInfoKey {
|
||||
) : VerificationInfoKey {
|
||||
|
||||
override val transactionID: String?
|
||||
get() = relatesTo?.eventId
|
||||
|
@ -46,9 +46,9 @@ internal data class MessageVerificationKeyContent(
|
|||
|
||||
override fun toEventContent() = this.toContent()
|
||||
|
||||
companion object : KeyVerifInfoFactory {
|
||||
companion object : VerificationInfoKeyFactory {
|
||||
|
||||
override fun create(tid: String, pubKey: String): VerifInfoKey {
|
||||
override fun create(tid: String, pubKey: String): VerificationInfoKey {
|
||||
return MessageVerificationKeyContent(
|
||||
pubKey,
|
||||
RelationDefaultContent(
|
||||
|
|
|
@ -20,15 +20,15 @@ import com.squareup.moshi.JsonClass
|
|||
import im.vector.matrix.android.api.session.events.model.RelationType
|
||||
import im.vector.matrix.android.api.session.events.model.toContent
|
||||
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoMac
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoMacFactory
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoMac
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoMacFactory
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal data class MessageVerificationMacContent(
|
||||
@Json(name = "mac") override val mac: Map<String, String>? = null,
|
||||
@Json(name = "keys") override val keys: String? = null,
|
||||
@Json(name = "m.relates_to") val relatesTo: RelationDefaultContent?
|
||||
) : VerifInfoMac {
|
||||
) : VerificationInfoMac {
|
||||
|
||||
override val transactionID: String?
|
||||
get() = relatesTo?.eventId
|
||||
|
@ -42,8 +42,8 @@ internal data class MessageVerificationMacContent(
|
|||
return true
|
||||
}
|
||||
|
||||
companion object : VerifInfoMacFactory {
|
||||
override fun create(tid: String, mac: Map<String, String>, keys: String): VerifInfoMac {
|
||||
companion object : VerificationInfoMacFactory {
|
||||
override fun create(tid: String, mac: Map<String, String>, keys: String): VerificationInfoMac {
|
||||
return MessageVerificationMacContent(
|
||||
mac,
|
||||
keys,
|
||||
|
|
|
@ -21,12 +21,12 @@ import im.vector.matrix.android.api.session.events.model.Content
|
|||
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class MessageVerificationRequestContent(
|
||||
internal data class MessageVerificationRequestContent(
|
||||
@Json(name = "msgtype") override val type: String = MessageType.MSGTYPE_VERIFICATION_REQUEST,
|
||||
@Json(name = "body") override val body: String,
|
||||
@Json(name = "from_device") val fromDevice: String,
|
||||
@Json(name = "methods") val methods: List<String>,
|
||||
@Json(name = "to") val to: String,
|
||||
@Json(name = "to") val toUserId: String,
|
||||
// @Json(name = "timestamp") val timestamp: Int,
|
||||
@Json(name = "format") val format: String? = null,
|
||||
@Json(name = "formatted_body") val formattedBody: String? = null,
|
||||
|
|
|
@ -22,12 +22,12 @@ import im.vector.matrix.android.api.session.events.model.toContent
|
|||
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationStart
|
||||
import im.vector.matrix.android.internal.crypto.verification.SASVerificationTransaction
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoStart
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoStart
|
||||
import im.vector.matrix.android.internal.util.JsonCanonicalizer
|
||||
import timber.log.Timber
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class MessageVerificationStartContent(
|
||||
internal data class MessageVerificationStartContent(
|
||||
@Json(name = "from_device") override val fromDevice: String?,
|
||||
@Json(name = "hashes") override val hashes: List<String>?,
|
||||
@Json(name = "key_agreement_protocols") override val keyAgreementProtocols: List<String>?,
|
||||
|
@ -35,7 +35,7 @@ data class MessageVerificationStartContent(
|
|||
@Json(name = "short_authentication_string") override val shortAuthenticationStrings: List<String>?,
|
||||
@Json(name = "method") override val method: String?,
|
||||
@Json(name = "m.relates_to") val relatesTo: RelationDefaultContent?
|
||||
) : VerifInfoStart {
|
||||
) : VerificationInfoStart {
|
||||
|
||||
override fun toCanonicalJson(): String? {
|
||||
return JsonCanonicalizer.getCanonicalJson(MessageVerificationStartContent::class.java, this)
|
||||
|
|
|
@ -17,8 +17,8 @@ package im.vector.matrix.android.internal.crypto.model.rest
|
|||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoAccept
|
||||
import im.vector.matrix.android.internal.crypto.verification.AcceptVerifInfoFactory
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoAccept
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoAcceptFactory
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
|
@ -65,7 +65,7 @@ internal data class KeyVerificationAccept(
|
|||
*/
|
||||
@Json(name = "commitment")
|
||||
override var commitment: String? = null
|
||||
) : SendToDeviceObject, VerifInfoAccept {
|
||||
) : SendToDeviceObject, VerificationInfoAccept {
|
||||
|
||||
override fun isValid(): Boolean {
|
||||
if (transactionID.isNullOrBlank()
|
||||
|
@ -82,13 +82,13 @@ internal data class KeyVerificationAccept(
|
|||
|
||||
override fun toSendToDeviceObject() = this
|
||||
|
||||
companion object : AcceptVerifInfoFactory {
|
||||
companion object : VerificationInfoAcceptFactory {
|
||||
override fun create(tid: String,
|
||||
keyAgreementProtocol: String,
|
||||
hash: String,
|
||||
commitment: String,
|
||||
messageAuthenticationCode: String,
|
||||
shortAuthenticationStrings: List<String>): VerifInfoAccept {
|
||||
shortAuthenticationStrings: List<String>): VerificationInfoAccept {
|
||||
return KeyVerificationAccept().apply {
|
||||
this.transactionID = tid
|
||||
this.keyAgreementProtocol = keyAgreementProtocol
|
||||
|
|
|
@ -18,7 +18,7 @@ package im.vector.matrix.android.internal.crypto.model.rest
|
|||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.api.session.crypto.sas.CancelCode
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoCancel
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoCancel
|
||||
|
||||
/**
|
||||
* To device event sent by either party to cancel a key verification.
|
||||
|
@ -40,7 +40,7 @@ internal data class KeyVerificationCancel(
|
|||
* human-readable reason for cancelling. This should only be used if the receiving client does not understand the code given.
|
||||
*/
|
||||
override var reason: String? = null
|
||||
) : SendToDeviceObject, VerifInfoCancel {
|
||||
) : SendToDeviceObject, VerificationInfoCancel {
|
||||
|
||||
companion object {
|
||||
fun create(tid: String, cancelCode: CancelCode): KeyVerificationCancel {
|
||||
|
|
|
@ -17,8 +17,8 @@ package im.vector.matrix.android.internal.crypto.model.rest
|
|||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.internal.crypto.verification.KeyVerifInfoFactory
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoKey
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoKeyFactory
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoKey
|
||||
|
||||
/**
|
||||
* Sent by both devices to send their ephemeral Curve25519 public key to the other device.
|
||||
|
@ -35,9 +35,9 @@ internal data class KeyVerificationKey(
|
|||
*/
|
||||
@Json(name = "key") override val key: String? = null
|
||||
|
||||
) : SendToDeviceObject, VerifInfoKey {
|
||||
) : SendToDeviceObject, VerificationInfoKey {
|
||||
|
||||
companion object : KeyVerifInfoFactory {
|
||||
companion object : VerificationInfoKeyFactory {
|
||||
override fun create(tid: String, pubKey: String): KeyVerificationKey {
|
||||
return KeyVerificationKey(tid, pubKey)
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ package im.vector.matrix.android.internal.crypto.model.rest
|
|||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoMac
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoMacFactory
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoMac
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoMacFactory
|
||||
|
||||
/**
|
||||
* Sent by both devices to send the MAC of their device key to the other device.
|
||||
|
@ -29,7 +29,7 @@ internal data class KeyVerificationMac(
|
|||
@Json(name = "mac") override val mac: Map<String, String>? = null,
|
||||
@Json(name = "key") override val keys: String? = null
|
||||
|
||||
) : SendToDeviceObject, VerifInfoMac {
|
||||
) : SendToDeviceObject, VerificationInfoMac {
|
||||
|
||||
override fun isValid(): Boolean {
|
||||
if (transactionID.isNullOrBlank() || keys.isNullOrBlank() || mac.isNullOrEmpty()) {
|
||||
|
@ -40,8 +40,8 @@ internal data class KeyVerificationMac(
|
|||
|
||||
override fun toSendToDeviceObject(): SendToDeviceObject? = this
|
||||
|
||||
companion object : VerifInfoMacFactory {
|
||||
override fun create(tid: String, mac: Map<String, String>, keys: String): VerifInfoMac {
|
||||
companion object : VerificationInfoMacFactory {
|
||||
override fun create(tid: String, mac: Map<String, String>, keys: String): VerificationInfoMac {
|
||||
return KeyVerificationMac(tid, mac, keys)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import im.vector.matrix.android.internal.crypto.verification.VerificationInfo
|
|||
* Requests a key verification with another user's devices.
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class KeyVerificationRequest(
|
||||
internal data class KeyVerificationRequest(
|
||||
|
||||
@Json(name = "from_device")
|
||||
val fromDevice: String,
|
||||
|
|
|
@ -19,7 +19,7 @@ import com.squareup.moshi.Json
|
|||
import com.squareup.moshi.JsonClass
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasMode
|
||||
import im.vector.matrix.android.internal.crypto.verification.SASVerificationTransaction
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerifInfoStart
|
||||
import im.vector.matrix.android.internal.crypto.verification.VerificationInfoStart
|
||||
import im.vector.matrix.android.internal.util.JsonCanonicalizer
|
||||
import timber.log.Timber
|
||||
|
||||
|
@ -27,7 +27,7 @@ import timber.log.Timber
|
|||
* Sent by Alice to initiate an interactive key verification.
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
class KeyVerificationStart : SendToDeviceObject, VerifInfoStart {
|
||||
class KeyVerificationStart : SendToDeviceObject, VerificationInfoStart {
|
||||
|
||||
override fun toCanonicalJson(): String? {
|
||||
return JsonCanonicalizer.getCanonicalJson(KeyVerificationStart::class.java, this)
|
||||
|
|
|
@ -68,9 +68,8 @@ internal class DefaultRequestVerificationDMTask @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun createRequestEvent(params: RequestVerificationDMTask.Params): Event {
|
||||
val event = localEchoEventFactory.createVerificationRequest(params.roomId, params.from, params.to, params.methods).also {
|
||||
localEchoEventFactory.saveLocalEcho(monarchy, it)
|
||||
}
|
||||
val event = localEchoEventFactory.createVerificationRequest(params.roomId, params.from, params.to, params.methods)
|
||||
.also { localEchoEventFactory.saveLocalEcho(monarchy, it) }
|
||||
if (params.cryptoService.isRoomEncrypted(params.roomId)) {
|
||||
try {
|
||||
return encryptEventTask.execute(EncryptEventTask.Params(
|
||||
|
|
|
@ -66,7 +66,7 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onVerificationStart(startReq: VerifInfoStart) {
|
||||
override fun onVerificationStart(startReq: VerificationInfoStart) {
|
||||
Timber.v("## SAS I: received verification request from state $state")
|
||||
if (state != SasVerificationTxState.None) {
|
||||
Timber.e("## SAS I: received verification request from invalid state")
|
||||
|
@ -126,7 +126,7 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
}
|
||||
}
|
||||
|
||||
private fun doAccept(accept: VerifInfoAccept) {
|
||||
private fun doAccept(accept: VerificationInfoAccept) {
|
||||
this.accepted = accept
|
||||
Timber.v("## SAS incoming accept request id:$transactionId")
|
||||
|
||||
|
@ -144,12 +144,12 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onVerificationAccept(accept: VerifInfoAccept) {
|
||||
override fun onVerificationAccept(accept: VerificationInfoAccept) {
|
||||
Timber.v("## SAS invalid message for incoming request id:$transactionId")
|
||||
cancel(CancelCode.UnexpectedMessage)
|
||||
}
|
||||
|
||||
override fun onKeyVerificationKey(userId: String, vKey: VerifInfoKey) {
|
||||
override fun onKeyVerificationKey(userId: String, vKey: VerificationInfoKey) {
|
||||
Timber.v("## SAS received key for request id:$transactionId")
|
||||
if (state != SasVerificationTxState.SendingAccept && state != SasVerificationTxState.Accepted) {
|
||||
Timber.e("## SAS received key from invalid state $state")
|
||||
|
@ -202,7 +202,7 @@ internal class DefaultIncomingSASVerificationTransaction(
|
|||
state = SasVerificationTxState.ShortCodeReady
|
||||
}
|
||||
|
||||
override fun onKeyVerificationMac(vKey: VerifInfoMac) {
|
||||
override fun onKeyVerificationMac(vKey: VerificationInfoMac) {
|
||||
Timber.v("## SAS I: received mac for request id:$transactionId")
|
||||
// Check for state?
|
||||
if (state != SasVerificationTxState.SendingKey
|
||||
|
|
|
@ -66,7 +66,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onVerificationStart(startReq: VerifInfoStart) {
|
||||
override fun onVerificationStart(startReq: VerificationInfoStart) {
|
||||
Timber.e("## SAS O: onVerificationStart - unexpected id:$transactionId")
|
||||
cancel(CancelCode.UnexpectedMessage)
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
// )
|
||||
// }
|
||||
|
||||
override fun onVerificationAccept(accept: VerifInfoAccept) {
|
||||
override fun onVerificationAccept(accept: VerificationInfoAccept) {
|
||||
Timber.v("## SAS O: onVerificationAccept id:$transactionId")
|
||||
if (state != SasVerificationTxState.Started) {
|
||||
Timber.e("## SAS O: received accept request from invalid state $state")
|
||||
|
@ -159,7 +159,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onKeyVerificationKey(userId: String, vKey: VerifInfoKey) {
|
||||
override fun onKeyVerificationKey(userId: String, vKey: VerificationInfoKey) {
|
||||
Timber.v("## SAS O: onKeyVerificationKey id:$transactionId")
|
||||
if (state != SasVerificationTxState.SendingKey && state != SasVerificationTxState.KeySent) {
|
||||
Timber.e("## received key from invalid state $state")
|
||||
|
@ -201,7 +201,7 @@ internal class DefaultOutgoingSASVerificationRequest(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onKeyVerificationMac(vKey: VerifInfoMac) {
|
||||
override fun onKeyVerificationMac(vKey: VerificationInfoMac) {
|
||||
Timber.v("## SAS O: onKeyVerificationMac id:$transactionId")
|
||||
if (state != SasVerificationTxState.OnKeyReceived
|
||||
&& state != SasVerificationTxState.ShortCodeReady
|
||||
|
|
|
@ -39,7 +39,6 @@ import im.vector.matrix.android.internal.crypto.model.rest.*
|
|||
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
|
||||
import im.vector.matrix.android.internal.crypto.tasks.DefaultRequestVerificationDMTask
|
||||
import im.vector.matrix.android.internal.crypto.tasks.RequestVerificationDMTask
|
||||
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
|
||||
import im.vector.matrix.android.internal.session.SessionScope
|
||||
import im.vector.matrix.android.internal.session.room.send.SendResponse
|
||||
import im.vector.matrix.android.internal.task.TaskConstraints
|
||||
|
@ -56,18 +55,18 @@ import kotlin.collections.HashMap
|
|||
import kotlin.collections.set
|
||||
|
||||
@SessionScope
|
||||
internal class DefaultSasVerificationService @Inject constructor(private val credentials: Credentials,
|
||||
internal class DefaultSasVerificationService @Inject constructor(
|
||||
private val credentials: Credentials,
|
||||
private val cryptoStore: IMXCryptoStore,
|
||||
private val myDeviceInfoHolder: Lazy<MyDeviceInfoHolder>,
|
||||
private val deviceListManager: DeviceListManager,
|
||||
private val setDeviceVerificationAction: SetDeviceVerificationAction,
|
||||
private val sendToDeviceTask: SendToDeviceTask,
|
||||
private val requestVerificationDMTask: DefaultRequestVerificationDMTask,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val sasTransportRoomMessageFactory: SasTransportRoomMessageFactory,
|
||||
private val sasToDeviceTransportFactory: SasToDeviceTransportFactory,
|
||||
private val taskExecutor: TaskExecutor)
|
||||
: VerificationTransaction.Listener, SasVerificationService {
|
||||
private val sasTransportToDeviceFactory: SasTransportToDeviceFactory,
|
||||
private val taskExecutor: TaskExecutor
|
||||
) : VerificationTransaction.Listener, SasVerificationService {
|
||||
|
||||
private val uiHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
|
@ -217,7 +216,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
|||
return
|
||||
}
|
||||
|
||||
handleStart(otherUserId, startReq as VerifInfoStart) {
|
||||
handleStart(otherUserId, startReq as VerificationInfoStart) {
|
||||
it.transport = sasTransportRoomMessageFactory.createTransport(event.roomId
|
||||
?: "", cryptoService)
|
||||
}?.let {
|
||||
|
@ -246,7 +245,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
|||
// startReq.fromDevice ?: event.getSenderKey()!!,
|
||||
// CancelCode.UnknownMethod
|
||||
// )
|
||||
sasToDeviceTransportFactory.createTransport(null).cancelTransaction(
|
||||
sasTransportToDeviceFactory.createTransport(null).cancelTransaction(
|
||||
startReq.transactionID ?: "",
|
||||
otherUserId!!,
|
||||
startReq.fromDevice ?: event.getSenderKey()!!,
|
||||
|
@ -257,9 +256,9 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
|||
}
|
||||
// Download device keys prior to everything
|
||||
handleStart(otherUserId, startReq) {
|
||||
it.transport = sasToDeviceTransportFactory.createTransport(it)
|
||||
it.transport = sasTransportToDeviceFactory.createTransport(it)
|
||||
}?.let {
|
||||
sasToDeviceTransportFactory.createTransport(null).cancelTransaction(
|
||||
sasTransportToDeviceFactory.createTransport(null).cancelTransaction(
|
||||
startReq.transactionID ?: "",
|
||||
otherUserId!!,
|
||||
startReq.fromDevice ?: event.getSenderKey()!!,
|
||||
|
@ -268,7 +267,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun handleStart(otherUserId: String?, startReq: VerifInfoStart, txConfigure: (SASVerificationTransaction) -> Unit): CancelCode? {
|
||||
private suspend fun handleStart(otherUserId: String?, startReq: VerificationInfoStart, txConfigure: (SASVerificationTransaction) -> Unit): CancelCode? {
|
||||
Timber.d("## SAS onStartRequestReceived ${startReq.transactionID!!}")
|
||||
if (checkKeysAreDownloaded(otherUserId!!, startReq) != null) {
|
||||
Timber.v("## SAS onStartRequestReceived $startReq")
|
||||
|
@ -318,7 +317,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
|||
}
|
||||
|
||||
private suspend fun checkKeysAreDownloaded(otherUserId: String,
|
||||
startReq: VerifInfoStart): MXUsersDevicesMap<MXDeviceInfo>? {
|
||||
startReq: VerificationInfoStart): MXUsersDevicesMap<MXDeviceInfo>? {
|
||||
return try {
|
||||
val keys = deviceListManager.downloadKeys(listOf(otherUserId), true)
|
||||
val deviceIds = keys.getUserDeviceIds(otherUserId) ?: return null
|
||||
|
@ -357,7 +356,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
|||
handleOnCancel(otherUserId, cancelReq)
|
||||
}
|
||||
|
||||
private fun handleOnCancel(otherUserId: String, cancelReq: VerifInfoCancel) {
|
||||
private fun handleOnCancel(otherUserId: String, cancelReq: VerificationInfoCancel) {
|
||||
Timber.v("## SAS onCancelReceived otherUser:$otherUserId reason:${cancelReq.reason}")
|
||||
val existing = getExistingTransaction(otherUserId, cancelReq.transactionID!!)
|
||||
if (existing == null) {
|
||||
|
@ -387,7 +386,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
|||
handleAccept(acceptReq, event.senderId!!)
|
||||
}
|
||||
|
||||
private fun handleAccept(acceptReq: VerifInfoAccept, senderId: String) {
|
||||
private fun handleAccept(acceptReq: VerificationInfoAccept, senderId: String) {
|
||||
if (!acceptReq.isValid()) {
|
||||
// ignore
|
||||
Timber.e("## SAS Received invalid accept request")
|
||||
|
@ -433,7 +432,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
|||
handleKeyReceived(event, keyReq)
|
||||
}
|
||||
|
||||
private fun handleKeyReceived(event: Event, keyReq: VerifInfoKey) {
|
||||
private fun handleKeyReceived(event: Event, keyReq: VerificationInfoKey) {
|
||||
Timber.d("## SAS Received Key from ${event.senderId} with info $keyReq")
|
||||
val otherUserId = event.senderId!!
|
||||
val existing = getExistingTransaction(otherUserId, keyReq.transactionID!!)
|
||||
|
@ -474,7 +473,7 @@ internal class DefaultSasVerificationService @Inject constructor(private val cre
|
|||
handleMacReceived(event.senderId, macReq)
|
||||
}
|
||||
|
||||
private fun handleMacReceived(senderId: String, macReq: VerifInfoMac) {
|
||||
private fun handleMacReceived(senderId: String, macReq: VerificationInfoMac) {
|
||||
Timber.v("## SAS Received $macReq")
|
||||
val existing = getExistingTransaction(senderId, macReq.transactionID!!)
|
||||
if (existing == null) {
|
||||
|
|
|
@ -88,13 +88,13 @@ internal abstract class SASVerificationTransaction(
|
|||
|
||||
private var olmSas: OlmSAS? = null
|
||||
|
||||
var startReq: VerifInfoStart? = null
|
||||
var accepted: VerifInfoAccept? = null
|
||||
var startReq: VerificationInfoStart? = null
|
||||
var accepted: VerificationInfoAccept? = null
|
||||
var otherKey: String? = null
|
||||
var shortCodeBytes: ByteArray? = null
|
||||
|
||||
var myMac: VerifInfoMac? = null
|
||||
var theirMac: VerifInfoMac? = null
|
||||
var myMac: VerificationInfoMac? = null
|
||||
var theirMac: VerificationInfoMac? = null
|
||||
|
||||
fun getSAS(): OlmSAS {
|
||||
if (olmSas == null) olmSas = OlmSAS()
|
||||
|
@ -171,23 +171,23 @@ internal abstract class SASVerificationTransaction(
|
|||
|
||||
override fun acceptVerificationEvent(senderId: String, info: VerificationInfo) {
|
||||
when (info) {
|
||||
is VerifInfoStart -> onVerificationStart(info)
|
||||
is VerifInfoAccept -> onVerificationAccept(info)
|
||||
is VerifInfoKey -> onKeyVerificationKey(senderId, info)
|
||||
is VerifInfoMac -> onKeyVerificationMac(info)
|
||||
is VerificationInfoStart -> onVerificationStart(info)
|
||||
is VerificationInfoAccept -> onVerificationAccept(info)
|
||||
is VerificationInfoKey -> onKeyVerificationKey(senderId, info)
|
||||
is VerificationInfoMac -> onKeyVerificationMac(info)
|
||||
else -> {
|
||||
// nop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun onVerificationStart(startReq: VerifInfoStart)
|
||||
abstract fun onVerificationStart(startReq: VerificationInfoStart)
|
||||
|
||||
abstract fun onVerificationAccept(accept: VerifInfoAccept)
|
||||
abstract fun onVerificationAccept(accept: VerificationInfoAccept)
|
||||
|
||||
abstract fun onKeyVerificationKey(userId: String, vKey: VerifInfoKey)
|
||||
abstract fun onKeyVerificationKey(userId: String, vKey: VerificationInfoKey)
|
||||
|
||||
abstract fun onKeyVerificationMac(vKey: VerifInfoMac)
|
||||
abstract fun onKeyVerificationMac(vKey: VerificationInfoMac)
|
||||
|
||||
protected fun verifyMacs() {
|
||||
Timber.v("## SAS verifying macs for id:$transactionId")
|
||||
|
|
|
@ -44,10 +44,10 @@ internal interface SasTransport {
|
|||
hash: String,
|
||||
commitment: String,
|
||||
messageAuthenticationCode: String,
|
||||
shortAuthenticationStrings: List<String>): VerifInfoAccept
|
||||
shortAuthenticationStrings: List<String>): VerificationInfoAccept
|
||||
|
||||
fun createKey(tid: String,
|
||||
pubKey: String): VerifInfoKey
|
||||
pubKey: String): VerificationInfoKey
|
||||
|
||||
fun createMac(tid: String, mac: Map<String, String>, keys: String): VerifInfoMac
|
||||
fun createMac(tid: String, mac: Map<String, String>, keys: String): VerificationInfoMac
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import im.vector.matrix.android.internal.task.configureWith
|
|||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class SasTransportRoomMessage constructor(
|
||||
internal class SasTransportRoomMessage(
|
||||
private val roomId: String,
|
||||
private val cryptoService: CryptoService,
|
||||
// private val tx: SASVerificationTransaction?,
|
||||
|
@ -109,9 +109,9 @@ internal class SasTransportRoomMessage constructor(
|
|||
commitment: String,
|
||||
messageAuthenticationCode: String,
|
||||
shortAuthenticationStrings: List<String>)
|
||||
: VerifInfoAccept = MessageVerificationAcceptContent.create(tid, keyAgreementProtocol, hash, commitment, messageAuthenticationCode, shortAuthenticationStrings)
|
||||
: VerificationInfoAccept = MessageVerificationAcceptContent.create(tid, keyAgreementProtocol, hash, commitment, messageAuthenticationCode, shortAuthenticationStrings)
|
||||
|
||||
override fun createKey(tid: String, pubKey: String): VerifInfoKey = MessageVerificationKeyContent.create(tid, pubKey)
|
||||
override fun createKey(tid: String, pubKey: String): VerificationInfoKey = MessageVerificationKeyContent.create(tid, pubKey)
|
||||
|
||||
override fun createMac(tid: String, mac: Map<String, String>, keys: String) = MessageVerificationMacContent.create(tid, mac, keys)
|
||||
}
|
||||
|
|
|
@ -98,14 +98,14 @@ internal class SasTransportToDevice(
|
|||
commitment: String,
|
||||
messageAuthenticationCode: String,
|
||||
shortAuthenticationStrings: List<String>)
|
||||
: VerifInfoAccept = KeyVerificationAccept.create(tid, keyAgreementProtocol, hash, commitment, messageAuthenticationCode, shortAuthenticationStrings)
|
||||
: VerificationInfoAccept = KeyVerificationAccept.create(tid, keyAgreementProtocol, hash, commitment, messageAuthenticationCode, shortAuthenticationStrings)
|
||||
|
||||
override fun createKey(tid: String, pubKey: String): VerifInfoKey = KeyVerificationKey.create(tid, pubKey)
|
||||
override fun createKey(tid: String, pubKey: String): VerificationInfoKey = KeyVerificationKey.create(tid, pubKey)
|
||||
|
||||
override fun createMac(tid: String, mac: Map<String, String>, keys: String) = KeyVerificationMac.create(tid, mac, keys)
|
||||
}
|
||||
|
||||
internal class SasToDeviceTransportFactory @Inject constructor(
|
||||
internal class SasTransportToDeviceFactory @Inject constructor(
|
||||
private val sendToDeviceTask: SendToDeviceTask,
|
||||
private val taskExecutor: TaskExecutor) {
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package im.vector.matrix.android.internal.crypto.verification
|
|||
import im.vector.matrix.android.api.session.events.model.Content
|
||||
import im.vector.matrix.android.internal.crypto.model.rest.SendToDeviceObject
|
||||
|
||||
interface VerificationInfo {
|
||||
internal interface VerificationInfo {
|
||||
fun toEventContent(): Content? = null
|
||||
fun toSendToDeviceObject(): SendToDeviceObject? = null
|
||||
fun isValid() : Boolean
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package im.vector.matrix.android.internal.crypto.verification
|
||||
|
||||
internal interface VerifInfoAccept : VerificationInfo {
|
||||
internal interface VerificationInfoAccept : VerificationInfo {
|
||||
|
||||
val transactionID: String?
|
||||
|
||||
|
@ -46,12 +46,12 @@ internal interface VerifInfoAccept : VerificationInfo {
|
|||
var commitment: String?
|
||||
}
|
||||
|
||||
internal interface AcceptVerifInfoFactory {
|
||||
internal interface VerificationInfoAcceptFactory {
|
||||
|
||||
fun create(tid: String,
|
||||
keyAgreementProtocol: String,
|
||||
hash: String,
|
||||
commitment: String,
|
||||
messageAuthenticationCode: String,
|
||||
shortAuthenticationStrings: List<String>): VerifInfoAccept
|
||||
shortAuthenticationStrings: List<String>): VerificationInfoAccept
|
||||
}
|
|
@ -15,11 +15,11 @@
|
|||
*/
|
||||
package im.vector.matrix.android.internal.crypto.verification
|
||||
|
||||
interface VerifInfoCancel : VerificationInfo {
|
||||
internal interface VerificationInfoCancel : VerificationInfo {
|
||||
|
||||
val transactionID: String?
|
||||
/**
|
||||
* machine-readable reason for cancelling, see #CancelCode
|
||||
* machine-readable reason for cancelling, see [CancelCode]
|
||||
*/
|
||||
val code: String?
|
||||
|
|
@ -18,7 +18,7 @@ package im.vector.matrix.android.internal.crypto.verification
|
|||
/**
|
||||
* Sent by both devices to send their ephemeral Curve25519 public key to the other device.
|
||||
*/
|
||||
internal interface VerifInfoKey : VerificationInfo {
|
||||
internal interface VerificationInfoKey : VerificationInfo {
|
||||
|
||||
val transactionID: String?
|
||||
/**
|
||||
|
@ -27,6 +27,6 @@ internal interface VerifInfoKey : VerificationInfo {
|
|||
val key: String?
|
||||
}
|
||||
|
||||
internal interface KeyVerifInfoFactory {
|
||||
fun create(tid: String, pubKey: String): VerifInfoKey
|
||||
internal interface VerificationInfoKeyFactory {
|
||||
fun create(tid: String, pubKey: String): VerificationInfoKey
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package im.vector.matrix.android.internal.crypto.verification
|
||||
|
||||
internal interface VerifInfoMac : VerificationInfo {
|
||||
internal interface VerificationInfoMac : VerificationInfo {
|
||||
|
||||
val transactionID: String?
|
||||
|
||||
|
@ -33,6 +33,6 @@ internal interface VerifInfoMac : VerificationInfo {
|
|||
val keys: String?
|
||||
}
|
||||
|
||||
internal interface VerifInfoMacFactory {
|
||||
fun create(tid: String, mac: Map<String, String>, keys: String) : VerifInfoMac
|
||||
internal interface VerificationInfoMacFactory {
|
||||
fun create(tid: String, mac: Map<String, String>, keys: String) : VerificationInfoMac
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package im.vector.matrix.android.internal.crypto.verification
|
||||
|
||||
interface VerifInfoStart : VerificationInfo {
|
||||
internal interface VerificationInfoStart : VerificationInfo {
|
||||
|
||||
val method: String?
|
||||
val fromDevice: String?
|
|
@ -37,12 +37,13 @@ import timber.log.Timber
|
|||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class VerificationMessageLiveObserver @Inject constructor(@SessionDatabase realmConfiguration: RealmConfiguration,
|
||||
internal class VerificationMessageLiveObserver @Inject constructor(
|
||||
@SessionDatabase realmConfiguration: RealmConfiguration,
|
||||
@UserId private val userId: String,
|
||||
private val cryptoService: CryptoService,
|
||||
private val sasVerificationService: DefaultSasVerificationService,
|
||||
private val taskExecutor: TaskExecutor) :
|
||||
RealmLiveEntityObserver<EventEntity>(realmConfiguration) {
|
||||
private val taskExecutor: TaskExecutor
|
||||
) : RealmLiveEntityObserver<EventEntity>(realmConfiguration) {
|
||||
|
||||
override val query = Monarchy.Query<EventEntity> {
|
||||
EventEntity.types(it, listOf(
|
||||
|
|
|
@ -167,7 +167,7 @@ internal abstract class SessionModule {
|
|||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindVerificationEventObserver(verificationMessageLiveObserver: VerificationMessageLiveObserver): LiveEntityObserver
|
||||
abstract fun bindVerificationMessageLiveObserver(verificationMessageLiveObserver: VerificationMessageLiveObserver): LiveEntityObserver
|
||||
|
||||
@Binds
|
||||
abstract fun bindInitialSyncProgressService(initialSyncProgressService: DefaultInitialSyncProgressService): InitialSyncProgressService
|
||||
|
|
|
@ -157,13 +157,12 @@ internal class DefaultSendService @AssistedInject constructor(@Assisted private
|
|||
|
||||
override fun deleteFailedEcho(localEcho: TimelineEvent) {
|
||||
monarchy.writeAsync { realm ->
|
||||
TimelineEventEntity.where(realm, roomId = roomId, eventId = localEcho.root.eventId
|
||||
?: "").findFirst()?.let {
|
||||
it.deleteFromRealm()
|
||||
}
|
||||
EventEntity.where(realm, eventId = localEcho.root.eventId ?: "").findFirst()?.let {
|
||||
it.deleteFromRealm()
|
||||
}
|
||||
TimelineEventEntity.where(realm, roomId = roomId, eventId = localEcho.root.eventId ?: "")
|
||||
.findFirst()
|
||||
?.let { it.deleteFromRealm() }
|
||||
EventEntity.where(realm, eventId = localEcho.root.eventId ?: "")
|
||||
.findFirst()
|
||||
?.let { it.deleteFromRealm() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
fun createVerificationRequest(roomId: String, fromDevice: String, to: String, methods: List<String>): Event {
|
||||
fun createVerificationRequest(roomId: String, fromDevice: String, toUserId: String, methods: List<String>): Event {
|
||||
val localID = LocalEcho.createLocalEchoId()
|
||||
return Event(
|
||||
roomId = roomId,
|
||||
|
@ -297,7 +297,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||
content = MessageVerificationRequestContent(
|
||||
body = stringProvider.getString(R.string.key_verification_request_fallback_message, userId),
|
||||
fromDevice = fromDevice,
|
||||
to = to,
|
||||
toUserId = toUserId,
|
||||
methods = methods
|
||||
).toContent(),
|
||||
unsignedData = UnsignedData(age = null, transactionId = localID)
|
||||
|
|
|
@ -25,7 +25,7 @@ import javax.inject.Inject
|
|||
|
||||
internal class LocalEchoUpdater @Inject constructor(private val monarchy: Monarchy) {
|
||||
|
||||
suspend fun updateSendState(eventId: String, sendState: SendState) {
|
||||
fun updateSendState(eventId: String, sendState: SendState) {
|
||||
Timber.v("Update local state of $eventId to ${sendState.name}")
|
||||
monarchy.writeAsync { realm ->
|
||||
val sendingEventEntity = EventEntity.where(realm, eventId).findFirst()
|
||||
|
|
|
@ -40,7 +40,7 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
|
|||
CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token),
|
||||
SHRUG("/shrug", "<message>", R.string.command_description_shrug),
|
||||
// TODO temporary command
|
||||
VERIFY_USER("/verify", "<userID>", R.string.command_description_spoiler);
|
||||
VERIFY_USER("/verify", "<user-id>", R.string.command_description_verify);
|
||||
|
||||
val length
|
||||
get() = command.length + 1
|
||||
|
|
|
@ -245,7 +245,7 @@ object CommandParser {
|
|||
ParsedCommand.SendSpoiler(message)
|
||||
}
|
||||
Command.SHRUG.command -> {
|
||||
val message = textMessage.subSequence(Command.SHRUG.command.length, textMessage.length).trim()
|
||||
val message = textMessage.substring(Command.SHRUG.command.length).trim()
|
||||
|
||||
ParsedCommand.SendShrug(message)
|
||||
}
|
||||
|
|
|
@ -377,15 +377,13 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
|||
popDraft()
|
||||
}
|
||||
is ParsedCommand.SendShrug -> {
|
||||
val sequence: CharSequence = buildString {
|
||||
val sequence = buildString {
|
||||
append("¯\\_(ツ)_/¯")
|
||||
.apply {
|
||||
if (slashCommandResult.message.isNotEmpty()) {
|
||||
append(" ")
|
||||
append(slashCommandResult.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
room.sendTextMessage(sequence)
|
||||
_sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled())
|
||||
popDraft()
|
||||
|
|
|
@ -20,7 +20,9 @@ import im.vector.riotx.R
|
|||
import im.vector.riotx.core.preference.VectorSwitchPreference
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsLabsFragment @Inject constructor(val vectorPreferences: VectorPreferences) : VectorSettingsBaseFragment() {
|
||||
class VectorSettingsLabsFragment @Inject constructor(
|
||||
private val vectorPreferences: VectorPreferences
|
||||
) : VectorSettingsBaseFragment() {
|
||||
|
||||
override var titleRes = R.string.room_settings_labs_pref_title
|
||||
override val preferenceXmlRes = R.xml.vector_settings_labs
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
android:title="@string/labs_swipe_to_reply_in_timeline" />
|
||||
|
||||
<im.vector.riotx.core.preference.VectorSwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:defaultValue="@bool/debug_mode"
|
||||
android:key="SETTINGS_LABS_ALLOW_EXTENDED_LOGS"
|
||||
android:summary="@string/labs_allow_extended_logging_summary"
|
||||
android:title="@string/labs_allow_extended_logging" />
|
||||
|
|
Loading…
Reference in a new issue