diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-08-03 19:46:28 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-08-03 19:46:28 +0200 |
| commit | 0bc7b0d1d74cd8ab710d63a3a363eb79887bca6b (patch) | |
| tree | e84f7d9407f3255a775b95fb4138b5d88496e2fa | |
| parent | 6194006e59fb3c90a61981a18160ba50dddf4d73 (diff) | |
| download | mullvadvpn-0bc7b0d1d74cd8ab710d63a3a363eb79887bca6b.tar.xz mullvadvpn-0bc7b0d1d74cd8ab710d63a3a363eb79887bca6b.zip | |
Delete WG keys view controller
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 4 | ||||
| -rw-r--r-- | ios/MullvadVPN/SettingsDataSource.swift | 20 | ||||
| -rw-r--r-- | ios/MullvadVPN/SettingsNavigationController.swift | 4 | ||||
| -rw-r--r-- | ios/MullvadVPN/SettingsViewController.swift | 2 | ||||
| -rw-r--r-- | ios/MullvadVPN/WireguardKeysViewController.swift | 415 |
5 files changed, 1 insertions, 444 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index d8b9c9093a..84e1b45cf0 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -158,7 +158,6 @@ 5872D6E8286304DE00DB5F4E /* TermsOfService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5872D6E7286304DE00DB5F4E /* TermsOfService.swift */; }; 587425C12299833500CA2045 /* RootContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587425C02299833500CA2045 /* RootContainerViewController.swift */; }; 5875960A26F371FC00BF6711 /* Tunnel+Messaging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5875960926F371FC00BF6711 /* Tunnel+Messaging.swift */; }; - 5877153023981F7B001F8237 /* WireguardKeysViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5877152F23981F7B001F8237 /* WireguardKeysViewController.swift */; }; 5877D70F282137E8002FCFC7 /* SettingsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FF2C02281BDE02009EF542 /* SettingsManager.swift */; }; 58781CC922AE7CA8009B9D8E /* RelayConstraints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58781CC822AE7CA8009B9D8E /* RelayConstraints.swift */; }; 58781CCE22AE8918009B9D8E /* RelayConstraints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58781CC822AE7CA8009B9D8E /* RelayConstraints.swift */; }; @@ -464,7 +463,6 @@ 5872D6E7286304DE00DB5F4E /* TermsOfService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TermsOfService.swift; sourceTree = "<group>"; }; 587425C02299833500CA2045 /* RootContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootContainerViewController.swift; sourceTree = "<group>"; }; 5875960926F371FC00BF6711 /* Tunnel+Messaging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Tunnel+Messaging.swift"; sourceTree = "<group>"; }; - 5877152F23981F7B001F8237 /* WireguardKeysViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WireguardKeysViewController.swift; sourceTree = "<group>"; }; 58781CC822AE7CA8009B9D8E /* RelayConstraints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayConstraints.swift; sourceTree = "<group>"; }; 58781CD422AFBA39009B9D8E /* RelaySelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelaySelector.swift; sourceTree = "<group>"; }; 587A01FB23F1F0BE00B68763 /* SimulatorTunnelProviderHost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorTunnelProviderHost.swift; sourceTree = "<group>"; }; @@ -973,7 +971,6 @@ 585CA70E25F8C44600B47C62 /* UIMetrics.swift */, 58FD5BF12424F7D700112C88 /* UserInterfaceInteractionRestriction.swift */, 58F7CA872692E34000FC59FD /* WireguardKeysContentView.swift */, - 5877152F23981F7B001F8237 /* WireguardKeysViewController.swift */, ); path = MullvadVPN; sourceTree = "<group>"; @@ -1357,7 +1354,6 @@ 588D2FE3248AC27F00E313F7 /* AsyncOperation.swift in Sources */, 5820675026E6514100655B05 /* HTTP.swift in Sources */, 584D26C2270C8542004EA533 /* SettingsStaticTextFooterView.swift in Sources */, - 5877153023981F7B001F8237 /* WireguardKeysViewController.swift in Sources */, 587B7536266528A200DEF7E9 /* NotificationManager.swift in Sources */, 5820EDA9288FE064006BF4E4 /* DeviceManagementInteractor.swift in Sources */, 58FB865A26EA214400F188BC /* RelayCacheObserver.swift in Sources */, diff --git a/ios/MullvadVPN/SettingsDataSource.swift b/ios/MullvadVPN/SettingsDataSource.swift index 1a9caf3389..cb457b042a 100644 --- a/ios/MullvadVPN/SettingsDataSource.swift +++ b/ios/MullvadVPN/SettingsDataSource.swift @@ -43,7 +43,6 @@ class SettingsDataSource: NSObject, TunnelObserver, UITableViewDataSource, UITab enum Item: String { case account case preferences - case wireguardKey case version case problemReport case faq @@ -93,7 +92,7 @@ class SettingsDataSource: NSObject, TunnelObserver, UITableViewDataSource, UITab if TunnelManager.shared.deviceState.isLoggedIn { newSnapshot.appendSections([.main]) - newSnapshot.appendItems([.account, .preferences, .wireguardKey], in: .main) + newSnapshot.appendItems([.account, .preferences], in: .main) } newSnapshot.appendSections([.version, .problemReport]) @@ -153,23 +152,6 @@ class SettingsDataSource: NSObject, TunnelObserver, UITableViewDataSource, UITab return cell - case .wireguardKey: - let cell = tableView.dequeueReusableCell( - withIdentifier: CellReuseIdentifiers.basicCell.rawValue, - for: indexPath - ) as! SettingsCell - cell.titleLabel.text = NSLocalizedString( - "WIREGUARD_KEY_CELL_LABEL", - tableName: "Settings", - value: "WireGuard key", - comment: "" - ) - cell.detailTitleLabel.text = nil - cell.accessibilityIdentifier = "WireGuardKeyCell" - cell.disclosureType = .chevron - - return cell - case .version: let cell = tableView.dequeueReusableCell( withIdentifier: CellReuseIdentifiers.basicCell.rawValue, diff --git a/ios/MullvadVPN/SettingsNavigationController.swift b/ios/MullvadVPN/SettingsNavigationController.swift index 6611759c48..cc59a05c4e 100644 --- a/ios/MullvadVPN/SettingsNavigationController.swift +++ b/ios/MullvadVPN/SettingsNavigationController.swift @@ -12,7 +12,6 @@ import UIKit enum SettingsNavigationRoute { case account case preferences - case wireguardKeys case problemReport } @@ -102,9 +101,6 @@ class SettingsNavigationController: CustomNavigationController, SettingsViewCont case .preferences: return PreferencesViewController() - case .wireguardKeys: - return WireguardKeysViewController() - case .problemReport: return ProblemReportViewController() } diff --git a/ios/MullvadVPN/SettingsViewController.swift b/ios/MullvadVPN/SettingsViewController.swift index 6fa1bbf045..6601c65fdd 100644 --- a/ios/MullvadVPN/SettingsViewController.swift +++ b/ios/MullvadVPN/SettingsViewController.swift @@ -103,8 +103,6 @@ extension SettingsDataSource.Item { return .account case .preferences: return .preferences - case .wireguardKey: - return .wireguardKeys case .version: return nil case .problemReport: diff --git a/ios/MullvadVPN/WireguardKeysViewController.swift b/ios/MullvadVPN/WireguardKeysViewController.swift deleted file mode 100644 index 0a5f751058..0000000000 --- a/ios/MullvadVPN/WireguardKeysViewController.swift +++ /dev/null @@ -1,415 +0,0 @@ -// -// WireguardKeysViewController.swift -// MullvadVPN -// -// Created by pronebird on 04/12/2019. -// Copyright © 2019 Mullvad VPN AB. All rights reserved. -// - -import Foundation -import Logging -import UIKit - -/// A UI refresh interval for the public key creation date (in seconds) -private let creationDateRefreshInterval = Int(60) - -/// A maximum number of characters to display out of the entire public key representation -private let displayPublicKeyMaxLength = 20 - -private enum WireguardKeysViewState { - case `default` - case verifyingKey - case verifiedKey(Bool) - case regeneratingKey - case regeneratedKey(Bool) -} - -class WireguardKeysViewController: UIViewController, TunnelObserver { - private let contentView: WireguardKeysContentView = { - let contentView = WireguardKeysContentView() - contentView.translatesAutoresizingMaskIntoConstraints = false - return contentView - }() - - private var publicKeyPeriodicUpdateTimer: DispatchSourceTimer? - private var copyToPasteboardWork: DispatchWorkItem? - private var updateDeviceTask: Cancellable? - - private let alertPresenter = AlertPresenter() - private var state: WireguardKeysViewState = .default { - didSet { - updateViewState(state) - } - } - - override var preferredStatusBarStyle: UIStatusBarStyle { - return .lightContent - } - - override func viewDidLoad() { - super.viewDidLoad() - - view.backgroundColor = .secondaryColor - - let scrollView = UIScrollView() - scrollView.translatesAutoresizingMaskIntoConstraints = false - scrollView.addSubview(contentView) - view.addSubview(scrollView) - - NSLayoutConstraint.activate([ - scrollView.topAnchor.constraint(equalTo: view.topAnchor), - scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), - scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor), - scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor), - - contentView.topAnchor.constraint(equalTo: scrollView.topAnchor), - contentView.bottomAnchor - .constraint(greaterThanOrEqualTo: scrollView.safeAreaLayoutGuide.bottomAnchor), - contentView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), - contentView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor), - contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor), - ]) - - navigationItem.title = NSLocalizedString( - "NAVIGATION_TITLE", - tableName: "WireguardKeys", - value: "WireGuard key", - comment: "" - ) - - contentView.publicKeyRowView.actionHandler = { [weak self] in - self?.copyPublicKey() - } - - contentView.regenerateKeyButton.addTarget( - self, - action: #selector(handleRegenerateKey(_:)), - for: .touchUpInside - ) - contentView.verifyKeyButton.addTarget( - self, - action: #selector(handleVerifyKey(_:)), - for: .touchUpInside - ) - - TunnelManager.shared.addObserver(self) - updatePublicKey(deviceData: TunnelManager.shared.deviceState.deviceData, animated: false) - - startPublicKeyPeriodicUpdate() - } - - private func startPublicKeyPeriodicUpdate() { - let interval = DispatchTimeInterval.seconds(creationDateRefreshInterval) - let timerSource = DispatchSource.makeTimerSource(queue: .main) - timerSource.setEventHandler { [weak self] () in - self?.updatePublicKey( - deviceData: TunnelManager.shared.deviceState.deviceData, - animated: true - ) - } - timerSource.schedule(deadline: .now() + interval, repeating: interval) - timerSource.activate() - - publicKeyPeriodicUpdateTimer = timerSource - } - - // MARK: - TunnelObserver - - func tunnelManagerDidLoadConfiguration(_ manager: TunnelManager) { - // no-op - } - - func tunnelManager(_ manager: TunnelManager, didUpdateTunnelState tunnelState: TunnelState) { - // no-op - } - - func tunnelManager( - _ manager: TunnelManager, - didUpdateTunnelSettings tunnelSettings: TunnelSettingsV2 - ) { - // no-op - } - - func tunnelManager(_ manager: TunnelManager, didUpdateDeviceState deviceState: DeviceState) { - updatePublicKey(deviceData: deviceState.deviceData, animated: true) - } - - func tunnelManager(_ manager: TunnelManager, didFailWithError error: Error) { - // no-op - } - - // MARK: - Actions - - private func copyPublicKey() { - guard let deviceData = TunnelManager.shared.deviceState.deviceData else { return } - - UIPasteboard.general.string = deviceData.wgKeyData.privateKey.publicKey.base64Key - - setPublicKeyTitle( - string: NSLocalizedString( - "COPIED_TO_PASTEBOARD_LABEL", - tableName: "WireguardKeys", - value: "COPIED TO PASTEBOARD!", - comment: "" - ), - animated: true - ) - - let workItem = DispatchWorkItem { [weak self] in - self?.updatePublicKey( - deviceData: TunnelManager.shared.deviceState.deviceData, - animated: true - ) - } - - DispatchQueue.main.asyncAfter(wallDeadline: .now() + .seconds(3), execute: workItem) - copyToPasteboardWork?.cancel() - copyToPasteboardWork = workItem - } - - @objc private func handleRegenerateKey(_ sender: Any) { - regeneratePrivateKey() - } - - @objc private func handleVerifyKey(_ sender: Any) { - verifyKey() - } - - // MARK: - Private - - private func formatKeyGenerationElapsedTime(with creationDate: Date) -> String? { - return CustomDateComponentsFormatting.localizedString( - from: creationDate, - to: Date(), - unitsStyle: .full - ).map { formattedInterval -> String in - return String( - format: NSLocalizedString( - "KEY_GENERATED_SINCE_FORMAT", - tableName: "WireguardKeys", - value: "%@ ago", - comment: "" - ), - formattedInterval - ) - } - } - - private func updateCreationDateLabel(with creationDate: Date) { - contentView.creationRowView - .value = formatKeyGenerationElapsedTime(with: creationDate) ?? "-" - } - - private func updatePublicKey(deviceData: StoredDeviceData?, animated: Bool) { - if let wgKeyData = deviceData?.wgKeyData { - let displayKey = wgKeyData.privateKey - .publicKey - .base64Key - .prefix(displayPublicKeyMaxLength) - .appending("...") - - setPublicKeyTitle(string: displayKey, animated: animated) - updateCreationDateLabel(with: wgKeyData.creationDate) - } else { - setPublicKeyTitle(string: "-", animated: animated) - contentView.creationRowView.value = "-" - } - } - - private func updateViewState(_ state: WireguardKeysViewState) { - switch state { - case .default: - setKeyActionButtonsEnabled(true) - contentView.publicKeyRowView.status = .default - - case .verifyingKey: - setKeyActionButtonsEnabled(false) - contentView.publicKeyRowView.status = .verifying - - case let .verifiedKey(isValid): - setKeyActionButtonsEnabled(true) - contentView.publicKeyRowView.status = .verified(isValid) - announceKeyVerificationResult(isValid: isValid) - - case .regeneratingKey: - setKeyActionButtonsEnabled(false) - contentView.publicKeyRowView.status = .regenerating - - case let .regeneratedKey(success): - setKeyActionButtonsEnabled(true) - contentView.publicKeyRowView.status = .default - if success { - announceKeyRegenerated() - } - } - } - - private func setKeyActionButtonsEnabled(_ enabled: Bool) { - contentView.regenerateKeyButton.isEnabled = enabled - contentView.verifyKeyButton.isEnabled = enabled - } - - private func verifyKey() { - updateViewState(.verifyingKey) - - updateDeviceTask?.cancel() - - updateDeviceTask = TunnelManager.shared.updateDeviceData { [weak self] completion in - guard let self = self else { return } - - switch completion { - case .success: - self.updateViewState(.verifiedKey(true)) - - case let .failure(error): - if let restError = error as? REST.Error, - restError.compareErrorCode(.deviceNotFound) - { - self.updateViewState(.verifiedKey(false)) - } else { - self.showKeyVerificationFailureAlert(error) - self.updateViewState(.default) - } - - case .cancelled: - self.updateViewState(.default) - } - } - } - - private func regeneratePrivateKey() { - updateViewState(.regeneratingKey) - - _ = TunnelManager.shared.rotatePrivateKey(forceRotate: true) { [weak self] completion in - guard let self = self else { return } - - switch completion { - case .success: - self.updateViewState(.regeneratedKey(true)) - - case let .failure(error): - if let restError = error as? REST.Error, - restError.compareErrorCode(.deviceNotFound) - { - self.updateViewState(.regeneratedKey(false)) - } else { - self.showKeyRegenerationFailureAlert(error) - self.updateViewState(.default) - } - - case .cancelled: - self.updateViewState(.default) - } - } - } - - private func showKeyVerificationFailureAlert(_ error: Error) { - let errorDescription = String( - format: NSLocalizedString( - "VERIFY_KEY_FAILURE_ALERT_MESSAGE", - tableName: "WireguardKeys", - value: "Failed to verify the WireGuard key: %@", - comment: "" - ), - error.localizedDescription - ) - - let alertController = UIAlertController( - title: NSLocalizedString( - "VERIFY_KEY_FAILURE_ALERT_TITLE", - tableName: "WireguardKeys", - value: "Cannot verify the key", - comment: "" - ), - message: errorDescription, - preferredStyle: .alert - ) - - alertController.addAction( - UIAlertAction( - title: NSLocalizedString( - "VERIFY_KEY_FAILURE_ALERT_OK_ACTION", - tableName: "WireguardKeys", - value: "OK", - comment: "" - ), - style: .cancel - ) - ) - - alertPresenter.enqueue(alertController, presentingController: self) - } - - private func showKeyRegenerationFailureAlert(_ error: Error) { - let alertController = UIAlertController( - title: NSLocalizedString( - "REGENERATE_KEY_FAILURE_ALERT_TITLE", - tableName: "WireguardKeys", - value: "Cannot regenerate the key", - comment: "" - ), - message: error.localizedDescription, - preferredStyle: .alert - ) - alertController.addAction( - UIAlertAction( - title: NSLocalizedString( - "REGENERATE_KEY_FAILURE_ALERT_OK_ACTION", - tableName: "WireguardKeys", - value: "OK", - comment: "" - ), - style: .cancel - ) - ) - - alertPresenter.enqueue(alertController, presentingController: self) - } - - private func setPublicKeyTitle(string: String, animated: Bool) { - let updateTitle = { - self.contentView.publicKeyRowView.value = string - } - - if animated { - updateTitle() - } else { - UIView.performWithoutAnimation { - updateTitle() - self.contentView.publicKeyRowView.layoutIfNeeded() - } - } - } - - private func announceKeyVerificationResult(isValid: Bool) { - let announcementString: String - - if isValid { - announcementString = NSLocalizedString( - "ACCESSIBILITY_ANNOUNCEMENT_VALID_KEY", - tableName: "WireguardKeys", - value: "Key is valid.", - comment: "" - ) - } else { - announcementString = NSLocalizedString( - "ACCESSIBILITY_ANNOUNCEMENT_INVALID_KEY", - tableName: "WireguardKeys", - value: "Key is invalid.", - comment: "" - ) - } - - UIAccessibility.post(notification: .announcement, argument: announcementString) - } - - private func announceKeyRegenerated() { - let announcementString = NSLocalizedString( - "ACCESSIBILITY_ANNOUNCEMENT_REGENERATED_KEY", - tableName: "WireguardKeys", - value: "Key is regenerated.", - comment: "" - ) - UIAccessibility.post(notification: .announcement, argument: announcementString) - } -} |
