Security settings: Add an option to reset the secure backup

It will overwrite the existing one if any
This commit is contained in:
manuroe
2021-06-16 09:53:31 +02:00
parent 5e2d75a2fb
commit 40c5841b9b
13 changed files with 77 additions and 11 deletions

View File

@@ -27,6 +27,7 @@ final class SecretsSetupRecoveryKeyViewModel: SecretsSetupRecoveryKeyViewModelTy
private let recoveryService: MXRecoveryService
private let passphrase: String?
private let passphraseOnly: Bool
private let allowOverwrite: Bool
// MARK: Public
@@ -35,10 +36,11 @@ final class SecretsSetupRecoveryKeyViewModel: SecretsSetupRecoveryKeyViewModelTy
// MARK: - Setup
init(recoveryService: MXRecoveryService, passphrase: String?, passphraseOnly: Bool) {
init(recoveryService: MXRecoveryService, passphrase: String?, passphraseOnly: Bool, allowOverwrite: Bool = false) {
self.recoveryService = recoveryService
self.passphrase = passphrase
self.passphraseOnly = passphraseOnly
self.allowOverwrite = allowOverwrite
}
// MARK: - Public
@@ -61,6 +63,16 @@ final class SecretsSetupRecoveryKeyViewModel: SecretsSetupRecoveryKeyViewModelTy
private func createSecureKey() {
self.update(viewState: .loading)
if allowOverwrite && self.recoveryService.hasRecovery() {
MXLog.debug("[SecretsSetupRecoveryKeyViewModel] createSecureKey: Overwrite existing secure backup")
self.recoveryService.deleteRecovery(withDeleteServicesBackups: true) {
self.createSecureKey()
} failure: { error in
self.update(viewState: .error(error))
}
return
}
self.recoveryService.createRecovery(forSecrets: nil, withPassphrase: self.passphrase, createServicesBackups: true, success: { secretStorageKeyCreationInfo in
self.update(viewState: .recoveryCreated(secretStorageKeyCreationInfo.recoveryKey))