Update Scan confirm flow

This commit is contained in:
Valere 2020-04-09 16:29:52 +02:00
parent 3ba619d45c
commit 5081361c2d
13 changed files with 236 additions and 47 deletions

View File

@ -43,6 +43,7 @@ sealed class VerificationTxState {
// Will be used to ask the user if the other user has correctly scanned
object QrScannedByOther : VerificationQrTxState()
object WaitingOtherReciprocateConfirm : VerificationQrTxState()
// Terminal states
abstract class TerminalTxState : VerificationTxState()

View File

@ -646,9 +646,7 @@ internal class DefaultVerificationService @Inject constructor(
))
}
if (existingTransaction is SASDefaultVerificationTransaction) {
existingTransaction.state = VerificationTxState.Cancelled(safeValueOf(cancelReq.code), false)
}
existingTransaction?.state = VerificationTxState.Cancelled(safeValueOf(cancelReq.code), false)
}
private fun onRoomAcceptReceived(event: Event) {
@ -792,26 +790,53 @@ internal class DefaultVerificationService @Inject constructor(
private fun onDoneReceived(event: Event) {
Timber.v("## onDoneReceived")
val doneReq = event.getClearContent().toModel<KeyVerificationDone>()?.asValidObject()
if (doneReq == null || event.senderId != userId) {
if (doneReq == null || event.senderId == null) {
// ignore
Timber.e("## SAS Received invalid done request")
return
}
// We only send gossiping request when the other sent us a done
// We can ask without checking too much thinks (like trust), because we will check validity of secret on reception
getExistingTransaction(userId, doneReq.transactionId)
?: getOldTransaction(userId, doneReq.transactionId)
?.let { vt ->
val otherDeviceId = vt.otherDeviceId
if (!crossSigningService.canCrossSign()) {
outgoingGossipingRequestManager.sendSecretShareRequest(SELF_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId
?: "*")))
outgoingGossipingRequestManager.sendSecretShareRequest(USER_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId
handleDoneReceived(event.senderId, doneReq)
if (event.senderId == userId) {
// We only send gossiping request when the other sent us a done
// We can ask without checking too much thinks (like trust), because we will check validity of secret on reception
getExistingTransaction(userId, doneReq.transactionId)
?: getOldTransaction(userId, doneReq.transactionId)
?.let { vt ->
val otherDeviceId = vt.otherDeviceId
if (!crossSigningService.canCrossSign()) {
outgoingGossipingRequestManager.sendSecretShareRequest(SELF_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId
?: "*")))
outgoingGossipingRequestManager.sendSecretShareRequest(USER_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId
?: "*")))
}
outgoingGossipingRequestManager.sendSecretShareRequest(KEYBACKUP_SECRET_SSSS_NAME, mapOf(userId to listOf(otherDeviceId
?: "*")))
}
outgoingGossipingRequestManager.sendSecretShareRequest(KEYBACKUP_SECRET_SSSS_NAME, mapOf(userId to listOf(otherDeviceId ?: "*")))
}
}
}
private fun handleDoneReceived(senderId: String, doneReq: ValidVerificationDone) {
Timber.v("## SAS Done receieved $doneReq")
val existing = getExistingTransaction(senderId, doneReq.transactionId)
if (existing == null) {
Timber.e("## SAS Received invalid Done request")
return
}
if (existing is DefaultQrCodeVerificationTransaction) {
existing.onDoneReceived()
} else {
// SAS do not care for now?
}
// Now transactions are udated, let's also update Requests
val existingRequest = getExistingVerificationRequest(senderId)?.find { it.transactionId == doneReq.transactionId }
if (existingRequest == null) {
Timber.e("## SAS Received Done for unknown request txId:${doneReq.transactionId}")
return
}
updatePendingRequest(existingRequest.copy(isSuccessful = true))
}
private fun onRoomDoneReceived(event: Event) {
@ -993,14 +1018,14 @@ internal class DefaultVerificationService @Inject constructor(
)
}
private fun handleDoneReceived(senderId: String, doneInfo: ValidVerificationDone) {
val existingRequest = getExistingVerificationRequest(senderId)?.find { it.transactionId == doneInfo.transactionId }
if (existingRequest == null) {
Timber.e("## SAS Received Done for unknown request txId:${doneInfo.transactionId}")
return
}
updatePendingRequest(existingRequest.copy(isSuccessful = true))
}
// private fun handleDoneReceived(senderId: String, doneInfo: ValidVerificationDone) {
// val existingRequest = getExistingVerificationRequest(senderId)?.find { it.transactionId == doneInfo.transactionId }
// if (existingRequest == null) {
// Timber.e("## SAS Received Done for unknown request txId:${doneInfo.transactionId}")
// return
// }
// updatePendingRequest(existingRequest.copy(isSuccessful = true))
// }
// TODO All this methods should be delegated to a TransactionStore
override fun getExistingTransaction(otherUserId: String, tid: String): VerificationTransaction? {

View File

@ -57,7 +57,7 @@ internal abstract class DefaultVerificationTransaction(
protected fun trust(canTrustOtherUserMasterKey: Boolean,
toVerifyDeviceIds: List<String>,
eventuallyMarkMyMasterKeyAsTrusted: Boolean) {
eventuallyMarkMyMasterKeyAsTrusted: Boolean, autoDone : Boolean = true) {
Timber.d("## Verification: trust ($otherUserId,$otherDeviceId) , verifiedDevices:$toVerifyDeviceIds")
Timber.d("## Verification: trust Mark myMSK trusted $eventuallyMarkMyMasterKeyAsTrusted")
@ -97,14 +97,9 @@ internal abstract class DefaultVerificationTransaction(
})
}
state = VerificationTxState.Verified
transport.done(transactionId) {
// if (otherUserId == userId && !crossSigningService.canCrossSign()) {
// outgoingGossipingRequestManager.sendSecretShareRequest(SELF_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId ?: "*")))
// outgoingGossipingRequestManager.sendSecretShareRequest(USER_SIGNING_KEY_SSSS_NAME, mapOf(userId to listOf(otherDeviceId ?: "*")))
// outgoingGossipingRequestManager.sendSecretShareRequest(KEYBACKUP_SECRET_SSSS_NAME, mapOf(userId to listOf(otherDeviceId ?: "*")))
// }
if (autoDone) {
state = VerificationTxState.Verified
transport.done(transactionId) {}
}
}

View File

@ -15,12 +15,12 @@
*/
package im.vector.matrix.android.internal.crypto.verification
internal interface VerificationInfoDone : VerificationInfo<ValidVerificationInfoDone> {
import im.vector.matrix.android.api.session.room.model.message.ValidVerificationDone
override fun asValidObject(): ValidVerificationInfoDone? {
internal interface VerificationInfoDone : VerificationInfo<ValidVerificationDone> {
override fun asValidObject(): ValidVerificationDone? {
val validTransactionId = transactionId?.takeIf { it.isNotEmpty() } ?: return null
return ValidVerificationInfoDone(validTransactionId)
return ValidVerificationDone(validTransactionId)
}
}
internal data class ValidVerificationInfoDone(val transactionId: String)

View File

@ -187,9 +187,12 @@ internal class DefaultQrCodeVerificationTransaction(
// qrCodeData.sharedSecret will be used to send the start request
start(otherQrCodeData.sharedSecret)
trust(canTrustOtherUserMasterKey,
toVerifyDeviceIds.distinct(),
eventuallyMarkMyMasterKeyAsTrusted = true)
trust(
canTrustOtherUserMasterKey = canTrustOtherUserMasterKey,
toVerifyDeviceIds = toVerifyDeviceIds.distinct(),
eventuallyMarkMyMasterKeyAsTrusted = true,
autoDone = false
)
}
private fun start(remoteSecret: String, onDone: (() -> Unit)? = null) {
@ -199,6 +202,7 @@ internal class DefaultQrCodeVerificationTransaction(
throw IllegalStateException("Interactive Key verification already started")
}
state = VerificationTxState.Started
val startMessage = transport.createStartForQrCode(
deviceId,
transactionId,
@ -208,7 +212,7 @@ internal class DefaultQrCodeVerificationTransaction(
transport.sendToOther(
EventType.KEY_VERIFICATION_START,
startMessage,
VerificationTxState.Started,
VerificationTxState.WaitingOtherReciprocateConfirm,
CancelCode.User,
onDone
)
@ -244,6 +248,15 @@ internal class DefaultQrCodeVerificationTransaction(
}
}
fun onDoneReceived() {
if (state != VerificationTxState.WaitingOtherReciprocateConfirm) {
cancel(CancelCode.UnexpectedMessage)
return
}
state = VerificationTxState.Verified
transport.done(transactionId) {}
}
override fun otherUserScannedMyQrCode() {
when (qrCodeData) {
is QrCodeData.VerifyingAnotherUser -> {
@ -265,6 +278,6 @@ internal class DefaultQrCodeVerificationTransaction(
override fun otherUserDidNotScannedMyQrCode() {
// What can I do then?
// At least remove the transaction...
state = VerificationTxState.Cancelled(CancelCode.MismatchedKeys, true)
cancel(CancelCode.MismatchedKeys)
}
}

View File

@ -37,6 +37,7 @@ import im.vector.riotx.features.crypto.verification.cancel.VerificationNotMeFrag
import im.vector.riotx.features.crypto.verification.choose.VerificationChooseMethodFragment
import im.vector.riotx.features.crypto.verification.conclusion.VerificationConclusionFragment
import im.vector.riotx.features.crypto.verification.emoji.VerificationEmojiCodeFragment
import im.vector.riotx.features.crypto.verification.qrconfirmation.VerificationQRWaitingFragment
import im.vector.riotx.features.crypto.verification.qrconfirmation.VerificationQrScannedByOtherFragment
import im.vector.riotx.features.crypto.verification.request.VerificationRequestFragment
import im.vector.riotx.features.grouplist.GroupListFragment
@ -339,6 +340,11 @@ interface FragmentModule {
@FragmentKey(VerificationQrScannedByOtherFragment::class)
fun bindVerificationQrScannedByOtherFragment(fragment: VerificationQrScannedByOtherFragment): Fragment
@Binds
@IntoMap
@FragmentKey(VerificationQRWaitingFragment::class)
fun bindVerificationQRWaitingFragment(fragment: VerificationQRWaitingFragment): Fragment
@Binds
@IntoMap
@FragmentKey(VerificationConclusionFragment::class)

View File

@ -50,6 +50,7 @@ import im.vector.riotx.features.crypto.verification.cancel.VerificationNotMeFrag
import im.vector.riotx.features.crypto.verification.choose.VerificationChooseMethodFragment
import im.vector.riotx.features.crypto.verification.conclusion.VerificationConclusionFragment
import im.vector.riotx.features.crypto.verification.emoji.VerificationEmojiCodeFragment
import im.vector.riotx.features.crypto.verification.qrconfirmation.VerificationQRWaitingFragment
import im.vector.riotx.features.crypto.verification.qrconfirmation.VerificationQrScannedByOtherFragment
import im.vector.riotx.features.crypto.verification.request.VerificationRequestFragment
import im.vector.riotx.features.home.AvatarRenderer
@ -244,6 +245,13 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
showFragment(VerificationQrScannedByOtherFragment::class, Bundle())
return@withState
}
is VerificationTxState.Started,
is VerificationTxState.WaitingOtherReciprocateConfirm -> {
showFragment(VerificationQRWaitingFragment::class, Bundle().apply {
putParcelable(MvRx.KEY_ARG, VerificationQRWaitingFragment.Args(state.isMe, state.otherUserMxItem?.getBestName() ?: ""))
})
return@withState
}
is VerificationTxState.Verified -> {
showFragment(VerificationConclusionFragment::class, Bundle().apply {
putParcelable(MvRx.KEY_ARG, VerificationConclusionFragment.Args(true, null, state.isMe))

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.riotx.features.crypto.verification.qrconfirmation
import com.airbnb.epoxy.EpoxyController
import im.vector.riotx.R
import im.vector.riotx.core.resources.ColorProvider
import im.vector.riotx.core.resources.StringProvider
import im.vector.riotx.features.crypto.verification.epoxy.bottomSheetVerificationBigImageItem
import im.vector.riotx.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
import im.vector.riotx.features.crypto.verification.epoxy.bottomSheetVerificationWaitingItem
import javax.inject.Inject
class VerificationQRWaitingController @Inject constructor(
private val stringProvider: StringProvider,
private val colorProvider: ColorProvider
) : EpoxyController() {
private var args: VerificationQRWaitingFragment.Args? = null
fun update(args: VerificationQRWaitingFragment.Args) {
this.args = args
requestModelBuild()
}
override fun buildModels() {
val params = args ?: return
bottomSheetVerificationNoticeItem {
id("notice")
apply {
notice(stringProvider.getString(R.string.qr_code_scanned_verif_waiting_notice))
}
}
bottomSheetVerificationBigImageItem {
id("image")
imageRes(R.drawable.ic_shield_trusted)
}
bottomSheetVerificationWaitingItem {
id("waiting")
title(stringProvider.getString(R.string.qr_code_scanned_verif_waiting, params.otherUserName))
}
}
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.riotx.features.crypto.verification.qrconfirmation
import android.os.Bundle
import android.os.Parcelable
import android.view.View
import com.airbnb.mvrx.MvRx
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.configureWith
import im.vector.riotx.core.platform.VectorBaseFragment
import kotlinx.android.parcel.Parcelize
import kotlinx.android.synthetic.main.bottom_sheet_verification_child_fragment.*
import javax.inject.Inject
class VerificationQRWaitingFragment @Inject constructor(
val controller: VerificationQRWaitingController
) : VectorBaseFragment() {
@Parcelize
data class Args(
val isMe: Boolean,
val otherUserName: String
) : Parcelable
override fun getLayoutResId() = R.layout.bottom_sheet_verification_child_fragment
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupRecyclerView()
(arguments?.getParcelable(MvRx.KEY_ARG) as? Args)?.let {
controller.update(it)
}
}
override fun onDestroyView() {
bottomSheetVerificationRecyclerView.cleanup()
super.onDestroyView()
}
private fun setupRecyclerView() {
bottomSheetVerificationRecyclerView.configureWith(controller, hasFixedSize = false, disableItemAnimation = true)
}
}

View File

@ -21,6 +21,7 @@ import im.vector.riotx.R
import im.vector.riotx.core.epoxy.dividerItem
import im.vector.riotx.core.resources.ColorProvider
import im.vector.riotx.core.resources.StringProvider
import im.vector.riotx.features.crypto.verification.VerificationBottomSheetViewState
import im.vector.riotx.features.crypto.verification.epoxy.bottomSheetVerificationActionItem
import im.vector.riotx.features.crypto.verification.epoxy.bottomSheetVerificationNoticeItem
import javax.inject.Inject
@ -32,14 +33,26 @@ class VerificationQrScannedByOtherController @Inject constructor(
var listener: Listener? = null
init {
private var viewState: VerificationBottomSheetViewState? = null
fun update(viewState: VerificationBottomSheetViewState) {
this.viewState = viewState
requestModelBuild()
}
override fun buildModels() {
val state = viewState ?: return
bottomSheetVerificationNoticeItem {
id("notice")
notice(stringProvider.getString(R.string.qr_code_scanned_by_other_notice))
apply {
if (state.isMe) {
val name = state.otherUserMxItem?.getBestName() ?: ""
notice(stringProvider.getString(R.string.qr_code_scanned_self_verif_notice, name))
} else {
notice(stringProvider.getString(R.string.qr_code_scanned_by_other_notice))
}
}
}
dividerItem {

View File

@ -18,6 +18,7 @@ package im.vector.riotx.features.crypto.verification.qrconfirmation
import android.os.Bundle
import android.view.View
import com.airbnb.mvrx.parentFragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.riotx.R
import im.vector.riotx.core.extensions.cleanup
import im.vector.riotx.core.extensions.configureWith
@ -37,10 +38,13 @@ class VerificationQrScannedByOtherFragment @Inject constructor(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupRecyclerView()
}
override fun invalidate() = withState(sharedViewModel) { state ->
controller.update(state)
}
override fun onDestroyView() {
bottomSheetVerificationRecyclerView.cleanup()
controller.listener = null

View File

@ -2148,7 +2148,7 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming
<string name="a11y_qr_code_for_verification">QR code</string>
<string name="qr_code_scanned_by_other_notice">Did the other user successfully scan the QR code?</string>
<string name="qr_code_scanned_by_other_notice">Almost there! Is %s showing the same shield?</string>
<string name="qr_code_scanned_by_other_yes">Yes</string>
<string name="qr_code_scanned_by_other_no">No</string>

View File

@ -94,6 +94,11 @@
<string name="encryption_unknown_algorithm_tile_description">The encryption used by this room is not supported</string>
<string name="room_created_summary_item">%s created and configured the room.</string>
<string name="qr_code_scanned_self_verif_notice">Almost there! Is the other device showing the same shield?</string>
<string name="qr_code_scanned_verif_waiting_notice">Almost there! Waiting for confirmation…</string>
<string name="qr_code_scanned_verif_waiting">Waiting for %s…</string>
<string name="error_failed_to_import_keys">Failed to import keys</string>
<!-- END Strings added by Valere -->