Add generate key option
This commit is contained in:
parent
c27264761d
commit
45c5626267
|
@ -195,7 +195,8 @@ class MainActivity : VectorBaseActivity() {
|
|||
// We have a session.
|
||||
// Check it can be opened
|
||||
if (sessionHolder.getActiveSession().isOpenable) {
|
||||
HomeActivity.newIntent(this)
|
||||
// DO NOT COMMIT
|
||||
HomeActivity.newIntent(this, accountCreation = true)
|
||||
} else {
|
||||
// The token is still invalid
|
||||
SoftLogoutActivity.newIntent(this)
|
||||
|
|
|
@ -30,6 +30,7 @@ sealed class BootstrapActions : VectorViewModelAction {
|
|||
object GoToEnterAccountPassword : BootstrapActions()
|
||||
|
||||
data class DoInitialize(val passphrase: String, val auth: UserPasswordAuth? = null) : BootstrapActions()
|
||||
data class DoInitializeGeneratedKey(val auth: UserPasswordAuth? = null) : BootstrapActions()
|
||||
object TogglePasswordVisibility : BootstrapActions()
|
||||
data class UpdateCandidatePassphrase(val pass: String) : BootstrapActions()
|
||||
data class UpdateConfirmCandidatePassphrase(val pass: String) : BootstrapActions()
|
||||
|
|
|
@ -55,30 +55,35 @@ class BootstrapBottomSheet : VectorBaseBottomSheetDialogFragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
viewModel.observeViewEvents { event ->
|
||||
when (event) {
|
||||
is BootstrapViewEvents.Dismiss -> dismiss()
|
||||
is BootstrapViewEvents.ModalError -> {
|
||||
is BootstrapViewEvents.Dismiss -> dismiss()
|
||||
is BootstrapViewEvents.ModalError -> {
|
||||
AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.dialog_title_error)
|
||||
.setMessage(event.error)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
}
|
||||
BootstrapViewEvents.RecoveryKeySaved -> {
|
||||
BootstrapViewEvents.RecoveryKeySaved -> {
|
||||
KeepItSafeDialog().show(requireActivity())
|
||||
}
|
||||
BootstrapViewEvents.SkipBootstrap -> {
|
||||
promptSkip()
|
||||
is BootstrapViewEvents.SkipBootstrap -> {
|
||||
promptSkip(event.genKeyOption)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun promptSkip() {
|
||||
AlertDialog.Builder(requireActivity())
|
||||
private fun promptSkip(genKeyOption: Boolean) {
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setTitle(R.string.are_you_sure)
|
||||
.setMessage(R.string.bootstrap_skip_text)
|
||||
.setMessage(if (genKeyOption) R.string.bootstrap_skip_text else R.string.bootstrap_skip_text_no_gen_key)
|
||||
.setPositiveButton(R.string._continue, null)
|
||||
.setNeutralButton(R.string.generate_message_key) { _, _ ->
|
||||
.apply {
|
||||
if (genKeyOption) {
|
||||
setNeutralButton(R.string.generate_message_key) { _, _ ->
|
||||
viewModel.handle(BootstrapActions.DoInitializeGeneratedKey())
|
||||
}
|
||||
}
|
||||
}
|
||||
.setNegativeButton(R.string.skip) { _, _ ->
|
||||
dismiss()
|
||||
|
@ -118,7 +123,7 @@ class BootstrapBottomSheet : VectorBaseBottomSheetDialogFragment() {
|
|||
bootstrapTitleText.text = getString(R.string.confirm_recovery_passphrase, getString(R.string.recovery_passphrase))
|
||||
showFragment(BootstrapConfirmPassphraseFragment::class, Bundle())
|
||||
}
|
||||
is BootstrapStep.AccountPassword -> {
|
||||
is BootstrapStep.AccountPassword -> {
|
||||
bootstrapIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_user))
|
||||
bootstrapTitleText.text = getString(R.string.account_password)
|
||||
showFragment(BootstrapAccountPasswordFragment::class, Bundle())
|
||||
|
|
|
@ -64,7 +64,7 @@ interface BootstrapProgressListener {
|
|||
data class Params(
|
||||
val userPasswordAuth: UserPasswordAuth? = null,
|
||||
val progressListener: BootstrapProgressListener? = null,
|
||||
val passphrase: String
|
||||
val passphrase: String?
|
||||
)
|
||||
|
||||
class BootstrapCrossSigningTask @Inject constructor(
|
||||
|
@ -100,14 +100,23 @@ class BootstrapCrossSigningTask @Inject constructor(
|
|||
params.progressListener?.onProgress(WaitingViewData(stringProvider.getString(R.string.bootstrap_crosssigning_progress_pbkdf2), isIndeterminate = true))
|
||||
try {
|
||||
keyInfo = awaitCallback {
|
||||
ssssService.generateKeyWithPassphrase(
|
||||
UUID.randomUUID().toString(),
|
||||
"ssss_key",
|
||||
params.passphrase,
|
||||
EmptyKeySigner(),
|
||||
null,
|
||||
it
|
||||
)
|
||||
params.passphrase?.let { passphrase ->
|
||||
ssssService.generateKeyWithPassphrase(
|
||||
UUID.randomUUID().toString(),
|
||||
"ssss_key",
|
||||
passphrase,
|
||||
EmptyKeySigner(),
|
||||
null,
|
||||
it
|
||||
)
|
||||
} ?: kotlin.run {
|
||||
ssssService.generateKey(
|
||||
UUID.randomUUID().toString(),
|
||||
"ssss_key",
|
||||
EmptyKeySigner(),
|
||||
it
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (failure: Failure) {
|
||||
return BootstrapResult.FailedToCreateSSSSKey(failure)
|
||||
|
|
|
@ -151,6 +151,20 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
is BootstrapActions.DoInitializeGeneratedKey -> {
|
||||
val auth = action.auth ?: reAuthHelper.rememberedAuth()
|
||||
if (auth == null) {
|
||||
setState {
|
||||
copy(
|
||||
passphrase = null,
|
||||
passphraseRepeat = null,
|
||||
step = BootstrapStep.AccountPassword(false)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
startInitializeFlow(action.auth)
|
||||
}
|
||||
}
|
||||
BootstrapActions.RecoveryKeySaved -> {
|
||||
_viewEvents.post(BootstrapViewEvents.RecoveryKeySaved)
|
||||
setState {
|
||||
|
@ -237,7 +251,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
|||
bootstrapTask.invoke(this, Params(
|
||||
userPasswordAuth = auth ?: reAuthHelper.rememberedAuth(),
|
||||
progressListener = progressListener,
|
||||
passphrase = state.passphrase!!
|
||||
passphrase = state.passphrase
|
||||
)) {
|
||||
when (it) {
|
||||
is BootstrapResult.Success -> {
|
||||
|
@ -297,7 +311,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
|||
when (state.step) {
|
||||
is BootstrapStep.SetupPassphrase -> {
|
||||
// do we let you cancel from here?
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap)
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap())
|
||||
}
|
||||
is BootstrapStep.ConfirmPassphrase -> {
|
||||
setState {
|
||||
|
@ -309,11 +323,11 @@ class BootstrapSharedViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
is BootstrapStep.AccountPassword -> {
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap)
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap(state.passphrase != null))
|
||||
}
|
||||
BootstrapStep.Initializing -> {
|
||||
// do we let you cancel from here?
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap)
|
||||
_viewEvents.post(BootstrapViewEvents.SkipBootstrap(state.passphrase != null))
|
||||
}
|
||||
is BootstrapStep.SaveRecoveryKey,
|
||||
BootstrapStep.DoneSuccess -> {
|
||||
|
|
|
@ -22,5 +22,5 @@ sealed class BootstrapViewEvents : VectorViewEvents {
|
|||
object Dismiss : BootstrapViewEvents()
|
||||
data class ModalError(val error: String) : BootstrapViewEvents()
|
||||
object RecoveryKeySaved: BootstrapViewEvents()
|
||||
object SkipBootstrap: BootstrapViewEvents()
|
||||
data class SkipBootstrap(val genKeyOption: Boolean = true): BootstrapViewEvents()
|
||||
}
|
||||
|
|
|
@ -84,6 +84,8 @@
|
|||
<string name="auth_flow_not_supported">You cannot do that from mobile</string>
|
||||
|
||||
<string name="bootstrap_skip_text">Setting a Message Password lets you secure & unlock encrypted messages and trust.\n\nIf you don’t want to set a Message Password, generate a Message Key instead.</string>
|
||||
<string name="bootstrap_skip_text_no_gen_key">Setting a Message Password lets you secure & unlock encrypted messages and trust.</string>
|
||||
|
||||
<!-- END Strings added by Valere -->
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue