From 54c0239969793586511d3c4c8b7b82b8510ade30 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 24 Apr 2020 16:23:24 +0200 Subject: [PATCH 1/7] fix layout issue when text is displayed on 2 lines --- .../src/main/res/layout/bottom_sheet_bootstrap.xml | 12 +++--------- .../main/res/layout/bottom_sheet_verification.xml | 2 -- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/vector/src/main/res/layout/bottom_sheet_bootstrap.xml b/vector/src/main/res/layout/bottom_sheet_bootstrap.xml index 5f2ce368ff..fda590517c 100644 --- a/vector/src/main/res/layout/bottom_sheet_bootstrap.xml +++ b/vector/src/main/res/layout/bottom_sheet_bootstrap.xml @@ -1,5 +1,4 @@ - + android:paddingBottom="16dp"> - Date: Fri, 24 Apr 2020 17:00:30 +0200 Subject: [PATCH 2/7] Cleanup --- .../fragment_bootstrap_enter_account_password.xml | 6 ++---- .../layout/fragment_bootstrap_enter_passphrase.xml | 14 +++++++------- .../layout/fragment_bootstrap_migrate_backup.xml | 1 - 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/vector/src/main/res/layout/fragment_bootstrap_enter_account_password.xml b/vector/src/main/res/layout/fragment_bootstrap_enter_account_password.xml index c91110402f..c26723637b 100644 --- a/vector/src/main/res/layout/fragment_bootstrap_enter_account_password.xml +++ b/vector/src/main/res/layout/fragment_bootstrap_enter_account_password.xml @@ -12,11 +12,11 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" - tools:text="@string/enter_account_password" android:textColor="?riotx_text_primary" android:textSize="14sp" app:layout_constraintBottom_toTopOf="@id/bootstrapAccountPasswordTil" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" + tools:text="@string/enter_account_password" /> @@ -46,9 +46,9 @@ + android:layout_marginBottom="2dp" /> + android:drawableTint="@color/riotx_destructive_accent" + android:gravity="center_vertical" + android:text="@string/bootstrap_dont_reuse_pwd" + android:textSize="12sp" /> diff --git a/vector/src/main/res/layout/fragment_bootstrap_migrate_backup.xml b/vector/src/main/res/layout/fragment_bootstrap_migrate_backup.xml index 68417044f9..ac1b70d2c9 100644 --- a/vector/src/main/res/layout/fragment_bootstrap_migrate_backup.xml +++ b/vector/src/main/res/layout/fragment_bootstrap_migrate_backup.xml @@ -79,7 +79,6 @@ Date: Fri, 24 Apr 2020 17:22:05 +0200 Subject: [PATCH 3/7] Add "continue" button to the bootstrap bottom sheet --- .../recover/BootstrapConfirmPassphraseFragment.kt | 10 ++++++++-- .../crypto/recover/BootstrapEnterPassphraseFragment.kt | 10 ++++++++-- .../res/layout/fragment_bootstrap_enter_passphrase.xml | 9 +++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapConfirmPassphraseFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapConfirmPassphraseFragment.kt index 34a49e852e..d09eafee58 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapConfirmPassphraseFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapConfirmPassphraseFragment.kt @@ -95,6 +95,14 @@ class BootstrapConfirmPassphraseFragment @Inject constructor( sharedViewModel.handle(BootstrapActions.TogglePasswordVisibility) } .disposeOnDestroyView() + + bootstrapSubmit.clicks() + .debounce(300, TimeUnit.MILLISECONDS) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { + submit() + } + .disposeOnDestroyView() } private fun submit() = withState(sharedViewModel) { state -> @@ -113,8 +121,6 @@ class BootstrapConfirmPassphraseFragment @Inject constructor( } override fun invalidate() = withState(sharedViewModel) { state -> - super.invalidate() - if (state.step is BootstrapStep.ConfirmPassphrase) { val isPasswordVisible = state.step.isPasswordVisible ssss_passphrase_enter_edittext.showPassword(isPasswordVisible, updateCursor = false) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapEnterPassphraseFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapEnterPassphraseFragment.kt index 35e2e1373c..952b0e5d03 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapEnterPassphraseFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapEnterPassphraseFragment.kt @@ -90,6 +90,14 @@ class BootstrapEnterPassphraseFragment @Inject constructor( sharedViewModel.handle(BootstrapActions.TogglePasswordVisibility) } .disposeOnDestroyView() + + bootstrapSubmit.clicks() + .debounce(300, TimeUnit.MILLISECONDS) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { + submit() + } + .disposeOnDestroyView() } private fun submit() = withState(sharedViewModel) { state -> @@ -108,8 +116,6 @@ class BootstrapEnterPassphraseFragment @Inject constructor( } override fun invalidate() = withState(sharedViewModel) { state -> - super.invalidate() - if (state.step is BootstrapStep.SetupPassphrase) { val isPasswordVisible = state.step.isPasswordVisible ssss_passphrase_enter_edittext.showPassword(isPasswordVisible, updateCursor = false) diff --git a/vector/src/main/res/layout/fragment_bootstrap_enter_passphrase.xml b/vector/src/main/res/layout/fragment_bootstrap_enter_passphrase.xml index c4289aa3be..b344f2819d 100644 --- a/vector/src/main/res/layout/fragment_bootstrap_enter_passphrase.xml +++ b/vector/src/main/res/layout/fragment_bootstrap_enter_passphrase.xml @@ -1,5 +1,4 @@ - @@ -78,6 +76,13 @@ app:layout_constraintStart_toEndOf="@+id/ssss_passphrase_enter_til" app:layout_constraintTop_toTopOf="@+id/ssss_passphrase_enter_til" /> + From 35962c3cb504399fe3a53e128180bb05267307b4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 24 Apr 2020 17:40:15 +0200 Subject: [PATCH 4/7] Do not propose bootsrap for SSO accounts Because we do not support yet confirming account credentials using SSO --- .../riotx/features/home/HomeActivity.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt index ac2e2b7fa9..c28dca8dbf 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeActivity.kt @@ -167,13 +167,19 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { val crossSigningEnabledOnAccount = myCrossSigningKeys != null if (!crossSigningEnabledOnAccount && !sharedActionViewModel.isAccountCreation) { - // We need to ask - promptSecurityEvent( - session, - R.string.upgrade_security, - R.string.security_prompt_text - ) { - it.navigator.upgradeSessionSecurity(it) + // Do not propose for SSO accounts, because we do not support yet confirming account credentials using SSO + if (session.getHomeServerCapabilities().canChangePassword) { + // We need to ask + promptSecurityEvent( + session, + R.string.upgrade_security, + R.string.security_prompt_text + ) { + it.navigator.upgradeSessionSecurity(it) + } + } else { + // Do not do it again + sharedActionViewModel.hasDisplayedCompleteSecurityPrompt = true } } else if (myCrossSigningKeys?.isTrusted() == false) { // We need to ask From ebecb9bb9adeea3667fba367923ef9a44c6ff0d9 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 24 Apr 2020 18:06:02 +0200 Subject: [PATCH 5/7] i18n --- .../settings/crosssigning/CrossSigningEpoxyController.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningEpoxyController.kt b/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningEpoxyController.kt index dd050c29ac..a4b9190c51 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningEpoxyController.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningEpoxyController.kt @@ -54,7 +54,7 @@ class CrossSigningEpoxyController @Inject constructor( if (vectorPreferences.developerMode() && !data.isUploadingKeys) { bottomSheetVerificationActionItem { id("resetkeys") - title("Reset keys") + title(stringProvider.getString(R.string.reset_cross_signing)) titleColor(colorProvider.getColor(R.color.riotx_destructive_accent)) iconRes(R.drawable.ic_arrow_right) iconColor(colorProvider.getColor(R.color.riotx_destructive_accent)) @@ -73,7 +73,7 @@ class CrossSigningEpoxyController @Inject constructor( if (vectorPreferences.developerMode()) { bottomSheetVerificationActionItem { id("resetkeys") - title("Reset keys") + title(stringProvider.getString(R.string.reset_cross_signing)) titleColor(colorProvider.getColor(R.color.riotx_destructive_accent)) iconRes(R.drawable.ic_arrow_right) iconColor(colorProvider.getColor(R.color.riotx_destructive_accent)) @@ -113,7 +113,7 @@ class CrossSigningEpoxyController @Inject constructor( if (vectorPreferences.developerMode()) { bottomSheetVerificationActionItem { id("resetkeys") - title("Reset keys") + title(stringProvider.getString(R.string.reset_cross_signing)) titleColor(colorProvider.getColor(R.color.riotx_destructive_accent)) iconRes(R.drawable.ic_arrow_right) iconColor(colorProvider.getColor(R.color.riotx_destructive_accent)) @@ -130,7 +130,7 @@ class CrossSigningEpoxyController @Inject constructor( if (vectorPreferences.developerMode() && !data.isUploadingKeys) { bottomSheetVerificationActionItem { id("initKeys") - title("Initialize keys") + title(stringProvider.getString(R.string.initialize_cross_signing)) titleColor(colorProvider.getColor(R.color.riotx_positive_accent)) iconRes(R.drawable.ic_arrow_right) iconColor(colorProvider.getColor(R.color.riotx_positive_accent)) From a233e9b0a00ee7f1edf406cd1bbfe48f5a02815c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 24 Apr 2020 18:45:58 +0200 Subject: [PATCH 6/7] Avoid code duplication, and improve readability --- .../matrix/android/api/failure/Extensions.kt | 18 ++++++++ .../auth/registration/RegisterTask.kt | 24 ++-------- .../internal/crypto/tasks/DeleteDeviceTask.kt | 25 ++--------- .../crypto/tasks/UploadSigningKeysTask.kt | 41 ++++++----------- .../session/account/ChangePasswordTask.kt | 35 +++++---------- .../recover/BootstrapCrossSigningTask.kt | 16 +++---- .../CrossSigningSettingsViewModel.kt | 45 +++++++------------ 7 files changed, 73 insertions(+), 131 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Extensions.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Extensions.kt index 3a068af076..b325be4451 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Extensions.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Extensions.kt @@ -16,6 +16,9 @@ package im.vector.matrix.android.api.failure +import im.vector.matrix.android.api.extensions.tryThis +import im.vector.matrix.android.internal.auth.registration.RegistrationFlowResponse +import im.vector.matrix.android.internal.di.MoshiProvider import javax.net.ssl.HttpsURLConnection fun Throwable.is401() = @@ -37,3 +40,18 @@ fun Throwable.isInvalidPassword(): Boolean { && error.code == MatrixError.M_FORBIDDEN && error.message == "Invalid password" } + +/** + * Try to convert to a RegistrationFlowResponse. Return null in the cases it's not possible + */ +fun Throwable.toRegistrationFlowResponse(): RegistrationFlowResponse? { + return if (this is Failure.OtherServerError && this.httpCode == 401) { + tryThis { + MoshiProvider.providesMoshi() + .adapter(RegistrationFlowResponse::class.java) + .fromJson(this.errorBody) + } + } else { + null + } +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/registration/RegisterTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/registration/RegisterTask.kt index 69976b063f..473b960d94 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/registration/RegisterTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/registration/RegisterTask.kt @@ -18,8 +18,8 @@ package im.vector.matrix.android.internal.auth.registration import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.failure.Failure +import im.vector.matrix.android.api.failure.toRegistrationFlowResponse import im.vector.matrix.android.internal.auth.AuthAPI -import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task @@ -39,25 +39,9 @@ internal class DefaultRegisterTask( apiCall = authAPI.register(params.registrationParams) } } catch (throwable: Throwable) { - if (throwable is Failure.OtherServerError && throwable.httpCode == 401) { - // Parse to get a RegistrationFlowResponse - val registrationFlowResponse = try { - MoshiProvider.providesMoshi() - .adapter(RegistrationFlowResponse::class.java) - .fromJson(throwable.errorBody) - } catch (e: Exception) { - null - } - // check if the server response can be cast - if (registrationFlowResponse != null) { - throw Failure.RegistrationFlowError(registrationFlowResponse) - } else { - throw throwable - } - } else { - // Other error - throw throwable - } + throw throwable.toRegistrationFlowResponse() + ?.let { Failure.RegistrationFlowError(it) } + ?: throwable } } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceTask.kt index fbbaa0e0f7..809ec0be44 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/DeleteDeviceTask.kt @@ -17,10 +17,9 @@ package im.vector.matrix.android.internal.crypto.tasks import im.vector.matrix.android.api.failure.Failure -import im.vector.matrix.android.internal.auth.registration.RegistrationFlowResponse +import im.vector.matrix.android.api.failure.toRegistrationFlowResponse import im.vector.matrix.android.internal.crypto.api.CryptoApi import im.vector.matrix.android.internal.crypto.model.rest.DeleteDeviceParams -import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task import org.greenrobot.eventbus.EventBus @@ -43,25 +42,9 @@ internal class DefaultDeleteDeviceTask @Inject constructor( apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams()) } } catch (throwable: Throwable) { - if (throwable is Failure.OtherServerError && throwable.httpCode == 401) { - // Parse to get a RegistrationFlowResponse - val registrationFlowResponse = try { - MoshiProvider.providesMoshi() - .adapter(RegistrationFlowResponse::class.java) - .fromJson(throwable.errorBody) - } catch (e: Exception) { - null - } - // check if the server response can be casted - if (registrationFlowResponse != null) { - throw Failure.RegistrationFlowError(registrationFlowResponse) - } else { - throw throwable - } - } else { - // Other error - throw throwable - } + throw throwable.toRegistrationFlowResponse() + ?.let { Failure.RegistrationFlowError(it) } + ?: throwable } } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadSigningKeysTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadSigningKeysTask.kt index 0a69039219..a66a20617c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadSigningKeysTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadSigningKeysTask.kt @@ -17,14 +17,13 @@ package im.vector.matrix.android.internal.crypto.tasks import im.vector.matrix.android.api.failure.Failure -import im.vector.matrix.android.internal.auth.registration.RegistrationFlowResponse +import im.vector.matrix.android.api.failure.toRegistrationFlowResponse import im.vector.matrix.android.internal.crypto.api.CryptoApi import im.vector.matrix.android.internal.crypto.model.CryptoCrossSigningKey import im.vector.matrix.android.internal.crypto.model.rest.KeysQueryResponse import im.vector.matrix.android.internal.crypto.model.rest.UploadSigningKeysBody import im.vector.matrix.android.internal.crypto.model.rest.UserPasswordAuth import im.vector.matrix.android.internal.crypto.model.toRest -import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task import org.greenrobot.eventbus.EventBus @@ -65,37 +64,25 @@ internal class DefaultUploadSigningKeysTask @Inject constructor( } return } catch (throwable: Throwable) { - if (throwable is Failure.OtherServerError - && throwable.httpCode == 401 + val registrationFlowResponse = throwable.toRegistrationFlowResponse() + if (registrationFlowResponse != null && params.userPasswordAuth != null /* Avoid infinite loop */ && params.userPasswordAuth.session.isNullOrEmpty() ) { - try { - MoshiProvider.providesMoshi() - .adapter(RegistrationFlowResponse::class.java) - .fromJson(throwable.errorBody) - } catch (e: Exception) { - null - }?.let { - // Retry with authentication - try { - val req = executeRequest(eventBus) { - apiCall = cryptoApi.uploadSigningKeys( - uploadQuery.copy(auth = params.userPasswordAuth.copy(session = it.session)) - ) - } - if (req.failures?.isNotEmpty() == true) { - throw UploadSigningKeys(req.failures) - } - return - } catch (failure: Throwable) { - throw failure - } + // Retry with authentication + val req = executeRequest(eventBus) { + apiCall = cryptoApi.uploadSigningKeys( + uploadQuery.copy(auth = params.userPasswordAuth.copy(session = registrationFlowResponse.session)) + ) } + if (req.failures?.isNotEmpty() == true) { + throw UploadSigningKeys(req.failures) + } + } else { + // Other error + throw throwable } - // Other error - throw throwable } } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/account/ChangePasswordTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/account/ChangePasswordTask.kt index 6400253d9f..60cf92e5d1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/account/ChangePasswordTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/account/ChangePasswordTask.kt @@ -16,9 +16,7 @@ package im.vector.matrix.android.internal.session.account -import im.vector.matrix.android.api.failure.Failure -import im.vector.matrix.android.internal.auth.registration.RegistrationFlowResponse -import im.vector.matrix.android.internal.di.MoshiProvider +import im.vector.matrix.android.api.failure.toRegistrationFlowResponse import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task @@ -45,31 +43,20 @@ internal class DefaultChangePasswordTask @Inject constructor( apiCall = accountAPI.changePassword(changePasswordParams) } } catch (throwable: Throwable) { - if (throwable is Failure.OtherServerError - && throwable.httpCode == 401 + val registrationFlowResponse = throwable.toRegistrationFlowResponse() + + if (registrationFlowResponse != null /* Avoid infinite loop */ && changePasswordParams.auth?.session == null) { - try { - MoshiProvider.providesMoshi() - .adapter(RegistrationFlowResponse::class.java) - .fromJson(throwable.errorBody) - } catch (e: Exception) { - null - }?.let { - // Retry with authentication - try { - executeRequest(eventBus) { - apiCall = accountAPI.changePassword( - changePasswordParams.copy(auth = changePasswordParams.auth?.copy(session = it.session)) - ) - } - return - } catch (failure: Throwable) { - throw failure - } + // Retry with authentication + executeRequest(eventBus) { + apiCall = accountAPI.changePassword( + changePasswordParams.copy(auth = changePasswordParams.auth?.copy(session = registrationFlowResponse.session)) + ) } + } else { + throw throwable } - throw throwable } } } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapCrossSigningTask.kt b/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapCrossSigningTask.kt index 75ddb737f4..b70902631a 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapCrossSigningTask.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapCrossSigningTask.kt @@ -18,6 +18,7 @@ package im.vector.riotx.features.crypto.recover import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.failure.MatrixError +import im.vector.matrix.android.api.failure.toRegistrationFlowResponse import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.crypto.crosssigning.KEYBACKUP_SECRET_SSSS_NAME import im.vector.matrix.android.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME @@ -28,13 +29,11 @@ import im.vector.matrix.android.api.session.securestorage.SharedSecretStorageSer import im.vector.matrix.android.api.session.securestorage.SsssKeyCreationInfo import im.vector.matrix.android.api.session.securestorage.SsssKeySpec import im.vector.matrix.android.internal.auth.data.LoginFlowTypes -import im.vector.matrix.android.internal.auth.registration.RegistrationFlowResponse import im.vector.matrix.android.internal.crypto.crosssigning.toBase64NoPadding import im.vector.matrix.android.internal.crypto.keysbackup.model.MegolmBackupCreationInfo import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersion import im.vector.matrix.android.internal.crypto.keysbackup.util.extractCurveKeyFromRecoveryKey import im.vector.matrix.android.internal.crypto.model.rest.UserPasswordAuth -import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.util.awaitCallback import im.vector.riotx.R import im.vector.riotx.core.platform.ViewModelTask @@ -230,15 +229,10 @@ class BootstrapCrossSigningTask @Inject constructor( private fun handleInitializeXSigningError(failure: Throwable): BootstrapResult { if (failure is Failure.ServerError && failure.error.code == MatrixError.M_FORBIDDEN) { return BootstrapResult.InvalidPasswordError(failure.error) - } else if (failure is Failure.OtherServerError && failure.httpCode == 401) { - try { - MoshiProvider.providesMoshi() - .adapter(RegistrationFlowResponse::class.java) - .fromJson(failure.errorBody) - } catch (e: Exception) { - null - }?.let { flowResponse -> - if (flowResponse.flows?.any { it.stages?.contains(LoginFlowTypes.PASSWORD) == true } != true) { + } else { + val registrationFlowResponse = failure.toRegistrationFlowResponse() + if (registrationFlowResponse != null) { + if (registrationFlowResponse.flows?.any { it.stages?.contains(LoginFlowTypes.PASSWORD) == true } != true) { // can't do this from here return BootstrapResult.UnsupportedAuthFlow() } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningSettingsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningSettingsViewModel.kt index f18e0b3cc7..24fc1bfdf8 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningSettingsViewModel.kt @@ -22,14 +22,12 @@ import com.airbnb.mvrx.ViewModelContext import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.failure.Failure +import im.vector.matrix.android.api.failure.toRegistrationFlowResponse import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.crypto.crosssigning.MXCrossSigningInfo import im.vector.matrix.android.internal.auth.data.LoginFlowTypes -import im.vector.matrix.android.internal.auth.registration.RegistrationFlowResponse import im.vector.matrix.android.internal.crypto.crosssigning.isVerified import im.vector.matrix.android.internal.crypto.model.rest.UserPasswordAuth -import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.rx.rx import im.vector.riotx.core.extensions.exhaustive import im.vector.riotx.core.platform.VectorViewModel @@ -113,35 +111,26 @@ class CrossSigningSettingsViewModel @AssistedInject constructor(@Assisted privat override fun onFailure(failure: Throwable) { _pendingSession = null - if (failure is Failure.OtherServerError && failure.httpCode == 401) { - try { - MoshiProvider.providesMoshi() - .adapter(RegistrationFlowResponse::class.java) - .fromJson(failure.errorBody) - } catch (e: Exception) { - null - }?.let { flowResponse -> - // Retry with authentication - if (flowResponse.flows?.any { it.stages?.contains(LoginFlowTypes.PASSWORD) == true } == true) { - _pendingSession = flowResponse.session ?: "" - _viewEvents.post(CrossSigningSettingsViewEvents.RequestPassword) - return - } else { - // can't do this from here - _viewEvents.post(CrossSigningSettingsViewEvents.Failure(Throwable("You cannot do that from mobile"))) + val registrationFlowResponse = failure.toRegistrationFlowResponse() + if (registrationFlowResponse != null) { + // Retry with authentication + if (registrationFlowResponse.flows?.any { it.stages?.contains(LoginFlowTypes.PASSWORD) == true } == true) { + _pendingSession = registrationFlowResponse.session ?: "" + _viewEvents.post(CrossSigningSettingsViewEvents.RequestPassword) + } else { + // can't do this from here + _viewEvents.post(CrossSigningSettingsViewEvents.Failure(Throwable("You cannot do that from mobile"))) - setState { - copy(isUploadingKeys = false) - } - return + setState { + copy(isUploadingKeys = false) } } - } + } else { + _viewEvents.post(CrossSigningSettingsViewEvents.Failure(failure)) - _viewEvents.post(CrossSigningSettingsViewEvents.Failure(failure)) - - setState { - copy(isUploadingKeys = false) + setState { + copy(isUploadingKeys = false) + } } } }) From b1e1b4a7dc2db3e5f22173bd4c4036147d3a0244 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 24 Apr 2020 18:48:22 +0200 Subject: [PATCH 7/7] Remove "Reset keys" developer action --- .../CrossSigningEpoxyController.kt | 38 ------------------- .../CrossSigningSettingsFragment.kt | 10 ----- 2 files changed, 48 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningEpoxyController.kt b/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningEpoxyController.kt index a4b9190c51..fff177f43d 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningEpoxyController.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningEpoxyController.kt @@ -37,7 +37,6 @@ class CrossSigningEpoxyController @Inject constructor( interface InteractionListener { fun onInitializeCrossSigningKeys() - fun onResetCrossSigningKeys() fun verifySession() } @@ -51,18 +50,6 @@ class CrossSigningEpoxyController @Inject constructor( titleIconResourceId(R.drawable.ic_shield_trusted) title(stringProvider.getString(R.string.encryption_information_dg_xsigning_complete)) } - if (vectorPreferences.developerMode() && !data.isUploadingKeys) { - bottomSheetVerificationActionItem { - id("resetkeys") - title(stringProvider.getString(R.string.reset_cross_signing)) - titleColor(colorProvider.getColor(R.color.riotx_destructive_accent)) - iconRes(R.drawable.ic_arrow_right) - iconColor(colorProvider.getColor(R.color.riotx_destructive_accent)) - listener { - interactionListener?.onResetCrossSigningKeys() - } - } - } } else if (data.xSigningKeysAreTrusted) { genericItem { id("trusted") @@ -70,19 +57,6 @@ class CrossSigningEpoxyController @Inject constructor( title(stringProvider.getString(R.string.encryption_information_dg_xsigning_trusted)) } if (!data.isUploadingKeys) { - if (vectorPreferences.developerMode()) { - bottomSheetVerificationActionItem { - id("resetkeys") - title(stringProvider.getString(R.string.reset_cross_signing)) - titleColor(colorProvider.getColor(R.color.riotx_destructive_accent)) - iconRes(R.drawable.ic_arrow_right) - iconColor(colorProvider.getColor(R.color.riotx_destructive_accent)) - listener { - interactionListener?.onResetCrossSigningKeys() - } - } - } - bottomSheetVerificationActionItem { id("verify") title(stringProvider.getString(R.string.complete_security)) @@ -110,18 +84,6 @@ class CrossSigningEpoxyController @Inject constructor( interactionListener?.verifySession() } } - if (vectorPreferences.developerMode()) { - bottomSheetVerificationActionItem { - id("resetkeys") - title(stringProvider.getString(R.string.reset_cross_signing)) - titleColor(colorProvider.getColor(R.color.riotx_destructive_accent)) - iconRes(R.drawable.ic_arrow_right) - iconColor(colorProvider.getColor(R.color.riotx_destructive_accent)) - listener { - interactionListener?.onResetCrossSigningKeys() - } - } - } } else { genericItem { id("not") diff --git a/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningSettingsFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningSettingsFragment.kt index 76835211cb..1f81fd7c7b 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningSettingsFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/crosssigning/CrossSigningSettingsFragment.kt @@ -101,14 +101,4 @@ class CrossSigningSettingsFragment @Inject constructor( override fun verifySession() { viewModel.handle(CrossSigningAction.VerifySession) } - - override fun onResetCrossSigningKeys() { - AlertDialog.Builder(requireContext()) - .setTitle(R.string.dialog_title_confirmation) - .setMessage(R.string.are_you_sure) - .setPositiveButton(R.string.ok) { _, _ -> - viewModel.handle(CrossSigningAction.InitializeCrossSigning) - } - .show() - } }