Add generate key option

This commit is contained in:
Valere 2020-04-02 18:30:43 +02:00
parent c27264761d
commit 45c5626267
7 changed files with 57 additions and 25 deletions

View file

@ -195,7 +195,8 @@ class MainActivity : VectorBaseActivity() {
// We have a session. // We have a session.
// Check it can be opened // Check it can be opened
if (sessionHolder.getActiveSession().isOpenable) { if (sessionHolder.getActiveSession().isOpenable) {
HomeActivity.newIntent(this) // DO NOT COMMIT
HomeActivity.newIntent(this, accountCreation = true)
} else { } else {
// The token is still invalid // The token is still invalid
SoftLogoutActivity.newIntent(this) SoftLogoutActivity.newIntent(this)

View file

@ -30,6 +30,7 @@ sealed class BootstrapActions : VectorViewModelAction {
object GoToEnterAccountPassword : BootstrapActions() object GoToEnterAccountPassword : BootstrapActions()
data class DoInitialize(val passphrase: String, val auth: UserPasswordAuth? = null) : BootstrapActions() data class DoInitialize(val passphrase: String, val auth: UserPasswordAuth? = null) : BootstrapActions()
data class DoInitializeGeneratedKey(val auth: UserPasswordAuth? = null) : BootstrapActions()
object TogglePasswordVisibility : BootstrapActions() object TogglePasswordVisibility : BootstrapActions()
data class UpdateCandidatePassphrase(val pass: String) : BootstrapActions() data class UpdateCandidatePassphrase(val pass: String) : BootstrapActions()
data class UpdateConfirmCandidatePassphrase(val pass: String) : BootstrapActions() data class UpdateConfirmCandidatePassphrase(val pass: String) : BootstrapActions()

View file

@ -66,19 +66,24 @@ class BootstrapBottomSheet : VectorBaseBottomSheetDialogFragment() {
BootstrapViewEvents.RecoveryKeySaved -> { BootstrapViewEvents.RecoveryKeySaved -> {
KeepItSafeDialog().show(requireActivity()) KeepItSafeDialog().show(requireActivity())
} }
BootstrapViewEvents.SkipBootstrap -> { is BootstrapViewEvents.SkipBootstrap -> {
promptSkip() promptSkip(event.genKeyOption)
} }
} }
} }
} }
private fun promptSkip() { private fun promptSkip(genKeyOption: Boolean) {
AlertDialog.Builder(requireActivity()) AlertDialog.Builder(requireContext())
.setTitle(R.string.are_you_sure) .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) .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) { _, _ -> .setNegativeButton(R.string.skip) { _, _ ->
dismiss() dismiss()

View file

@ -64,7 +64,7 @@ interface BootstrapProgressListener {
data class Params( data class Params(
val userPasswordAuth: UserPasswordAuth? = null, val userPasswordAuth: UserPasswordAuth? = null,
val progressListener: BootstrapProgressListener? = null, val progressListener: BootstrapProgressListener? = null,
val passphrase: String val passphrase: String?
) )
class BootstrapCrossSigningTask @Inject constructor( 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)) params.progressListener?.onProgress(WaitingViewData(stringProvider.getString(R.string.bootstrap_crosssigning_progress_pbkdf2), isIndeterminate = true))
try { try {
keyInfo = awaitCallback { keyInfo = awaitCallback {
params.passphrase?.let { passphrase ->
ssssService.generateKeyWithPassphrase( ssssService.generateKeyWithPassphrase(
UUID.randomUUID().toString(), UUID.randomUUID().toString(),
"ssss_key", "ssss_key",
params.passphrase, passphrase,
EmptyKeySigner(), EmptyKeySigner(),
null, null,
it it
) )
} ?: kotlin.run {
ssssService.generateKey(
UUID.randomUUID().toString(),
"ssss_key",
EmptyKeySigner(),
it
)
}
} }
} catch (failure: Failure) { } catch (failure: Failure) {
return BootstrapResult.FailedToCreateSSSSKey(failure) return BootstrapResult.FailedToCreateSSSSKey(failure)

View file

@ -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 -> { BootstrapActions.RecoveryKeySaved -> {
_viewEvents.post(BootstrapViewEvents.RecoveryKeySaved) _viewEvents.post(BootstrapViewEvents.RecoveryKeySaved)
setState { setState {
@ -237,7 +251,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
bootstrapTask.invoke(this, Params( bootstrapTask.invoke(this, Params(
userPasswordAuth = auth ?: reAuthHelper.rememberedAuth(), userPasswordAuth = auth ?: reAuthHelper.rememberedAuth(),
progressListener = progressListener, progressListener = progressListener,
passphrase = state.passphrase!! passphrase = state.passphrase
)) { )) {
when (it) { when (it) {
is BootstrapResult.Success -> { is BootstrapResult.Success -> {
@ -297,7 +311,7 @@ class BootstrapSharedViewModel @AssistedInject constructor(
when (state.step) { when (state.step) {
is BootstrapStep.SetupPassphrase -> { is BootstrapStep.SetupPassphrase -> {
// do we let you cancel from here? // do we let you cancel from here?
_viewEvents.post(BootstrapViewEvents.SkipBootstrap) _viewEvents.post(BootstrapViewEvents.SkipBootstrap())
} }
is BootstrapStep.ConfirmPassphrase -> { is BootstrapStep.ConfirmPassphrase -> {
setState { setState {
@ -309,11 +323,11 @@ class BootstrapSharedViewModel @AssistedInject constructor(
} }
} }
is BootstrapStep.AccountPassword -> { is BootstrapStep.AccountPassword -> {
_viewEvents.post(BootstrapViewEvents.SkipBootstrap) _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) _viewEvents.post(BootstrapViewEvents.SkipBootstrap(state.passphrase != null))
} }
is BootstrapStep.SaveRecoveryKey, is BootstrapStep.SaveRecoveryKey,
BootstrapStep.DoneSuccess -> { BootstrapStep.DoneSuccess -> {

View file

@ -22,5 +22,5 @@ sealed class BootstrapViewEvents : VectorViewEvents {
object Dismiss : BootstrapViewEvents() object Dismiss : BootstrapViewEvents()
data class ModalError(val error: String) : BootstrapViewEvents() data class ModalError(val error: String) : BootstrapViewEvents()
object RecoveryKeySaved: BootstrapViewEvents() object RecoveryKeySaved: BootstrapViewEvents()
object SkipBootstrap: BootstrapViewEvents() data class SkipBootstrap(val genKeyOption: Boolean = true): BootstrapViewEvents()
} }

View file

@ -84,6 +84,8 @@
<string name="auth_flow_not_supported">You cannot do that from mobile</string> <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 &amp; unlock encrypted messages and trust.\n\nIf you dont want to set a Message Password, generate a Message Key instead.</string> <string name="bootstrap_skip_text">Setting a Message Password lets you secure &amp; unlock encrypted messages and trust.\n\nIf you dont 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 &amp; unlock encrypted messages and trust.</string>
<!-- END Strings added by Valere --> <!-- END Strings added by Valere -->