Fix / Use transport to start verification

This commit is contained in:
Valere 2019-12-04 18:22:01 +01:00
parent d370f6d7c8
commit 7fc57bdf9b
8 changed files with 92 additions and 16 deletions

View file

@ -52,6 +52,13 @@ interface SasVerificationService {
fun requestKeyVerificationInDMs(userId: String, roomId: String, callback: MatrixCallback<String>?) fun requestKeyVerificationInDMs(userId: String, roomId: String, callback: MatrixCallback<String>?)
fun beginKeyVerificationInDMs(method: String,
transactionId: String,
roomId: String,
otherUserId: String,
otherDeviceId: String,
callback: MatrixCallback<String>?): String?
// fun transactionUpdated(tx: SasVerificationTransaction) // fun transactionUpdated(tx: SasVerificationTransaction)
interface SasVerificationListener { interface SasVerificationListener {

View file

@ -21,7 +21,7 @@ import im.vector.matrix.android.api.session.events.model.Content
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
internal data class MessageVerificationRequestContent( data class MessageVerificationRequestContent(
@Json(name = "msgtype") override val type: String = MessageType.MSGTYPE_VERIFICATION_REQUEST, @Json(name = "msgtype") override val type: String = MessageType.MSGTYPE_VERIFICATION_REQUEST,
@Json(name = "body") override val body: String, @Json(name = "body") override val body: String,
@Json(name = "from_device") val fromDevice: String, @Json(name = "from_device") val fromDevice: String,

View file

@ -78,14 +78,15 @@ internal class DefaultOutgoingSASVerificationRequest(
throw IllegalStateException("Interactive Key verification already started") throw IllegalStateException("Interactive Key verification already started")
} }
val startMessage = KeyVerificationStart() val startMessage = transport.createStart(
startMessage.fromDevice = credentials.deviceId credentials.deviceId ?: "",
startMessage.method = KeyVerificationStart.VERIF_METHOD_SAS KeyVerificationStart.VERIF_METHOD_SAS,
startMessage.transactionID = transactionId transactionId,
startMessage.keyAgreementProtocols = KNOWN_AGREEMENT_PROTOCOLS KNOWN_AGREEMENT_PROTOCOLS,
startMessage.hashes = KNOWN_HASHES KNOWN_HASHES,
startMessage.messageAuthenticationCodes = KNOWN_MACS KNOWN_MACS,
startMessage.shortAuthenticationStrings = KNOWN_SHORT_CODES KNOWN_SHORT_CODES
)
startReq = startMessage startReq = startMessage
state = SasVerificationTxState.SendingStart state = SasVerificationTxState.SendingStart

View file

@ -348,7 +348,7 @@ internal class DefaultSasVerificationService @Inject constructor(
if (!cancelReq.isValid()) { if (!cancelReq.isValid()) {
// ignore // ignore
Timber.e("## SAS Received invalid accept request") Timber.e("## SAS Received invalid cancel request")
return return
} }
val otherUserId = event.senderId!! val otherUserId = event.senderId!!
@ -477,7 +477,7 @@ internal class DefaultSasVerificationService @Inject constructor(
Timber.v("## SAS Received $macReq") Timber.v("## SAS Received $macReq")
val existing = getExistingTransaction(senderId, macReq.transactionID!!) val existing = getExistingTransaction(senderId, macReq.transactionID!!)
if (existing == null) { if (existing == null) {
Timber.e("## SAS Received invalid accept request") Timber.e("## SAS Received invalid Mac request")
return return
} }
if (existing is SASVerificationTransaction) { if (existing is SASVerificationTransaction) {
@ -532,6 +532,7 @@ internal class DefaultSasVerificationService @Inject constructor(
txID, txID,
userId, userId,
deviceID) deviceID)
tx.transport = sasTransportToDeviceFactory.createTransport(tx)
addTransaction(tx) addTransaction(tx)
tx.start() tx.start()
@ -565,6 +566,28 @@ internal class DefaultSasVerificationService @Inject constructor(
}.executeBy(taskExecutor) }.executeBy(taskExecutor)
} }
override fun beginKeyVerificationInDMs(method: String, transactionId: String, roomId: String,
otherUserId: String, otherDeviceId: String,
callback: MatrixCallback<String>?): String? {
if (KeyVerificationStart.VERIF_METHOD_SAS == method) {
val tx = DefaultOutgoingSASVerificationRequest(
setDeviceVerificationAction,
credentials,
cryptoStore,
myDeviceInfoHolder.get().myDevice.fingerprint()!!,
transactionId,
otherUserId,
otherDeviceId)
tx.transport = sasTransportRoomMessageFactory.createTransport(roomId, cryptoService)
addTransaction(tx)
tx.start()
return transactionId
} else {
throw IllegalArgumentException("Unknown verification method")
}
}
/** /**
* This string must be unique for the pair of users performing verification for the duration that the transaction is valid * This string must be unique for the pair of users performing verification for the duration that the transaction is valid
*/ */

View file

@ -47,7 +47,15 @@ internal interface SasTransport {
shortAuthenticationStrings: List<String>): VerificationInfoAccept shortAuthenticationStrings: List<String>): VerificationInfoAccept
fun createKey(tid: String, fun createKey(tid: String,
pubKey: String): VerificationInfoKey pubKey: String): VerificationInfoKey
fun createStart(fromDevice: String,
method: String,
transactionID: String,
keyAgreementProtocols: List<String>,
hashes: List<String>,
messageAuthenticationCodes: List<String>,
shortAuthenticationStrings: List<String>) : VerificationInfoStart
fun createMac(tid: String, mac: Map<String, String>, keys: String): VerificationInfoMac fun createMac(tid: String, mac: Map<String, String>, keys: String): VerificationInfoMac
} }

View file

@ -125,6 +125,27 @@ internal class SasTransportRoomMessage(
override fun createKey(tid: String, pubKey: String): VerificationInfoKey = 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) override fun createMac(tid: String, mac: Map<String, String>, keys: String) = MessageVerificationMacContent.create(tid, mac, keys)
override fun createStart(fromDevice: String,
method: String,
transactionID: String,
keyAgreementProtocols: List<String>,
hashes: List<String>,
messageAuthenticationCodes: List<String>,
shortAuthenticationStrings: List<String>): VerificationInfoStart {
return MessageVerificationStartContent(
fromDevice,
hashes,
keyAgreementProtocols,
messageAuthenticationCodes,
shortAuthenticationStrings,
method,
RelationDefaultContent(
type = RelationType.REFERENCE,
eventId = transactionID
)
)
}
} }
internal class SasTransportRoomMessageFactory @Inject constructor( internal class SasTransportRoomMessageFactory @Inject constructor(

View file

@ -20,10 +20,7 @@ import im.vector.matrix.android.api.session.crypto.sas.CancelCode
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationAccept import im.vector.matrix.android.internal.crypto.model.rest.*
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationCancel
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationKey
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationMac
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.configureWith import im.vector.matrix.android.internal.task.configureWith
@ -113,6 +110,24 @@ internal class SasTransportToDevice(
override fun createKey(tid: String, pubKey: String): VerificationInfoKey = 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) override fun createMac(tid: String, mac: Map<String, String>, keys: String) = KeyVerificationMac.create(tid, mac, keys)
override fun createStart(fromDevice: String,
method: String,
transactionID: String,
keyAgreementProtocols: List<String>,
hashes: List<String>,
messageAuthenticationCodes: List<String>,
shortAuthenticationStrings: List<String>): 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
}
}
} }
internal class SasTransportToDeviceFactory @Inject constructor( internal class SasTransportToDeviceFactory @Inject constructor(

View file

@ -46,6 +46,7 @@ object MoshiProvider {
.registerSubtype(MessageVideoContent::class.java, MessageType.MSGTYPE_VIDEO) .registerSubtype(MessageVideoContent::class.java, MessageType.MSGTYPE_VIDEO)
.registerSubtype(MessageLocationContent::class.java, MessageType.MSGTYPE_LOCATION) .registerSubtype(MessageLocationContent::class.java, MessageType.MSGTYPE_LOCATION)
.registerSubtype(MessageFileContent::class.java, MessageType.MSGTYPE_FILE) .registerSubtype(MessageFileContent::class.java, MessageType.MSGTYPE_FILE)
.registerSubtype(MessageVerificationRequestContent::class.java, MessageType.MSGTYPE_VERIFICATION_REQUEST)
) )
.add(SerializeNulls.JSON_ADAPTER_FACTORY) .add(SerializeNulls.JSON_ADAPTER_FACTORY)
.build() .build()