Send verification request when the device is not new

This commit is contained in:
ganfra 2020-07-08 14:56:36 +02:00 committed by Valere
commit d49d0295a2
15 changed files with 91 additions and 43 deletions

View file

@ -10,7 +10,8 @@ Improvements 🙌:
- Handling (almost) properly the groups fetching (#1634)
Bugfix 🐛:
-
- Regression | Share action menu do not work (#1647)
- verification issues on transition (#1555)
Translations 🗣:
-

View file

@ -1234,7 +1234,7 @@ internal class DefaultVerificationService @Inject constructor(
)
// We can SCAN or SHOW QR codes only if cross-signing is enabled
val methodValues = if (crossSigningService.isCrossSigningVerified()) {
val methodValues = if (crossSigningService.getMyCrossSigningKeys() != null) {
// Add reciprocate method if application declares it can scan or show QR codes
// Not sure if it ok to do that (?)
val reciprocateMethod = methods

View file

@ -250,7 +250,10 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
is VerificationTxState.Started,
is VerificationTxState.WaitingOtherReciprocateConfirm -> {
showFragment(VerificationQRWaitingFragment::class, Bundle().apply {
putParcelable(MvRx.KEY_ARG, VerificationQRWaitingFragment.Args(state.isMe, state.otherUserMxItem?.getBestName() ?: ""))
putParcelable(MvRx.KEY_ARG, VerificationQRWaitingFragment.Args(
isMe = state.isMe,
otherUserName = state.otherUserMxItem?.getBestName() ?: ""
))
})
return@withState
}
@ -353,6 +356,17 @@ class VerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {
}
}
}
fun forSelfVerification(session: Session, outgoingRequest: String): VerificationBottomSheet {
return VerificationBottomSheet().apply {
arguments = Bundle().apply {
putParcelable(MvRx.KEY_ARG, VerificationArgs(
otherUserId = session.myUserId,
selfVerificationMode = true,
verificationId = outgoingRequest
))
}
}
}
const val WAITING_SELF_VERIF_TAG: String = "WAITING_SELF_VERIF_TAG"
}

View file

@ -177,7 +177,11 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet
R.string.crosssigning_verify_this_session,
R.string.confirm_your_identity
) {
it.navigator.waitSessionVerification(it)
if (event.waitForIncomingRequest) {
it.navigator.waitSessionVerification(it)
} else {
it.navigator.requestSelfSessionVerification(it)
}
}
}

View file

@ -21,5 +21,5 @@ import im.vector.riotx.core.platform.VectorViewEvents
sealed class HomeActivityViewEvents : VectorViewEvents {
data class AskPasswordToInitCrossSigning(val userItem: MatrixItem.UserItem?) : HomeActivityViewEvents()
data class OnNewSession(val userItem: MatrixItem.UserItem?) : HomeActivityViewEvents()
data class OnNewSession(val userItem: MatrixItem.UserItem?, val waitForIncomingRequest: Boolean = true) : HomeActivityViewEvents()
}

View file

@ -130,7 +130,14 @@ class HomeActivityViewModel @AssistedInject constructor(
// Cross-signing is already set up for this user, is it trusted?
if (!mxCrossSigningInfo.isTrusted()) {
// New session
_viewEvents.post(HomeActivityViewEvents.OnNewSession(session.getUser(session.myUserId)?.toMatrixItem()))
_viewEvents.post(
HomeActivityViewEvents.OnNewSession(
session.getUser(session.myUserId)?.toMatrixItem(),
// If it's an old unverified, we should send requests
// instead of waiting for an incoming one
reAuthHelper.data != null
)
)
}
} else {
// Initialize cross-signing

View file

@ -1337,13 +1337,13 @@ class RoomDetailFragment @Inject constructor(
private fun onShareActionClicked(action: EventSharedAction.Share) {
session.fileService().downloadFile(
FileService.DownloadMode.FOR_EXTERNAL_SHARE,
action.eventId,
action.messageContent.body,
action.messageContent.getFileUrl(),
action.messageContent.mimeType,
action.messageContent.encryptedFileInfo?.toElementToDecrypt(),
object : MatrixCallback<File> {
downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE,
id = action.eventId,
fileName = action.messageContent.body,
mimeType = action.messageContent.mimeType,
url = action.messageContent.getFileUrl(),
elementToDecrypt = action.messageContent.encryptedFileInfo?.toElementToDecrypt(),
callback = object : MatrixCallback<File> {
override fun onSuccess(data: File) {
if (isAdded) {
shareMedia(requireContext(), data, getMimeTypeFromUri(requireContext(), data.toUri()))

View file

@ -873,13 +873,13 @@ class RoomDetailViewModel @AssistedInject constructor(
}
} else {
session.fileService().downloadFile(
FileService.DownloadMode.FOR_INTERNAL_USE,
action.eventId,
action.messageFileContent.getFileName(),
action.messageFileContent.mimeType,
mxcUrl,
action.messageFileContent.encryptedFileInfo?.toElementToDecrypt(),
object : MatrixCallback<File> {
downloadMode = FileService.DownloadMode.FOR_INTERNAL_USE,
id = action.eventId,
fileName = action.messageFileContent.getFileName(),
mimeType = action.messageFileContent.mimeType,
url = mxcUrl,
elementToDecrypt = action.messageFileContent.encryptedFileInfo?.toElementToDecrypt(),
callback = object : MatrixCallback<File> {
override fun onSuccess(data: File) {
_viewEvents.post(RoomDetailViewEvents.DownloadFileState(
action.messageFileContent.mimeType,

View file

@ -134,13 +134,13 @@ class ImageMediaViewerActivity : VectorBaseActivity() {
private fun onShareActionClicked() {
session.fileService().downloadFile(
FileService.DownloadMode.FOR_EXTERNAL_SHARE,
mediaData.eventId,
mediaData.filename,
mediaData.mimeType,
mediaData.url,
mediaData.elementToDecrypt,
object : MatrixCallback<File> {
downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE,
id = mediaData.eventId,
fileName = mediaData.filename,
mimeType = mediaData.mimeType,
url = mediaData.url,
elementToDecrypt = mediaData.elementToDecrypt,
callback = object : MatrixCallback<File> {
override fun onSuccess(data: File) {
shareMedia(this@ImageMediaViewerActivity, data, getMimeTypeFromUri(this@ImageMediaViewerActivity, data.toUri()))
}

View file

@ -70,7 +70,7 @@ class VideoContentRenderer @Inject constructor(private val activeSessionHolder:
downloadMode = FileService.DownloadMode.FOR_INTERNAL_USE,
id = data.eventId,
fileName = data.filename,
mimeType = null,
mimeType = data.mimeType,
url = data.url,
elementToDecrypt = data.elementToDecrypt,
callback = object : MatrixCallback<File> {

View file

@ -79,13 +79,13 @@ class VideoMediaViewerActivity : VectorBaseActivity() {
private fun onShareActionClicked() {
session.fileService().downloadFile(
FileService.DownloadMode.FOR_EXTERNAL_SHARE,
mediaData.eventId,
mediaData.filename,
mediaData.mimeType,
mediaData.url,
mediaData.elementToDecrypt,
object : MatrixCallback<File> {
downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE,
id = mediaData.eventId,
fileName = mediaData.filename,
mimeType = mediaData.mimeType,
url = mediaData.url,
elementToDecrypt = mediaData.elementToDecrypt,
callback = object : MatrixCallback<File> {
override fun onSuccess(data: File) {
shareMedia(this@VideoMediaViewerActivity, data, getMimeTypeFromUri(this@VideoMediaViewerActivity, data.toUri()))
}

View file

@ -116,6 +116,26 @@ class DefaultNavigator @Inject constructor(
}
}
override fun requestSelfSessionVerification(context: Context) {
val session = sessionHolder.getSafeActiveSession() ?: return
val otherSessions = session.cryptoService().getCryptoDeviceInfo(session.myUserId).filter {
it.deviceId != session.sessionParams.deviceId
}.map { it.deviceId }
if (context is VectorBaseActivity) {
if (otherSessions.isNotEmpty()) {
val pr = session.cryptoService().verificationService().requestKeyVerification(
supportedVerificationMethodsProvider.provide(),
session.myUserId,
otherSessions)
VerificationBottomSheet.forSelfVerification(session, pr.transactionId ?: pr.localId)
.show(context.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
} else {
VerificationBottomSheet.forSelfVerification(session)
.show(context.supportFragmentManager, VerificationBottomSheet.WAITING_SELF_VERIF_TAG)
}
}
}
override fun waitSessionVerification(context: Context) {
val session = sessionHolder.getSafeActiveSession() ?: return
if (context is VectorBaseActivity) {

View file

@ -40,6 +40,8 @@ interface Navigator {
fun requestSessionVerification(context: Context, otherSessionId: String)
fun requestSelfSessionVerification(context: Context)
fun waitSessionVerification(context: Context)
fun upgradeSessionSecurity(context: Context, initCrossSigningOnly: Boolean)

View file

@ -158,13 +158,13 @@ class RoomUploadsViewModel @AssistedInject constructor(
try {
val file = awaitCallback<File> {
session.fileService().downloadFile(
FileService.DownloadMode.FOR_EXTERNAL_SHARE,
action.uploadEvent.eventId,
action.uploadEvent.contentWithAttachmentContent.body,
action.uploadEvent.contentWithAttachmentContent.getFileUrl(),
action.uploadEvent.contentWithAttachmentContent.mimeType,
action.uploadEvent.contentWithAttachmentContent.encryptedFileInfo?.toElementToDecrypt(),
it)
downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE,
id = action.uploadEvent.eventId,
fileName = action.uploadEvent.contentWithAttachmentContent.body,
mimeType = action.uploadEvent.contentWithAttachmentContent.mimeType,
url = action.uploadEvent.contentWithAttachmentContent.getFileUrl(),
elementToDecrypt = action.uploadEvent.contentWithAttachmentContent.encryptedFileInfo?.toElementToDecrypt(),
callback = it)
}
_viewEvents.post(RoomUploadsViewEvents.FileReadyForSaving(file, action.uploadEvent.contentWithAttachmentContent.body))
} catch (failure: Throwable) {

View file

@ -51,7 +51,7 @@ class CrossSigningSettingsFragment @Inject constructor(
Unit
}
CrossSigningSettingsViewEvents.VerifySession -> {
navigator.waitSessionVerification(requireActivity())
navigator.requestSelfSessionVerification(requireActivity())
}
CrossSigningSettingsViewEvents.SetUpRecovery -> {
navigator.upgradeSessionSecurity(requireActivity(), false)