Crypto identity reset (#3107)

* Add EncryptionReset password entry screen

* Expose client proxy identity reset method

* Update the IdentityConfirmationScreen to the latest designs

* Replace the old recovery key reset screen with a new EncryptionReset one

* Fixes #3102 - Add support for resetting the user's whole crypto identity

* Address review comments

* Bump the SDK to v1.0.30
This commit is contained in:
Stefan Ceriu
2024-08-05 09:35:18 +03:00
committed by GitHub
parent 276bbb09f2
commit 63e0b94764
58 changed files with 1217 additions and 319 deletions
@@ -1,56 +0,0 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// periphery:ignore:all - this is just a resetKey remove this comment once generating the final file
import Combine
import SwiftUI
enum ResetRecoveryKeyScreenCoordinatorAction {
case cancel
}
final class ResetRecoveryKeyScreenCoordinator: CoordinatorProtocol {
private let viewModel: ResetRecoveryKeyScreenViewModelProtocol
private var cancellables = Set<AnyCancellable>()
private let actionsSubject: PassthroughSubject<ResetRecoveryKeyScreenCoordinatorAction, Never> = .init()
var actionsPublisher: AnyPublisher<ResetRecoveryKeyScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init() {
viewModel = ResetRecoveryKeyScreenViewModel()
}
func start() {
viewModel.actionsPublisher.sink { [weak self] action in
MXLog.info("Coordinator: received view model action: \(action)")
guard let self else { return }
switch action {
case .cancel:
self.actionsSubject.send(.cancel)
}
}
.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(ResetRecoveryKeyScreen(context: viewModel.context))
}
}
@@ -1,46 +0,0 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
enum ResetRecoveryKeyScreenViewModelAction {
case cancel
}
struct ResetRecoveryKeyScreenViewState: BindableState {
private let listItem3AttributedText = {
let boldPlaceholder = "{bold}"
var finalString = AttributedString(L10n.screenCreateNewRecoveryKeyListItem3(boldPlaceholder))
var boldString = AttributedString(L10n.screenCreateNewRecoveryKeyListItem3ResetAll)
boldString.bold()
finalString.replace(boldPlaceholder, with: boldString)
return finalString
}()
var listItems: [AttributedString] {
[
AttributedString(L10n.screenCreateNewRecoveryKeyListItem1(InfoPlistReader.main.productionAppName)),
AttributedString(L10n.screenCreateNewRecoveryKeyListItem2),
listItem3AttributedText,
AttributedString(L10n.screenCreateNewRecoveryKeyListItem4),
AttributedString(L10n.screenCreateNewRecoveryKeyListItem5)
]
}
}
enum ResetRecoveryKeyScreenViewAction {
case cancel
}
@@ -1,41 +0,0 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Combine
import SwiftUI
typealias ResetRecoveryKeyScreenViewModelType = StateStoreViewModel<ResetRecoveryKeyScreenViewState, ResetRecoveryKeyScreenViewAction>
class ResetRecoveryKeyScreenViewModel: ResetRecoveryKeyScreenViewModelType, ResetRecoveryKeyScreenViewModelProtocol {
private let actionsSubject: PassthroughSubject<ResetRecoveryKeyScreenViewModelAction, Never> = .init()
var actionsPublisher: AnyPublisher<ResetRecoveryKeyScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init() {
super.init(initialViewState: ResetRecoveryKeyScreenViewState())
}
// MARK: - Public
override func process(viewAction: ResetRecoveryKeyScreenViewAction) {
switch viewAction {
case .cancel:
// We might also need to display first an alert and do a logOut API call in some cases
actionsSubject.send(.cancel)
}
}
}
@@ -1,23 +0,0 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Combine
@MainActor
protocol ResetRecoveryKeyScreenViewModelProtocol {
var actionsPublisher: AnyPublisher<ResetRecoveryKeyScreenViewModelAction, Never> { get }
var context: ResetRecoveryKeyScreenViewModelType.Context { get }
}
@@ -1,75 +0,0 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Compound
import SwiftUI
struct ResetRecoveryKeyScreen: View {
@ObservedObject var context: ResetRecoveryKeyScreenViewModel.Context
var body: some View {
NavigationStack {
FullscreenDialog {
mainContent
} bottomContent: {
EmptyView()
}
.toolbar { toolbar }
.toolbar(.visible, for: .navigationBar)
.background()
.backgroundStyle(.compound.bgSubtleSecondary)
.interactiveDismissDisabled()
}
}
private var mainContent: some View {
VStack(spacing: 40) {
header
SFNumberedListView(items: context.viewState.listItems)
}
}
private var header: some View {
VStack(spacing: 16) {
HeroImage(icon: \.computer, style: .subtle)
Text(L10n.screenCreateNewRecoveryKeyTitle)
.foregroundColor(.compound.textPrimary)
.font(.compound.headingMDBold)
.multilineTextAlignment(.center)
}
}
@ToolbarContentBuilder
private var toolbar: some ToolbarContent {
ToolbarItem(placement: .cancellationAction) {
Button(L10n.actionCancel) {
context.send(viewAction: .cancel)
}
}
}
}
// MARK: - Previews
struct ResetRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = ResetRecoveryKeyScreenViewModel()
static var previews: some View {
NavigationStack {
ResetRecoveryKeyScreen(context: viewModel.context)
}
}
}
@@ -28,7 +28,7 @@ enum SecureBackupRecoveryKeyScreenCoordinatorAction {
case recoverySetUp
case recoveryChanged
case recoveryFixed
case showResetKeyInfo
case resetEncryption
}
final class SecureBackupRecoveryKeyScreenCoordinator: CoordinatorProtocol {
@@ -65,8 +65,8 @@ final class SecureBackupRecoveryKeyScreenCoordinator: CoordinatorProtocol {
case .unknown:
fatalError()
}
case .showResetKeyInfo:
self.actionsSubject.send(.showResetKeyInfo)
case .resetEncryption:
self.actionsSubject.send(.resetEncryption)
}
}
.store(in: &cancellables)
@@ -19,7 +19,7 @@ import Foundation
enum SecureBackupRecoveryKeyScreenViewModelAction {
case done(mode: SecureBackupRecoveryKeyScreenViewMode)
case cancel
case showResetKeyInfo
case resetEncryption
}
enum SecureBackupRecoveryKeyScreenViewMode {
@@ -90,7 +90,7 @@ enum SecureBackupRecoveryKeyScreenViewAction {
case copyKey
case keySaved
case confirmKey
case resetKey
case resetEncryption
case done
case cancel
}
@@ -40,13 +40,12 @@ class SecureBackupRecoveryKeyScreenViewModel: SecureBackupRecoveryKeyScreenViewM
secureBackupController.recoveryState
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak userIndicatorController] state in
let loadingIndicatorIdentifier = "SecureBackupRecoveryKeyScreenLoading"
.sink(receiveValue: { [weak self] state in
switch state {
case .settingUp:
userIndicatorController?.submitIndicator(.init(id: loadingIndicatorIdentifier, type: .modal, title: L10n.commonLoading, persistent: true))
self?.showLoadingIndicator()
default:
userIndicatorController?.retractIndicatorWithId(loadingIndicatorIdentifier)
self?.hideLoadingIndicator()
}
})
.store(in: &cancellables)
@@ -67,6 +66,8 @@ class SecureBackupRecoveryKeyScreenViewModel: SecureBackupRecoveryKeyScreenViewM
MXLog.error("Failed generating recovery key with error: \(error)")
state.bindings.alertInfo = .init(id: .init())
}
hideLoadingIndicator()
}
case .copyKey:
UIPasteboard.general.string = state.recoveryKey
@@ -76,8 +77,7 @@ class SecureBackupRecoveryKeyScreenViewModel: SecureBackupRecoveryKeyScreenViewM
state.doneButtonEnabled = true
case .confirmKey:
Task {
let loadingIndicatorIdentifier = "SecureBackupRecoveryKeyScreen"
userIndicatorController.submitIndicator(.init(id: loadingIndicatorIdentifier, type: .modal, title: L10n.commonLoading, persistent: true))
showLoadingIndicator()
switch await secureBackupController.confirmRecoveryKey(state.bindings.confirmationRecoveryKey) {
case .success:
@@ -87,7 +87,7 @@ class SecureBackupRecoveryKeyScreenViewModel: SecureBackupRecoveryKeyScreenViewM
state.bindings.alertInfo = .init(id: .init())
}
userIndicatorController.retractIndicatorWithId(loadingIndicatorIdentifier)
hideLoadingIndicator()
}
case .cancel:
actionsSubject.send(.cancel)
@@ -100,10 +100,23 @@ class SecureBackupRecoveryKeyScreenViewModel: SecureBackupRecoveryKeyScreenViewM
guard let self else { return }
actionsSubject.send(.done(mode: context.viewState.mode))
}))
case .resetKey:
actionsSubject.send(.showResetKeyInfo)
case .resetEncryption:
actionsSubject.send(.resetEncryption)
}
}
private static let loadingIndicatorIdentifier = "\(SecureBackupRecoveryKeyScreenViewModel.self)-Loading"
private func showLoadingIndicator() {
userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
type: .modal,
title: L10n.commonLoading,
persistent: true))
}
private func hideLoadingIndicator() {
userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
}
}
extension SecureBackupRecoveryState {
@@ -101,7 +101,7 @@ struct SecureBackupRecoveryKeyScreen: View {
.disabled(context.confirmationRecoveryKey.isEmpty)
Button {
context.send(viewAction: .resetKey)
context.send(viewAction: .resetEncryption)
} label: {
Text(L10n.screenIdentityConfirmationCreateNewRecoveryKey)
.padding(.vertical, 14)
@@ -205,9 +205,6 @@ struct SecureBackupRecoveryKeyScreen: View {
.font(.compound.bodySMSemibold)
SecureField(L10n.screenRecoveryKeyConfirmKeyPlaceholder, text: $context.confirmationRecoveryKey)
.textContentType(.password) // Not ideal but stops random suggestions
.autocapitalization(.none)
.disableAutocorrection(true)
.frame(maxWidth: .infinity)
.padding()
.background(Color.compound.bgSubtleSecondaryLevel0)
@@ -19,20 +19,30 @@ import SwiftUI
struct SecureBackupScreenCoordinatorParameters {
let appSettings: AppSettings
let secureBackupController: SecureBackupControllerProtocol
let clientProxy: ClientProxyProtocol
weak var navigationStackCoordinator: NavigationStackCoordinator?
let userIndicatorController: UserIndicatorControllerProtocol
}
enum SecureBackupScreenCoordinatorAction {
case requestOIDCAuthorisation(URL)
}
final class SecureBackupScreenCoordinator: CoordinatorProtocol {
private let parameters: SecureBackupScreenCoordinatorParameters
private var viewModel: SecureBackupScreenViewModelProtocol
private var cancellables = Set<AnyCancellable>()
private let actionsSubject: PassthroughSubject<SecureBackupScreenCoordinatorAction, Never> = .init()
var actions: AnyPublisher<SecureBackupScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(parameters: SecureBackupScreenCoordinatorParameters) {
self.parameters = parameters
viewModel = SecureBackupScreenViewModel(secureBackupController: parameters.secureBackupController,
viewModel = SecureBackupScreenViewModel(secureBackupController: parameters.clientProxy.secureBackupController,
userIndicatorController: parameters.userIndicatorController,
chatBackupDetailsURL: parameters.appSettings.chatBackupDetailsURL)
}
@@ -43,9 +53,9 @@ final class SecureBackupScreenCoordinator: CoordinatorProtocol {
switch action {
case .recoveryKey:
let navigationStackCoordinator = NavigationStackCoordinator()
let recoveryNavigationStackCoordinator = NavigationStackCoordinator()
let recoveryKeyCoordinator = SecureBackupRecoveryKeyScreenCoordinator(parameters: .init(secureBackupController: parameters.secureBackupController,
let recoveryKeyCoordinator = SecureBackupRecoveryKeyScreenCoordinator(parameters: .init(secureBackupController: parameters.clientProxy.secureBackupController,
userIndicatorController: parameters.userIndicatorController,
isModallyPresented: true))
@@ -63,19 +73,19 @@ final class SecureBackupScreenCoordinator: CoordinatorProtocol {
case .recoveryFixed:
showSuccessIndicator(title: L10n.screenRecoveryKeyConfirmSuccess)
parameters.navigationStackCoordinator?.setSheetCoordinator(nil)
case .showResetKeyInfo:
showResetRecoveryKeyScreen(navigationStackCoordinator: navigationStackCoordinator)
case .resetEncryption:
showEncryptionReset(recoveryNavigationStackCoordinator: recoveryNavigationStackCoordinator)
}
}
.store(in: &cancellables)
navigationStackCoordinator.setRootCoordinator(recoveryKeyCoordinator, animated: true)
recoveryNavigationStackCoordinator.setRootCoordinator(recoveryKeyCoordinator, animated: true)
parameters.navigationStackCoordinator?.setSheetCoordinator(navigationStackCoordinator)
parameters.navigationStackCoordinator?.setSheetCoordinator(recoveryNavigationStackCoordinator)
case .keyBackup:
let navigationStackCoordinator = NavigationStackCoordinator()
let keyBackupCoordinator = SecureBackupKeyBackupScreenCoordinator(parameters: .init(secureBackupController: parameters.secureBackupController,
let keyBackupCoordinator = SecureBackupKeyBackupScreenCoordinator(parameters: .init(secureBackupController: parameters.clientProxy.secureBackupController,
userIndicatorController: parameters.userIndicatorController))
keyBackupCoordinator.actions.sink { [weak self] action in
@@ -108,15 +118,30 @@ final class SecureBackupScreenCoordinator: CoordinatorProtocol {
persistent: false))
}
private func showResetRecoveryKeyScreen(navigationStackCoordinator: NavigationStackCoordinator) {
let coordinator = ResetRecoveryKeyScreenCoordinator()
coordinator.actionsPublisher.sink { action in
private func showEncryptionReset(recoveryNavigationStackCoordinator: NavigationStackCoordinator) {
let resetNavigationStackCoordinator = NavigationStackCoordinator()
let coordinator = EncryptionResetScreenCoordinator(parameters: .init(clientProxy: parameters.clientProxy,
navigationStackCoordinator: resetNavigationStackCoordinator,
userIndicatorController: parameters.userIndicatorController))
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .cancel:
navigationStackCoordinator.setSheetCoordinator(nil)
recoveryNavigationStackCoordinator.setSheetCoordinator(nil)
case .requestOIDCAuthorisation(let url):
actionsSubject.send(.requestOIDCAuthorisation(url))
case .resetFinished:
parameters.navigationStackCoordinator?.setSheetCoordinator(nil) // Dismiss the recovery screen
recoveryNavigationStackCoordinator.setSheetCoordinator(nil)
}
}
.store(in: &cancellables)
navigationStackCoordinator.setSheetCoordinator(coordinator)
resetNavigationStackCoordinator.setRootCoordinator(coordinator)
recoveryNavigationStackCoordinator.setSheetCoordinator(resetNavigationStackCoordinator)
}
}