Cancel transaction if failed to decrypt other part events

This commit is contained in:
Valere 2020-02-28 18:23:49 +01:00
parent d5137897c1
commit 3639007985
3 changed files with 27 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package im.vector.matrix.android.api.session.crypto.verification
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.LocalEcho
/**
@ -136,4 +137,6 @@ interface VerificationService {
return age in tooInThePast..tooInTheFuture
}
}
fun onPotentiallyInterestingEventRoomFailToDecrypt(event: Event)
}

View File

@ -85,6 +85,7 @@ internal class DefaultRoomVerificationUpdateTask @Inject constructor(
)
} catch (e: MXCryptoError) {
Timber.e("## SAS Failed to decrypt event: ${event.eventId}")
params.verificationService.onPotentiallyInterestingEventRoomFailToDecrypt(event)
}
}
Timber.v("## SAS Verification live observer: received msgId: ${event.eventId} type: ${event.getClearType()}")

View File

@ -35,6 +35,7 @@ import im.vector.matrix.android.api.session.crypto.verification.safeValueOf
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.LocalEcho
import im.vector.matrix.android.api.session.events.model.RelationType
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.message.MessageContent
import im.vector.matrix.android.api.session.room.model.message.MessageRelationContent
@ -54,6 +55,7 @@ import im.vector.matrix.android.internal.crypto.actions.SetDeviceVerificationAct
import im.vector.matrix.android.internal.crypto.crosssigning.DeviceTrustLevel
import im.vector.matrix.android.internal.crypto.model.CryptoDeviceInfo
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationAccept
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationCancel
import im.vector.matrix.android.internal.crypto.model.rest.KeyVerificationKey
@ -354,6 +356,27 @@ internal class DefaultVerificationService @Inject constructor(
*/
}
override fun onPotentiallyInterestingEventRoomFailToDecrypt(event: Event) {
// When Should/Can we cancel??
val relationContent = event.content.toModel<EncryptedEventContent>()?.relatesTo
if (relationContent?.type == RelationType.REFERENCE) {
val relatedId = relationContent.eventId ?: return
// at least if request was sent by me, I can safely cancel without interfering
pendingRequests[event.senderId]?.firstOrNull {
it.transactionId == relatedId && !it.isIncoming
}?.let { pr ->
verificationTransportRoomMessageFactory.createTransport(event.roomId ?: "", null)
.cancelTransaction(
relatedId,
event.senderId ?: "",
event.getSenderKey() ?: "",
CancelCode.InvalidMessage
)
updatePendingRequest(pr.copy(cancelConclusion = CancelCode.InvalidMessage))
}
}
}
private suspend fun onRoomStartRequestReceived(event: Event) {
val startReq = event.getClearContent().toModel<MessageVerificationStartContent>()
?.copy(