Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support backup key lost in 4S migration #8013

Closed
wants to merge 3 commits into from

Conversation

BillCarsonFr
Copy link
Member

@BillCarsonFr BillCarsonFr commented Jan 26, 2023

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Adds a button if you forgot your backup pass during 4S migration.
Also added a config option that allows to discard the existing backup and setup 4S with a fresh one (default false).

Motivation and context

When setting up 4S for the first time on an account with an existing key backup (Migration from old accounts pre 4S), there is no option when the user did forget his backup passphrase/key.
It's particularly annoying if secure backup is required, because you will be locked out the app (the backup pass is required to setup 4S.

This state of no 4S with existing backup can also happens if a user is deactivated then reactivated, created an issue on synapse to track that matrix-org/synapse#14923

Screenshots / GIFs

New forgot button
|image|image|

If existing backup ignored user will directly start the setup flow
image

Tests

  • Step 1
  • Step 2
  • Step ...

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@Farsss07
Copy link

FB_IMG_1672609708361

@BillCarsonFr BillCarsonFr requested review from a team and mnaturel and removed request for a team January 26, 2023 22:29
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

16.7% 16.7% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@mnaturel mnaturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I have just added small remarks to improve code readability. And I didn't test it since I am not sure how to do it.

@@ -60,6 +62,11 @@ import java.io.OutputStream
import kotlin.coroutines.Continuation
import kotlin.coroutines.resumeWithException

enum class BackupMigrationStrategy {
IgnoreExistingBackup,
ProposeToConvertTo4S
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a trailing comma to follow the convention on the project.

// }
BootstrapActions.MigrationHandleKeyLost -> {
// delete the backups as key is lost
session.coroutineScope.launch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to encapsulate this logic into a dedicated method such as handleMigrationKeyLost().

session.coroutineScope.launch {
clearAllExistingBackups()
}
doesKeyBackupExist = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this part should also be inside the coroutine so that we are sure to have a consistent state. Let's say there is an error when clearing the existing backups for instance, then we should not update the state and the doesKeyBackupExist field to false I guess?

@@ -275,6 +313,22 @@ class BootstrapSharedViewModel @AssistedInject constructor(
}
}

private suspend fun clearAllExistingBackups() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this code into a dedicated use case ClearAllExistingBackupsUseCase?

doesKeyBackupExist = true
isBackupCreatedFromPassphrase = keyVersion.getAuthDataAsMegolmBackupAuthData()?.privateKeySalt != null
setState {
copy(step = BootstrapStep.FirstForm(keyBackUpExist = doesKeyBackupExist, methods = this.secureBackupMethod))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not make big difference but since doesKeyBackupExist is mutable should we pass true to keyBackUpExist when updating the state instead?

@bmarty
Copy link
Member

bmarty commented May 11, 2023

According to @BillCarsonFr , this PR can be closed, Synapse issue is fixed: matrix-org/synapse#14923

@bmarty bmarty closed this May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants