mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Add generate key option
This commit is contained in:
parent
c27264761d
commit
45c5626267
7 changed files with 57 additions and 25 deletions
|
@ -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()
|
||||
|
|
|
@ -66,19 +66,24 @@ class BootstrapBottomSheet : VectorBaseBottomSheetDialogFragment() {
|
|||
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()
|
||||
|
|
|
@ -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 {
|
||||
params.passphrase?.let { passphrase ->
|
||||
ssssService.generateKeyWithPassphrase(
|
||||
UUID.randomUUID().toString(),
|
||||
"ssss_key",
|
||||
params.passphrase,
|
||||
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 a new issue