From 517af968e6b923cc8bd9a9a743e1367ca857899f Mon Sep 17 00:00:00 2001 From: valere Date: Mon, 22 May 2023 22:26:26 +0200 Subject: [PATCH 1/3] Remove legacy manually verify specific other device --- .../src/main/res/values/strings.xml | 4 +++- .../devices/DeviceListAction.kt | 2 -- .../devices/DeviceListBottomSheet.kt | 11 +-------- .../DeviceListBottomSheetViewEvents.kt | 4 +--- .../devices/DeviceListBottomSheetViewModel.kt | 21 ++--------------- .../devices/DeviceTrustInfoActionFragment.kt | 5 ---- .../devices/DeviceTrustInfoEpoxyController.kt | 23 +++---------------- .../features/settings/devices/TrustUtils.kt | 2 ++ 8 files changed, 12 insertions(+), 60 deletions(-) diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index 3d1a36d4c34..bc29627bf9e 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -2465,7 +2465,9 @@ This session is trusted for secure messaging because %1$s (%2$s) verified it: %1$s (%2$s) signed in using a new session: - Until this user trusts this session, messages sent to and from it are labeled with warnings. Alternatively, you can manually verify it. + + Until this user trusts this session, messages sent to and from it are labeled with warnings. Alternatively, you can manually verify it. + Until this user trusts this session, messages sent to and from it are labeled with warnings. Initialize CrossSigning diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListAction.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListAction.kt index c269a4166af..09ae73a55c8 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListAction.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListAction.kt @@ -22,6 +22,4 @@ import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo sealed class DeviceListAction : VectorViewModelAction { data class SelectDevice(val device: CryptoDeviceInfo) : DeviceListAction() object DeselectDevice : DeviceListAction() - - data class ManuallyVerify(val deviceId: String) : DeviceListAction() } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt index 2a0ca4850e1..2dbb03121d2 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt @@ -47,16 +47,7 @@ class DeviceListBottomSheet : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) viewModel.observeViewEvents { - when (it) { - is DeviceListBottomSheetViewEvents.Verify -> { - // TODO selfverif -// VerificationBottomSheet.withArgs( -// // roomId = null, -// otherUserId = it.userId, -// transactionId = it.txID -// ).show(requireActivity().supportFragmentManager, "REQPOP") - } - } + // nop } } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewEvents.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewEvents.kt index 8c6cba6cd94..159f505e164 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewEvents.kt @@ -21,6 +21,4 @@ import im.vector.app.core.platform.VectorViewEvents /** * Transient events for device list screen. */ -sealed class DeviceListBottomSheetViewEvents : VectorViewEvents { - data class Verify(val userId: String, val txID: String) : DeviceListBottomSheetViewEvents() -} +sealed class DeviceListBottomSheetViewEvents : VectorViewEvents diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt index c3281858f07..435c44aa115 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt @@ -34,7 +34,6 @@ import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo -import org.matrix.android.sdk.api.session.crypto.verification.VerificationMethod import org.matrix.android.sdk.api.session.getUserOrDefault import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem @@ -42,7 +41,7 @@ import org.matrix.android.sdk.flow.flow data class DeviceListViewState( val userId: String, - val allowDeviceAction: Boolean, + val myUserId: String, val userItem: MatrixItem? = null, val memberCrossSigningKey: MXCrossSigningInfo? = null, val myDeviceId: String = "", @@ -69,7 +68,7 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor( val session = EntryPoints.get(viewModelContext.app(), SingletonEntryPoint::class.java).activeSessionHolder().getActiveSession() return DeviceListViewState( userId = userId, - allowDeviceAction = args.allowDeviceAction, + myUserId = session.myUserId, userItem = session.getUserOrDefault(userId).toMatrixItem(), myDeviceId = session.sessionParams.deviceId, ) @@ -104,7 +103,6 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor( when (action) { is DeviceListAction.SelectDevice -> selectDevice(action) is DeviceListAction.DeselectDevice -> deselectDevice() - is DeviceListAction.ManuallyVerify -> manuallyVerify(action) } } @@ -121,7 +119,6 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor( } private fun selectDevice(action: DeviceListAction.SelectDevice) { - if (!initialState.allowDeviceAction) return setState { copy(selectedDevice = action.device) } @@ -132,18 +129,4 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor( copy(selectedDevice = null) } } - - private fun manuallyVerify(action: DeviceListAction.ManuallyVerify) { - if (!initialState.allowDeviceAction) return - viewModelScope.launch { - session.cryptoService().verificationService().requestDeviceVerification( - methods = listOf(VerificationMethod.SAS), - otherUserId = initialState.userId, - otherDeviceId = action.deviceId, - ).transactionId - .let { txID -> - _viewEvents.post(DeviceListBottomSheetViewEvents.Verify(initialState.userId, txID)) - } - } - } } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceTrustInfoActionFragment.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceTrustInfoActionFragment.kt index d8abd910918..d3b5a259139 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceTrustInfoActionFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceTrustInfoActionFragment.kt @@ -28,7 +28,6 @@ import im.vector.app.core.extensions.configureWith import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.utils.DimensionConverter import im.vector.app.databinding.BottomSheetGenericListBinding -import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo import javax.inject.Inject @AndroidEntryPoint @@ -63,8 +62,4 @@ class DeviceTrustInfoActionFragment : override fun invalidate() = withState(viewModel) { epoxyController.setData(it) } - - override fun onVerifyManually(device: CryptoDeviceInfo) { - viewModel.handle(DeviceListAction.ManuallyVerify(device.deviceId)) - } } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceTrustInfoEpoxyController.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceTrustInfoEpoxyController.kt index 20c388dd95a..0f39fc889ce 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceTrustInfoEpoxyController.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceTrustInfoEpoxyController.kt @@ -25,13 +25,10 @@ import im.vector.app.core.ui.list.genericFooterItem import im.vector.app.core.ui.list.genericItem import im.vector.app.core.ui.list.genericWithValueItem import im.vector.app.core.utils.DimensionConverter -import im.vector.app.features.crypto.verification.epoxy.bottomSheetVerificationActionItem -import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.devices.TrustUtils import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence import me.gujun.android.span.span import org.matrix.android.sdk.api.extensions.orFalse -import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel import javax.inject.Inject @@ -39,13 +36,10 @@ class DeviceTrustInfoEpoxyController @Inject constructor( private val stringProvider: StringProvider, private val colorProvider: ColorProvider, private val dimensionConverter: DimensionConverter, - private val vectorPreferences: VectorPreferences ) : TypedEpoxyController() { - interface InteractionListener { - fun onVerifyManually(device: CryptoDeviceInfo) - } + interface InteractionListener var interactionListener: InteractionListener? = null @@ -54,7 +48,7 @@ class DeviceTrustInfoEpoxyController @Inject constructor( data?.selectedDevice?.let { cryptoDeviceInfo -> val trustMSK = data.memberCrossSigningKey?.isTrusted().orFalse() val legacyMode = data.memberCrossSigningKey == null - val isMyDevice = data.myDeviceId == cryptoDeviceInfo.deviceId + val isMyDevice = data.userId == data.myUserId && data.myDeviceId == cryptoDeviceInfo.deviceId val trustLevel = TrustUtils.shieldForTrust( isMyDevice, trustMSK, @@ -126,18 +120,7 @@ class DeviceTrustInfoEpoxyController @Inject constructor( id("warn") centered(false) textColor(host.colorProvider.getColorFromAttribute(R.attr.vctr_content_primary)) - text(host.stringProvider.getString(R.string.verification_profile_device_untrust_info).toEpoxyCharSequence()) - } - - bottomSheetVerificationActionItem { - id("verify") - title(host.stringProvider.getString(R.string.cross_signing_verify_by_emoji)) - titleColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary)) - iconRes(R.drawable.ic_arrow_right) - iconColor(host.colorProvider.getColorFromAttribute(R.attr.colorPrimary)) - listener { - host.interactionListener?.onVerifyManually(cryptoDeviceInfo) - } + text(host.stringProvider.getString(R.string.verification_profile_other_device_untrust_info).toEpoxyCharSequence()) } } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/TrustUtils.kt b/vector/src/main/java/im/vector/app/features/settings/devices/TrustUtils.kt index 7709a63344b..983790c80a2 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/TrustUtils.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/TrustUtils.kt @@ -22,6 +22,8 @@ import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel // TODO Replace usage by the use case GetEncryptionTrustLevelForDeviceUseCase object TrustUtils { + // XXX why is this using the RoomEncryptionTrustLevel? + // should be using a new DeviceTrustShield enum fun shieldForTrust( currentDevice: Boolean, trustMSK: Boolean, From 94956a2ec64b78be79572dfc85218f5ddcf69338 Mon Sep 17 00:00:00 2001 From: valere Date: Mon, 22 May 2023 22:37:37 +0200 Subject: [PATCH 2/3] Add change log --- changelog.d/8458.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/8458.misc diff --git a/changelog.d/8458.misc b/changelog.d/8458.misc new file mode 100644 index 00000000000..ba32317523d --- /dev/null +++ b/changelog.d/8458.misc @@ -0,0 +1 @@ +Remove UI option to manually verify a specific device of another user (deprecated behaviour) From bb59a758cf346d44f9391dedf8491770bf789301 Mon Sep 17 00:00:00 2001 From: valere Date: Tue, 23 May 2023 16:38:53 +0200 Subject: [PATCH 3/3] code review --- .../crypto/quads/SharedSecuredStorageResetAllFragment.kt | 2 +- .../roommemberprofile/devices/DeviceListBottomSheet.kt | 5 ++--- .../im/vector/app/features/settings/devices/TrustUtils.kt | 2 -- .../verification/GetEncryptionTrustLevelForDeviceUseCase.kt | 2 ++ 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecuredStorageResetAllFragment.kt b/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecuredStorageResetAllFragment.kt index 66344107a4f..d060e3996d0 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecuredStorageResetAllFragment.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecuredStorageResetAllFragment.kt @@ -52,7 +52,7 @@ class SharedSecuredStorageResetAllFragment : views.ssssResetOtherDevices.debouncedClicks { withState(sharedViewModel) { - DeviceListBottomSheet.newInstance(it.userId, false).show(childFragmentManager, "DEV_LIST") + DeviceListBottomSheet.newInstance(it.userId).show(childFragmentManager, "DEV_LIST") } } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt index 2dbb03121d2..63c44b40003 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/devices/DeviceListBottomSheet.kt @@ -100,13 +100,12 @@ class DeviceListBottomSheet : @Parcelize data class Args( val userId: String, - val allowDeviceAction: Boolean ) : Parcelable companion object { - fun newInstance(userId: String, allowDeviceAction: Boolean = true): DeviceListBottomSheet { + fun newInstance(userId: String): DeviceListBottomSheet { return DeviceListBottomSheet().apply { - setArguments(Args(userId, allowDeviceAction)) + setArguments(Args(userId)) } } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/TrustUtils.kt b/vector/src/main/java/im/vector/app/features/settings/devices/TrustUtils.kt index 983790c80a2..7709a63344b 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/TrustUtils.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/TrustUtils.kt @@ -22,8 +22,6 @@ import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel // TODO Replace usage by the use case GetEncryptionTrustLevelForDeviceUseCase object TrustUtils { - // XXX why is this using the RoomEncryptionTrustLevel? - // should be using a new DeviceTrustShield enum fun shieldForTrust( currentDevice: Boolean, trustMSK: Boolean, diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/verification/GetEncryptionTrustLevelForDeviceUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/verification/GetEncryptionTrustLevelForDeviceUseCase.kt index 268ae866013..762a6364940 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/verification/GetEncryptionTrustLevelForDeviceUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/verification/GetEncryptionTrustLevelForDeviceUseCase.kt @@ -25,6 +25,8 @@ class GetEncryptionTrustLevelForDeviceUseCase @Inject constructor( private val getEncryptionTrustLevelForOtherDeviceUseCase: GetEncryptionTrustLevelForOtherDeviceUseCase, ) { + // XXX why is this using the RoomEncryptionTrustLevel? + // should be using a new DeviceTrustShield enum fun execute(currentSessionCrossSigningInfo: CurrentSessionCrossSigningInfo, cryptoDeviceInfo: CryptoDeviceInfo?): RoomEncryptionTrustLevel? { if (cryptoDeviceInfo == null) { return null