From cda050a64e910339b92061c2c8ac023a9e698b9f Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 May 2022 14:52:22 +0200 Subject: [PATCH 1/7] fix(session): add evaluateFirstRun method in AppDelegate --- IVPNClient/AppDelegate.swift | 10 ++++++++++ IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift | 1 + 2 files changed, 11 insertions(+) diff --git a/IVPNClient/AppDelegate.swift b/IVPNClient/AppDelegate.swift index d7d815519..7c107be83 100644 --- a/IVPNClient/AppDelegate.swift +++ b/IVPNClient/AppDelegate.swift @@ -45,6 +45,15 @@ class AppDelegate: UIResponder { // MARK: - Methods - + private func evaluateFirstRun() { + if UserDefaults.standard.object(forKey: UserDefaults.Key.firstInstall) == nil { + KeyChain.clearAll() + UserDefaults.clearSession() + UserDefaults.standard.set(false, forKey: UserDefaults.Key.firstInstall) + UserDefaults.standard.synchronize() + } + } + private func evaluateUITests() { // When running the application for UI Testing we need to remove all the stored data so we can start testing the clear app // It is impossible to access the KeyChain from the UI test itself as the test runs in different process @@ -191,6 +200,7 @@ extension AppDelegate: UIApplicationDelegate { createLogFiles() resetLastPingTimestamp() clearURLCache() + evaluateFirstRun() if #available(iOS 14.0, *) { DNSManager.shared.loadProfile { _ in } diff --git a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift index 365e64b8a..dff5e1077 100644 --- a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift +++ b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift @@ -73,6 +73,7 @@ extension UserDefaults { static let selectedExitServerRandom = "SelectedExitServerRandom" static let fastestServerPreferred = "FastestServerPreferred" static let fastestServerConfigured = "FastestServerConfiguredForOpenVPN" + static let firstInstall = "FirstInstall" static let secureDNS = "SecureDNS" static let serviceStatus = "ServiceStatus" static let isIPv6 = "isIPv6" From 14a48fc0011e33f7230666ad4fa58461c6ce0dd9 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 May 2022 16:19:14 +0200 Subject: [PATCH 2/7] fix(session): update evaluateFirstRun method --- IVPNClient/AppDelegate.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/IVPNClient/AppDelegate.swift b/IVPNClient/AppDelegate.swift index 7c107be83..12967710a 100644 --- a/IVPNClient/AppDelegate.swift +++ b/IVPNClient/AppDelegate.swift @@ -46,6 +46,10 @@ class AppDelegate: UIResponder { // MARK: - Methods - private func evaluateFirstRun() { + guard UIApplication.shared.isProtectedDataAvailable else { + return + } + if UserDefaults.standard.object(forKey: UserDefaults.Key.firstInstall) == nil { KeyChain.clearAll() UserDefaults.clearSession() From c129405d7b51234853fc4f97f63f72126461e4bd Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 May 2022 16:20:00 +0200 Subject: [PATCH 3/7] fix(session): set data-protection to NSFileProtectionCompleteUntilFirstUserAuthentication --- IVPNClient/IVPNClient.entitlements | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IVPNClient/IVPNClient.entitlements b/IVPNClient/IVPNClient.entitlements index acb41e1fd..7af37748d 100644 --- a/IVPNClient/IVPNClient.entitlements +++ b/IVPNClient/IVPNClient.entitlements @@ -7,7 +7,7 @@ applinks:www.ivpn.net com.apple.developer.default-data-protection - NSFileProtectionComplete + NSFileProtectionCompleteUntilFirstUserAuthentication com.apple.developer.networking.networkextension packet-tunnel-provider From 7ca244957a95591e3869e4d2df14cf755900d4f6 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 May 2022 16:23:28 +0200 Subject: [PATCH 4/7] fix(session): move evaluateFirstRun method to MainViewController --- IVPNClient/AppDelegate.swift | 14 -------------- .../Scenes/MainScreen/MainViewController.swift | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/IVPNClient/AppDelegate.swift b/IVPNClient/AppDelegate.swift index 12967710a..d7d815519 100644 --- a/IVPNClient/AppDelegate.swift +++ b/IVPNClient/AppDelegate.swift @@ -45,19 +45,6 @@ class AppDelegate: UIResponder { // MARK: - Methods - - private func evaluateFirstRun() { - guard UIApplication.shared.isProtectedDataAvailable else { - return - } - - if UserDefaults.standard.object(forKey: UserDefaults.Key.firstInstall) == nil { - KeyChain.clearAll() - UserDefaults.clearSession() - UserDefaults.standard.set(false, forKey: UserDefaults.Key.firstInstall) - UserDefaults.standard.synchronize() - } - } - private func evaluateUITests() { // When running the application for UI Testing we need to remove all the stored data so we can start testing the clear app // It is impossible to access the KeyChain from the UI test itself as the test runs in different process @@ -204,7 +191,6 @@ extension AppDelegate: UIApplicationDelegate { createLogFiles() resetLastPingTimestamp() clearURLCache() - evaluateFirstRun() if #available(iOS 14.0, *) { DNSManager.shared.loadProfile { _ in } diff --git a/IVPNClient/Scenes/MainScreen/MainViewController.swift b/IVPNClient/Scenes/MainScreen/MainViewController.swift index d81422eec..9e5cadbac 100644 --- a/IVPNClient/Scenes/MainScreen/MainViewController.swift +++ b/IVPNClient/Scenes/MainScreen/MainViewController.swift @@ -70,6 +70,7 @@ class MainViewController: UIViewController { addObservers() startServersUpdate() startVPNStatusObserver() + evaluateFirstRun() } override func viewWillAppear(_ animated: Bool) { @@ -266,4 +267,17 @@ class MainViewController: UIViewController { #endif } + private func evaluateFirstRun() { + guard UIApplication.shared.isProtectedDataAvailable else { + return + } + + if UserDefaults.standard.object(forKey: UserDefaults.Key.firstInstall) == nil { + KeyChain.clearAll() + UserDefaults.clearSession() + UserDefaults.standard.set(false, forKey: UserDefaults.Key.firstInstall) + UserDefaults.standard.synchronize() + } + } + } From a828f7ad61c5dffb7d1a38112df80711615d5be2 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 11 May 2022 16:26:18 +0200 Subject: [PATCH 5/7] fix(session): update evaluateFirstRun method --- IVPNClient/Scenes/MainScreen/MainViewController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/IVPNClient/Scenes/MainScreen/MainViewController.swift b/IVPNClient/Scenes/MainScreen/MainViewController.swift index 9e5cadbac..5846d3696 100644 --- a/IVPNClient/Scenes/MainScreen/MainViewController.swift +++ b/IVPNClient/Scenes/MainScreen/MainViewController.swift @@ -273,8 +273,9 @@ class MainViewController: UIViewController { } if UserDefaults.standard.object(forKey: UserDefaults.Key.firstInstall) == nil { - KeyChain.clearAll() - UserDefaults.clearSession() + #warning("Uncomment for the next release") + // KeyChain.clearAll() + // UserDefaults.clearSession() UserDefaults.standard.set(false, forKey: UserDefaults.Key.firstInstall) UserDefaults.standard.synchronize() } From eedd179c7d82e21779dd54902ef4ee8028395ddf Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 11 May 2022 17:06:59 +0200 Subject: [PATCH 6/7] fix(session): update evaluateFirstRun method --- IVPNClient/Scenes/MainScreen/MainViewController.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/IVPNClient/Scenes/MainScreen/MainViewController.swift b/IVPNClient/Scenes/MainScreen/MainViewController.swift index 5846d3696..59c76375f 100644 --- a/IVPNClient/Scenes/MainScreen/MainViewController.swift +++ b/IVPNClient/Scenes/MainScreen/MainViewController.swift @@ -272,10 +272,9 @@ class MainViewController: UIViewController { return } - if UserDefaults.standard.object(forKey: UserDefaults.Key.firstInstall) == nil { - #warning("Uncomment for the next release") - // KeyChain.clearAll() - // UserDefaults.clearSession() + if UserDefaults.standard.object(forKey: UserDefaults.Key.firstInstall) == nil && UserDefaults.standard.object(forKey: UserDefaults.Key.selectedServerGateway) == nil { + KeyChain.clearAll() + UserDefaults.clearSession() UserDefaults.standard.set(false, forKey: UserDefaults.Key.firstInstall) UserDefaults.standard.synchronize() } From 99013ba52f3f9b652d40d01df6a365c47276d830 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Thu, 12 May 2022 11:25:04 +0200 Subject: [PATCH 7/7] fix(session): update evaluateFirstRun method --- IVPNClient/Scenes/MainScreen/MainViewController.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/IVPNClient/Scenes/MainScreen/MainViewController.swift b/IVPNClient/Scenes/MainScreen/MainViewController.swift index 59c76375f..af70c80bc 100644 --- a/IVPNClient/Scenes/MainScreen/MainViewController.swift +++ b/IVPNClient/Scenes/MainScreen/MainViewController.swift @@ -65,12 +65,12 @@ class MainViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.accessibilityIdentifier = "mainScreen" + evaluateFirstRun() initErrorObservers() initFloatingPanel() addObservers() startServersUpdate() startVPNStatusObserver() - evaluateFirstRun() } override func viewWillAppear(_ animated: Bool) { @@ -275,6 +275,8 @@ class MainViewController: UIViewController { if UserDefaults.standard.object(forKey: UserDefaults.Key.firstInstall) == nil && UserDefaults.standard.object(forKey: UserDefaults.Key.selectedServerGateway) == nil { KeyChain.clearAll() UserDefaults.clearSession() + Application.shared.settings.connectionProtocol = Config.defaultProtocol + Application.shared.settings.saveConnectionProtocol() UserDefaults.standard.set(false, forKey: UserDefaults.Key.firstInstall) UserDefaults.standard.synchronize() }