From 9c834153b0f41ede115174f84b7333422e2a98dd Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 18 Oct 2023 09:41:28 +0200 Subject: [PATCH 1/4] fix: update disconnect method in VPNManager --- IVPNClient/Managers/VPNManager.swift | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/IVPNClient/Managers/VPNManager.swift b/IVPNClient/Managers/VPNManager.swift index 59192949e..3d89dddbd 100644 --- a/IVPNClient/Managers/VPNManager.swift +++ b/IVPNClient/Managers/VPNManager.swift @@ -232,7 +232,7 @@ class VPNManager { func installOnDemandRules(settings: ConnectionSettings, accessDetails: AccessDetails) { switch settings { case .ipsec: - self.disable(tunnelType: .openvpn) { _ in + disable(tunnelType: .openvpn) { _ in self.disable(tunnelType: .wireguard) { _ in self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in self.disconnect(tunnelType: .ipsec) @@ -240,19 +240,15 @@ class VPNManager { } } case .openvpn: - self.disable(tunnelType: .ipsec) { _ in + disable(tunnelType: .ipsec) { _ in self.disable(tunnelType: .wireguard) { _ in - self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in - self.disconnect(tunnelType: .openvpn) - } + self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in } } } case .wireguard: - self.disable(tunnelType: .ipsec) { _ in + disable(tunnelType: .ipsec) { _ in self.disable(tunnelType: .openvpn) { _ in - self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in - self.disconnect(tunnelType: .wireguard) - } + self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in } } } } @@ -272,14 +268,9 @@ class VPNManager { } func disconnect(tunnelType: TunnelType, reconnectAutomatically: Bool = false) { - getManagerFor(tunnelType: tunnelType) { manager in - DispatchQueue.async { - manager.connection.stopVPNTunnel() - } - - if !UserDefaults.shared.networkProtectionEnabled || reconnectAutomatically { - self.removeOnDemandRule(manager: manager) - } + getManagerFor(tunnelType: tunnelType) { [self] manager in + manager.connection.stopVPNTunnel() + removeOnDemandRule(manager: manager) } } From 8478edd5a74a5526629ace3e1ffce915bfafd30e Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 18 Oct 2023 12:46:24 +0200 Subject: [PATCH 2/4] fix: update disconnect method in VPNManager --- IVPNClient/Managers/VPNManager.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/IVPNClient/Managers/VPNManager.swift b/IVPNClient/Managers/VPNManager.swift index 3d89dddbd..6cc26fe5f 100644 --- a/IVPNClient/Managers/VPNManager.swift +++ b/IVPNClient/Managers/VPNManager.swift @@ -242,13 +242,21 @@ class VPNManager { case .openvpn: disable(tunnelType: .ipsec) { _ in self.disable(tunnelType: .wireguard) { _ in - self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in } + self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in + DispatchQueue.async { + self.openvpnManager?.connection.stopVPNTunnel() + } + } } } case .wireguard: disable(tunnelType: .ipsec) { _ in self.disable(tunnelType: .openvpn) { _ in - self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in } + self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in + DispatchQueue.async { + self.wireguardManager?.connection.stopVPNTunnel() + } + } } } } @@ -270,7 +278,10 @@ class VPNManager { func disconnect(tunnelType: TunnelType, reconnectAutomatically: Bool = false) { getManagerFor(tunnelType: tunnelType) { [self] manager in manager.connection.stopVPNTunnel() - removeOnDemandRule(manager: manager) + + if !UserDefaults.shared.networkProtectionEnabled || reconnectAutomatically { + removeOnDemandRule(manager: manager) + } } } From 5e1a6bad5926a27ba3a80bea505499b1ffa56ee4 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Thu, 19 Oct 2023 09:56:31 +0200 Subject: [PATCH 3/4] fix(network protection): update StorageManager.swift --- IVPNClient/Managers/StorageManager.swift | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/IVPNClient/Managers/StorageManager.swift b/IVPNClient/Managers/StorageManager.swift index 9e85a8cf8..76163dc70 100644 --- a/IVPNClient/Managers/StorageManager.swift +++ b/IVPNClient/Managers/StorageManager.swift @@ -300,21 +300,35 @@ extension StorageManager { return nil } + private static func probeURL() -> URL? { + let isNetworkProtection = UserDefaults.shared.networkProtectionEnabled + let probeURL = URL(string: "https://\(Config.ApiHostName)\(Config.apiServersFile)") + return isNetworkProtection ? probeURL : nil + } + private static func getDefaultOnDemandRule(status: NEVPNStatus) -> NEOnDemandRule? { let defaultTrust = getDefaultTrust() if defaultTrust == NetworkTrust.Untrusted.rawValue { - return NEOnDemandRuleConnect() + let onDemandRule = NEOnDemandRuleConnect() + onDemandRule.probeURL = probeURL() + return onDemandRule } if defaultTrust == NetworkTrust.Trusted.rawValue { - return NEOnDemandRuleDisconnect() + let onDemandRule = NEOnDemandRuleDisconnect() + onDemandRule.probeURL = probeURL() + return onDemandRule } switch status { case .connected: - return NEOnDemandRuleConnect() + let onDemandRule = NEOnDemandRuleConnect() + onDemandRule.probeURL = probeURL() + return onDemandRule case .disconnected, .invalid: - return NEOnDemandRuleDisconnect() + let onDemandRule = NEOnDemandRuleDisconnect() + onDemandRule.probeURL = probeURL() + return onDemandRule default: return nil } From e1e539f35668caa13cb4799eb5f7dcd24971d151 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 24 Oct 2023 18:47:38 +0200 Subject: [PATCH 4/4] fix(network protection): update VPNManager.swift --- IVPNClient/Managers/VPNManager.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IVPNClient/Managers/VPNManager.swift b/IVPNClient/Managers/VPNManager.swift index 6cc26fe5f..0f3473984 100644 --- a/IVPNClient/Managers/VPNManager.swift +++ b/IVPNClient/Managers/VPNManager.swift @@ -243,7 +243,7 @@ class VPNManager { disable(tunnelType: .ipsec) { _ in self.disable(tunnelType: .wireguard) { _ in self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in - DispatchQueue.async { + DispatchQueue.delay(1) { self.openvpnManager?.connection.stopVPNTunnel() } } @@ -253,7 +253,7 @@ class VPNManager { disable(tunnelType: .ipsec) { _ in self.disable(tunnelType: .openvpn) { _ in self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in - DispatchQueue.async { + DispatchQueue.delay(1) { self.wireguardManager?.connection.stopVPNTunnel() } }