mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-17 11:48:51 +03:00
Support verification using room transport
This commit is contained in:
parent
be723256d3
commit
553604423e
8 changed files with 28 additions and 38 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.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<String>?,
|
||||
@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<String>): VerificationInfoAccept {
|
||||
shortAuthenticationStrings: List<String>): VerifInfoAccept {
|
||||
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.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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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<String>,
|
||||
@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,
|
||||
|
|
|
@ -88,7 +88,7 @@ internal data class KeyVerificationAccept(
|
|||
hash: String,
|
||||
commitment: String,
|
||||
messageAuthenticationCode: String,
|
||||
shortAuthenticationStrings: List<String>): VerificationInfoAccept {
|
||||
shortAuthenticationStrings: List<String>): VerifInfoAccept {
|
||||
return KeyVerificationAccept().apply {
|
||||
this.transactionID = tid
|
||||
this.keyAgreementProtocol = keyAgreementProtocol
|
||||
|
|
|
@ -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<EventEntity>(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) {
|
||||
|
||||
override val query = Monarchy.Query<EventEntity> {
|
||||
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<MessageContent>()?.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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -286,7 +286,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
fun createVerificationRequest(roomId: String, fromDevice: String, toUserId: String, methods: List<String>): Event {
|
||||
fun createVerificationRequest(roomId: String, fromDevice: String, to: 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,
|
||||
toUserId = toUserId,
|
||||
to = to,
|
||||
methods = methods
|
||||
).toContent(),
|
||||
unsignedData = UnsignedData(age = null, transactionId = localID)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue