mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Some cleanup
This commit is contained in:
parent
e976100f1a
commit
ad9873c565
6 changed files with 47 additions and 44 deletions
|
@ -245,7 +245,7 @@ interface Session :
|
||||||
|
|
||||||
val sharedSecretStorageService: SharedSecretStorageService
|
val sharedSecretStorageService: SharedSecretStorageService
|
||||||
|
|
||||||
fun getUIASsoFallbackUrl(authenticationSessionId: String): String
|
fun getUiaSsoFallbackUrl(authenticationSessionId: String): String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maintenance API, allows to print outs info on DB size to logcat
|
* Maintenance API, allows to print outs info on DB size to logcat
|
||||||
|
|
|
@ -36,3 +36,6 @@ internal const val SSO_REDIRECT_PATH = "/_matrix/client/r0/login/sso/redirect"
|
||||||
internal const val MSC2858_SSO_REDIRECT_PATH = "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect"
|
internal const val MSC2858_SSO_REDIRECT_PATH = "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect"
|
||||||
|
|
||||||
internal const val SSO_REDIRECT_URL_PARAM = "redirectUrl"
|
internal const val SSO_REDIRECT_URL_PARAM = "redirectUrl"
|
||||||
|
|
||||||
|
// Ref: https://matrix.org/docs/spec/client_server/r0.6.1#single-sign-on
|
||||||
|
internal const val SSO_UIA_FALLBACK_PATH = "/_matrix/client/r0/auth/m.login.sso/fallback/web"
|
||||||
|
|
|
@ -52,6 +52,8 @@ import org.matrix.android.sdk.api.session.terms.TermsService
|
||||||
import org.matrix.android.sdk.api.session.typing.TypingUsersTracker
|
import org.matrix.android.sdk.api.session.typing.TypingUsersTracker
|
||||||
import org.matrix.android.sdk.api.session.user.UserService
|
import org.matrix.android.sdk.api.session.user.UserService
|
||||||
import org.matrix.android.sdk.api.session.widgets.WidgetService
|
import org.matrix.android.sdk.api.session.widgets.WidgetService
|
||||||
|
import org.matrix.android.sdk.api.util.appendParamToUrl
|
||||||
|
import org.matrix.android.sdk.internal.auth.SSO_UIA_FALLBACK_PATH
|
||||||
import org.matrix.android.sdk.internal.auth.SessionParamsStore
|
import org.matrix.android.sdk.internal.auth.SessionParamsStore
|
||||||
import org.matrix.android.sdk.internal.crypto.DefaultCryptoService
|
import org.matrix.android.sdk.internal.crypto.DefaultCryptoService
|
||||||
import org.matrix.android.sdk.internal.database.tools.RealmDebugTools
|
import org.matrix.android.sdk.internal.database.tools.RealmDebugTools
|
||||||
|
@ -273,16 +275,15 @@ internal class DefaultSession @Inject constructor(
|
||||||
return "$myUserId - ${sessionParams.deviceId}"
|
return "$myUserId - ${sessionParams.deviceId}"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUIASsoFallbackUrl(authenticationSessionId: String): String {
|
override fun getUiaSsoFallbackUrl(authenticationSessionId: String): String {
|
||||||
val hsBas = sessionParams.homeServerConnectionConfig
|
val hsBas = sessionParams.homeServerConnectionConfig
|
||||||
.homeServerUri
|
.homeServerUri
|
||||||
.toString()
|
.toString()
|
||||||
.trim { it == '/' }
|
.trim { it == '/' }
|
||||||
return buildString {
|
return buildString {
|
||||||
append(hsBas)
|
append(hsBas)
|
||||||
append("/_matrix/client/r0/auth/m.login.sso/fallback/web")
|
append(SSO_UIA_FALLBACK_PATH)
|
||||||
append("?session=")
|
appendParamToUrl("session", authenticationSessionId)
|
||||||
append(authenticationSessionId)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ class ReAuthViewModel @AssistedInject constructor(
|
||||||
ReAuthActions.StartSSOFallback -> {
|
ReAuthActions.StartSSOFallback -> {
|
||||||
if (state.flowType == LoginFlowTypes.SSO) {
|
if (state.flowType == LoginFlowTypes.SSO) {
|
||||||
setState { copy(ssoFallbackPageWasShown = true) }
|
setState { copy(ssoFallbackPageWasShown = true) }
|
||||||
val ssoURL = session.getUIASsoFallbackUrl(initialState.session ?: "")
|
val ssoURL = session.getUiaSsoFallbackUrl(initialState.session ?: "")
|
||||||
_viewEvents.post(ReAuthEvents.OpenSsoURl(ssoURL))
|
_viewEvents.post(ReAuthEvents.OpenSsoURl(ssoURL))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,13 +70,12 @@ class BootstrapReAuthFragment @Inject constructor(
|
||||||
return@withState
|
return@withState
|
||||||
}
|
}
|
||||||
val failure = state.step.failure
|
val failure = state.step.failure
|
||||||
|
views.reAuthFailureText.setTextOrHide(failure)
|
||||||
if (failure == null) {
|
if (failure == null) {
|
||||||
views.reAuthFailureText.setTextOrHide(null)
|
|
||||||
views.waitingProgress.isVisible = true
|
views.waitingProgress.isVisible = true
|
||||||
views.bootstrapCancelButton.isVisible = false
|
views.bootstrapCancelButton.isVisible = false
|
||||||
views.bootstrapRetryButton.isVisible = false
|
views.bootstrapRetryButton.isVisible = false
|
||||||
} else {
|
} else {
|
||||||
views.reAuthFailureText.setTextOrHide(failure)
|
|
||||||
views.waitingProgress.isVisible = false
|
views.waitingProgress.isVisible = false
|
||||||
views.bootstrapCancelButton.isVisible = true
|
views.bootstrapCancelButton.isVisible = true
|
||||||
views.bootstrapRetryButton.isVisible = true
|
views.bootstrapRetryButton.isVisible = true
|
||||||
|
|
|
@ -86,7 +86,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
when (args.setUpMode) {
|
when (args.setUpMode) {
|
||||||
SetupMode.PASSPHRASE_RESET,
|
SetupMode.PASSPHRASE_RESET,
|
||||||
SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET,
|
SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET,
|
||||||
SetupMode.HARD_RESET -> {
|
SetupMode.HARD_RESET -> {
|
||||||
setState {
|
setState {
|
||||||
copy(step = BootstrapStep.FirstForm(keyBackUpExist = false, reset = true))
|
copy(step = BootstrapStep.FirstForm(keyBackUpExist = false, reset = true))
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
copy(step = BootstrapStep.AccountReAuth())
|
copy(step = BootstrapStep.AccountReAuth())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetupMode.NORMAL -> {
|
SetupMode.NORMAL -> {
|
||||||
// need to check if user have an existing keybackup
|
// need to check if user have an existing keybackup
|
||||||
setState {
|
setState {
|
||||||
copy(step = BootstrapStep.CheckingMigration)
|
copy(step = BootstrapStep.CheckingMigration)
|
||||||
|
@ -149,8 +149,8 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
override fun handle(action: BootstrapActions) = withState { state ->
|
override fun handle(action: BootstrapActions) = withState { state ->
|
||||||
when (action) {
|
when (action) {
|
||||||
is BootstrapActions.GoBack -> queryBack()
|
is BootstrapActions.GoBack -> queryBack()
|
||||||
BootstrapActions.TogglePasswordVisibility -> {
|
BootstrapActions.TogglePasswordVisibility -> {
|
||||||
when (state.step) {
|
when (state.step) {
|
||||||
is BootstrapStep.SetupPassphrase -> {
|
is BootstrapStep.SetupPassphrase -> {
|
||||||
setState {
|
setState {
|
||||||
|
@ -173,13 +173,13 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
else -> Unit
|
else -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BootstrapActions.StartKeyBackupMigration -> {
|
BootstrapActions.StartKeyBackupMigration -> {
|
||||||
handleStartMigratingKeyBackup()
|
handleStartMigratingKeyBackup()
|
||||||
}
|
}
|
||||||
is BootstrapActions.Start -> {
|
is BootstrapActions.Start -> {
|
||||||
handleStart(action)
|
handleStart(action)
|
||||||
}
|
}
|
||||||
is BootstrapActions.UpdateCandidatePassphrase -> {
|
is BootstrapActions.UpdateCandidatePassphrase -> {
|
||||||
val strength = zxcvbn.measure(action.pass)
|
val strength = zxcvbn.measure(action.pass)
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
|
@ -188,7 +188,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BootstrapActions.GoToConfirmPassphrase -> {
|
is BootstrapActions.GoToConfirmPassphrase -> {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
passphrase = action.passphrase,
|
passphrase = action.passphrase,
|
||||||
|
@ -205,7 +205,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BootstrapActions.DoInitialize -> {
|
is BootstrapActions.DoInitialize -> {
|
||||||
if (state.passphrase == state.passphraseRepeat) {
|
if (state.passphrase == state.passphraseRepeat) {
|
||||||
startInitializeFlow(state)
|
startInitializeFlow(state)
|
||||||
} else {
|
} else {
|
||||||
|
@ -216,42 +216,42 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BootstrapActions.DoInitializeGeneratedKey -> {
|
is BootstrapActions.DoInitializeGeneratedKey -> {
|
||||||
startInitializeFlow(state)
|
startInitializeFlow(state)
|
||||||
}
|
}
|
||||||
BootstrapActions.RecoveryKeySaved -> {
|
BootstrapActions.RecoveryKeySaved -> {
|
||||||
_viewEvents.post(BootstrapViewEvents.RecoveryKeySaved)
|
_viewEvents.post(BootstrapViewEvents.RecoveryKeySaved)
|
||||||
setState {
|
setState {
|
||||||
copy(step = BootstrapStep.SaveRecoveryKey(true))
|
copy(step = BootstrapStep.SaveRecoveryKey(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BootstrapActions.Completed -> {
|
BootstrapActions.Completed -> {
|
||||||
_viewEvents.post(BootstrapViewEvents.Dismiss(true))
|
_viewEvents.post(BootstrapViewEvents.Dismiss(true))
|
||||||
}
|
}
|
||||||
BootstrapActions.GoToCompleted -> {
|
BootstrapActions.GoToCompleted -> {
|
||||||
setState {
|
setState {
|
||||||
copy(step = BootstrapStep.DoneSuccess)
|
copy(step = BootstrapStep.DoneSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BootstrapActions.SaveReqQueryStarted -> {
|
BootstrapActions.SaveReqQueryStarted -> {
|
||||||
setState {
|
setState {
|
||||||
copy(recoverySaveFileProcess = Loading())
|
copy(recoverySaveFileProcess = Loading())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BootstrapActions.SaveKeyToUri -> {
|
is BootstrapActions.SaveKeyToUri -> {
|
||||||
saveRecoveryKeyToUri(action.os)
|
saveRecoveryKeyToUri(action.os)
|
||||||
}
|
}
|
||||||
BootstrapActions.SaveReqFailed -> {
|
BootstrapActions.SaveReqFailed -> {
|
||||||
setState {
|
setState {
|
||||||
copy(recoverySaveFileProcess = Uninitialized)
|
copy(recoverySaveFileProcess = Uninitialized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BootstrapActions.GoToEnterAccountPassword -> {
|
BootstrapActions.GoToEnterAccountPassword -> {
|
||||||
setState {
|
setState {
|
||||||
copy(step = BootstrapStep.AccountReAuth())
|
copy(step = BootstrapStep.AccountReAuth())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BootstrapActions.HandleForgotBackupPassphrase -> {
|
BootstrapActions.HandleForgotBackupPassphrase -> {
|
||||||
if (state.step is BootstrapStep.GetBackupSecretPassForMigration) {
|
if (state.step is BootstrapStep.GetBackupSecretPassForMigration) {
|
||||||
setState {
|
setState {
|
||||||
copy(step = BootstrapStep.GetBackupSecretPassForMigration(state.step.isPasswordVisible, true))
|
copy(step = BootstrapStep.GetBackupSecretPassForMigration(state.step.isPasswordVisible, true))
|
||||||
|
@ -261,16 +261,16 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
// is BootstrapActions.ReAuth -> {
|
// is BootstrapActions.ReAuth -> {
|
||||||
// startInitializeFlow(action.pass)
|
// startInitializeFlow(action.pass)
|
||||||
// }
|
// }
|
||||||
is BootstrapActions.DoMigrateWithPassphrase -> {
|
is BootstrapActions.DoMigrateWithPassphrase -> {
|
||||||
startMigrationFlow(state.step, action.passphrase, null)
|
startMigrationFlow(state.step, action.passphrase, null)
|
||||||
}
|
}
|
||||||
is BootstrapActions.DoMigrateWithRecoveryKey -> {
|
is BootstrapActions.DoMigrateWithRecoveryKey -> {
|
||||||
startMigrationFlow(state.step, null, action.recoveryKey)
|
startMigrationFlow(state.step, null, action.recoveryKey)
|
||||||
}
|
}
|
||||||
BootstrapActions.SsoAuthDone -> {
|
BootstrapActions.SsoAuthDone -> {
|
||||||
uiaContinuation?.resume(DefaultBaseAuth(session = pendingAuth?.session ?: ""))
|
uiaContinuation?.resume(DefaultBaseAuth(session = pendingAuth?.session ?: ""))
|
||||||
}
|
}
|
||||||
is BootstrapActions.PasswordAuthDone -> {
|
is BootstrapActions.PasswordAuthDone -> {
|
||||||
val decryptedPass = session.loadSecureSecret<String>(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS)
|
val decryptedPass = session.loadSecureSecret<String>(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS)
|
||||||
uiaContinuation?.resume(
|
uiaContinuation?.resume(
|
||||||
UserPasswordAuth(
|
UserPasswordAuth(
|
||||||
|
@ -280,7 +280,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
BootstrapActions.ReAuthCancelled -> {
|
BootstrapActions.ReAuthCancelled -> {
|
||||||
setState {
|
setState {
|
||||||
copy(step = BootstrapStep.AccountReAuth(stringProvider.getString(R.string.authentication_error)))
|
copy(step = BootstrapStep.AccountReAuth(stringProvider.getString(R.string.authentication_error)))
|
||||||
}
|
}
|
||||||
|
@ -410,7 +410,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
_viewEvents.post(BootstrapViewEvents.RequestReAuth(flowResponse, errCode))
|
_viewEvents.post(BootstrapViewEvents.RequestReAuth(flowResponse, errCode))
|
||||||
}
|
}
|
||||||
LoginFlowTypes.SSO -> {
|
LoginFlowTypes.SSO -> {
|
||||||
pendingAuth = DefaultBaseAuth(flowResponse.session)
|
pendingAuth = DefaultBaseAuth(flowResponse.session)
|
||||||
uiaContinuation = promise
|
uiaContinuation = promise
|
||||||
setState {
|
setState {
|
||||||
|
@ -441,7 +441,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
is BootstrapResult.SuccessCrossSigningOnly -> {
|
is BootstrapResult.SuccessCrossSigningOnly -> {
|
||||||
_viewEvents.post(BootstrapViewEvents.Dismiss(true))
|
_viewEvents.post(BootstrapViewEvents.Dismiss(true))
|
||||||
}
|
}
|
||||||
is BootstrapResult.Success -> {
|
is BootstrapResult.Success -> {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
recoveryKeyCreationInfo = bootstrapResult.keyInfo,
|
recoveryKeyCreationInfo = bootstrapResult.keyInfo,
|
||||||
|
@ -452,7 +452,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BootstrapResult.InvalidPasswordError -> {
|
is BootstrapResult.InvalidPasswordError -> {
|
||||||
// it's a bad password / auth
|
// it's a bad password / auth
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
|
@ -460,7 +460,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BootstrapResult.Failure -> {
|
is BootstrapResult.Failure -> {
|
||||||
if (bootstrapResult is BootstrapResult.GenericError
|
if (bootstrapResult is BootstrapResult.GenericError
|
||||||
&& bootstrapResult.failure is Failure.OtherServerError
|
&& bootstrapResult.failure is Failure.OtherServerError
|
||||||
&& bootstrapResult.failure.httpCode == 401) {
|
&& bootstrapResult.failure.httpCode == 401) {
|
||||||
|
@ -510,7 +510,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BootstrapStep.SetupPassphrase -> {
|
is BootstrapStep.SetupPassphrase -> {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist),
|
step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist),
|
||||||
|
@ -520,7 +520,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BootstrapStep.ConfirmPassphrase -> {
|
is BootstrapStep.ConfirmPassphrase -> {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
step = BootstrapStep.SetupPassphrase(
|
step = BootstrapStep.SetupPassphrase(
|
||||||
|
@ -529,19 +529,19 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is BootstrapStep.AccountReAuth -> {
|
is BootstrapStep.AccountReAuth -> {
|
||||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap(state.passphrase != null))
|
_viewEvents.post(BootstrapViewEvents.SkipBootstrap(state.passphrase != null))
|
||||||
}
|
}
|
||||||
BootstrapStep.Initializing -> {
|
BootstrapStep.Initializing -> {
|
||||||
// do we let you cancel from here?
|
// do we let you cancel from here?
|
||||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap(state.passphrase != null))
|
_viewEvents.post(BootstrapViewEvents.SkipBootstrap(state.passphrase != null))
|
||||||
}
|
}
|
||||||
is BootstrapStep.SaveRecoveryKey,
|
is BootstrapStep.SaveRecoveryKey,
|
||||||
BootstrapStep.DoneSuccess -> {
|
BootstrapStep.DoneSuccess -> {
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
BootstrapStep.CheckingMigration -> Unit
|
BootstrapStep.CheckingMigration -> Unit
|
||||||
is BootstrapStep.FirstForm -> {
|
is BootstrapStep.FirstForm -> {
|
||||||
_viewEvents.post(
|
_viewEvents.post(
|
||||||
when (args.setUpMode) {
|
when (args.setUpMode) {
|
||||||
SetupMode.CROSS_SIGNING_ONLY,
|
SetupMode.CROSS_SIGNING_ONLY,
|
||||||
|
@ -550,7 +550,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is BootstrapStep.GetBackupSecretForMigration -> {
|
is BootstrapStep.GetBackupSecretForMigration -> {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist),
|
step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist),
|
||||||
|
@ -568,7 +568,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
||||||
private fun BackupToQuadSMigrationTask.Result.Failure.toHumanReadable(): String {
|
private fun BackupToQuadSMigrationTask.Result.Failure.toHumanReadable(): String {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is BackupToQuadSMigrationTask.Result.InvalidRecoverySecret -> stringProvider.getString(R.string.keys_backup_passphrase_error_decrypt)
|
is BackupToQuadSMigrationTask.Result.InvalidRecoverySecret -> stringProvider.getString(R.string.keys_backup_passphrase_error_decrypt)
|
||||||
is BackupToQuadSMigrationTask.Result.ErrorFailure -> errorFormatter.toHumanReadable(throwable)
|
is BackupToQuadSMigrationTask.Result.ErrorFailure -> errorFormatter.toHumanReadable(throwable)
|
||||||
// is BackupToQuadSMigrationTask.Result.NoKeyBackupVersion,
|
// is BackupToQuadSMigrationTask.Result.NoKeyBackupVersion,
|
||||||
// is BackupToQuadSMigrationTask.Result.IllegalParams,
|
// is BackupToQuadSMigrationTask.Result.IllegalParams,
|
||||||
else -> stringProvider.getString(R.string.unexpected_error)
|
else -> stringProvider.getString(R.string.unexpected_error)
|
||||||
|
|
Loading…
Reference in a new issue