diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationAcceptContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationAcceptContent.kt index 66914374df..bda4b9f0ac 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationAcceptContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationAcceptContent.kt @@ -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.VerificationInfoAcceptFactory -import im.vector.matrix.android.internal.crypto.verification.VerificationInfoAccept +import im.vector.matrix.android.internal.crypto.verification.AcceptVerifInfoFactory +import im.vector.matrix.android.internal.crypto.verification.VerifInfoAccept import timber.log.Timber @JsonClass(generateAdapter = true) @@ -32,7 +32,7 @@ internal data class MessageVerificationAcceptContent( @Json(name = "short_authentication_string") override val shortAuthenticationStrings: List?, @Json(name = "m.relates_to") val relatesTo: RelationDefaultContent?, @Json(name = "commitment") override var commitment: String? = null -) : VerificationInfoAccept { +) : VerifInfoAccept { override val transactionID: String? get() = relatesTo?.eventId @@ -52,14 +52,14 @@ internal data class MessageVerificationAcceptContent( override fun toEventContent() = this.toContent() - companion object : VerificationInfoAcceptFactory { + companion object : AcceptVerifInfoFactory { override fun create(tid: String, keyAgreementProtocol: String, hash: String, commitment: String, messageAuthenticationCode: String, - shortAuthenticationStrings: List): VerificationInfoAccept { + shortAuthenticationStrings: List): VerifInfoAccept { return MessageVerificationAcceptContent( hash, keyAgreementProtocol, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationCancelContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationCancelContent.kt index 2070845f46..08fc3cbdbb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationCancelContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationCancelContent.kt @@ -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.VerificationInfoCancel +import im.vector.matrix.android.internal.crypto.verification.VerifInfoCancel @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? -) : VerificationInfoCancel { +) : VerifInfoCancel { override val transactionID: String? get() = relatesTo?.eventId diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationKeyContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationKeyContent.kt index 2dacb19871..0b93e3299a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationKeyContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationKeyContent.kt @@ -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.VerificationInfoKey -import im.vector.matrix.android.internal.crypto.verification.VerificationInfoKeyFactory +import im.vector.matrix.android.internal.crypto.verification.VerifInfoKey +import im.vector.matrix.android.internal.crypto.verification.KeyVerifInfoFactory 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? -) : VerificationInfoKey { +) : VerifInfoKey { override val transactionID: String? get() = relatesTo?.eventId @@ -46,9 +46,9 @@ internal data class MessageVerificationKeyContent( override fun toEventContent() = this.toContent() - companion object : VerificationInfoKeyFactory { + companion object : KeyVerifInfoFactory { - override fun create(tid: String, pubKey: String): VerificationInfoKey { + override fun create(tid: String, pubKey: String): VerifInfoKey { return MessageVerificationKeyContent( pubKey, RelationDefaultContent( diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationRequestContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationRequestContent.kt index 1f6c8158fe..afefa39847 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationRequestContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageVerificationRequestContent.kt @@ -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) -data class MessageVerificationRequestContent( +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, - @Json(name = "to") val toUserId: String, + @Json(name = "to") val to: String, // @Json(name = "timestamp") val timestamp: Int, @Json(name = "format") val format: String? = null, @Json(name = "formatted_body") val formattedBody: String? = null, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationAccept.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationAccept.kt index ef30986124..45de68cf77 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationAccept.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/rest/KeyVerificationAccept.kt @@ -88,7 +88,7 @@ internal data class KeyVerificationAccept( hash: String, commitment: String, messageAuthenticationCode: String, - shortAuthenticationStrings: List): VerificationInfoAccept { + shortAuthenticationStrings: List): VerifInfoAccept { return KeyVerificationAccept().apply { this.transactionID = tid this.keyAgreementProtocol = keyAgreementProtocol diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationMessageLiveObserver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationMessageLiveObserver.kt index 9a9cf9a420..2886d78d8c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationMessageLiveObserver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/VerificationMessageLiveObserver.kt @@ -37,13 +37,12 @@ import timber.log.Timber import java.util.* import javax.inject.Inject -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(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(realmConfiguration) { override val query = Monarchy.Query { EventEntity.types(it, listOf( @@ -70,23 +69,12 @@ internal class VerificationMessageLiveObserver @Inject constructor( } .toList() - // TODO use age also, ignore initial sync or back pagination? - val now = System.currentTimeMillis() - val tooInThePast = now - (10 * 60 * 1000 * 1000) - val tooInTheFuture = System.currentTimeMillis() + (5 * 60 * 1000 * 1000) - events.forEach { event -> - Timber.d("## SAS Verification live observer: received msgId: ${event.eventId} msgtype: ${event.type} from ${event.senderId}") + Timber.d("## SAS Verification live observer: received msgId: ${event.eventId} msgtype: ${event.type} from ${event.senderId}") Timber.v("## SAS Verification live observer: received msgId: $event") - // If the request is in the future by more than 5 minutes or more than 10 minutes in the past, - // the message should be ignored by the receiver. - val eventOrigin = event.originServerTs ?: -1 - if (eventOrigin < tooInThePast || eventOrigin > tooInTheFuture) { - Timber.d("## SAS Verification live observer: msgId: ${event.eventId} is out of time ^^") - return@forEach - } // decrypt if needed? + if (event.isEncrypted() && event.mxDecryptionResult == null) { // TODO use a global event decryptor? attache to session and that listen to new sessionId? // for now decrypt sync @@ -114,6 +102,8 @@ internal class VerificationMessageLiveObserver @Inject constructor( } EventType.MESSAGE -> { if (MessageType.MSGTYPE_VERIFICATION_REQUEST == event.getClearContent().toModel()?.type) { + // TODO If the request is in the future by more than 5 minutes or more than 10 minutes in the past, + // the message should be ignored by the receiver. sasVerificationService.onRoomRequestReceived(event) } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt index 45172fb213..a225146d83 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt @@ -286,7 +286,7 @@ internal class LocalEchoEventFactory @Inject constructor( ) } - fun createVerificationRequest(roomId: String, fromDevice: String, toUserId: String, methods: List): Event { + fun createVerificationRequest(roomId: String, fromDevice: String, to: String, methods: List): 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, - toUserId = toUserId, + to = to, methods = methods ).toContent(), unsignedData = UnsignedData(age = null, transactionId = localID) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/TimelineItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/TimelineItemFactory.kt index a705576234..4c36b55fef 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/TimelineItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/TimelineItemFactory.kt @@ -72,7 +72,7 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me EventType.KEY_VERIFICATION_MAC -> { // These events are filtered from timeline in normal case // Only visible in developer mode - defaultItemFactory.create(event, highlight, callback) + defaultItemFactory.create(event, highlight, readMarkerVisible, callback) } // Unhandled event types (yet)