Commit fb508591 authored by Jose Blaya's avatar Jose Blaya
Browse files

Merge branch '110-piax-improve-how-to-reconnect-after-disconnect-vpn-manually' into 'release/2.0.0'

Resolve "PIAX. Improve how to reconnect after disconnect VPN manually"

See merge request ios/client-library-apple!166
parents 46173795 c2760e75
......@@ -268,12 +268,15 @@
DD58F4BD21AEF76100D043F7 /* String+Components.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58F4BC21AEF76100D043F7 /* String+Components.swift */; };
DD6DC5B921B6A83400F9D538 /* UIViewLoading.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6DC5B821B6A83400F9D538 /* UIViewLoading.swift */; };
DD6DC5BC21B6A8FC00F9D538 /* pia-spinner.json in Resources */ = {isa = PBXBuildFile; fileRef = DD6DC5BB21B6A8FC00F9D538 /* pia-spinner.json */; };
DD6FB0372224355600A84F05 /* UIDevice+WiFi.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6FB0362224355600A84F05 /* UIDevice+WiFi.swift */; };
DD76292821ECDFF80092DF50 /* Usage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292721ECDFF80092DF50 /* Usage.swift */; };
DD76292921ECDFF80092DF50 /* Usage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292721ECDFF80092DF50 /* Usage.swift */; };
DD76292E21ECEC3F0092DF50 /* DataManipulation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */; };
DD76292F21ECEC3F0092DF50 /* DataManipulation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */; };
DD86BAF121EF5B6D004A988F /* UIViewAutolayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD86BAF021EF5B6D004A988F /* UIViewAutolayout.swift */; };
DD8BF3CB219C6BAA0041357C /* ConfirmVPNPlanViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8BF3CA219C6BAA0041357C /* ConfirmVPNPlanViewController.swift */; };
DDA4A7BE21F5C31400A02ACD /* IKEv2Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDA4A7BD21F5C31400A02ACD /* IKEv2Profile.swift */; };
DDA4A7BF21F5C31B00A02ACD /* IKEv2Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDA4A7BD21F5C31400A02ACD /* IKEv2Profile.swift */; };
DDD824E32189969400151709 /* Preset.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD824E22189969400151709 /* Preset.swift */; };
DDD824E5218996CD00151709 /* Pages.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD824E4218996CD00151709 /* Pages.swift */; };
DDD824E72189C0E800151709 /* BrandableNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD824E62189C0E800151709 /* BrandableNavigationBar.swift */; };
......@@ -292,10 +295,6 @@
DDFCFAB721E925F70081F235 /* EnumsBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDFCFAB521E925F70081F235 /* EnumsBuilder.swift */; };
DDFCFABA21E929660081F235 /* MockTileProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDFCFAB921E929660081F235 /* MockTileProvider.swift */; };
DDFCFABB21E929660081F235 /* MockTileProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDFCFAB921E929660081F235 /* MockTileProvider.swift */; };
DDA4A7BE21F5C31400A02ACD /* IKEv2Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDA4A7BD21F5C31400A02ACD /* IKEv2Profile.swift */; };
DDA4A7BF21F5C31B00A02ACD /* IKEv2Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDA4A7BD21F5C31400A02ACD /* IKEv2Profile.swift */; };
DDC812482176166600CB290C /* SwiftGen+ScenesStoryboards.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC812472176166500CB290C /* SwiftGen+ScenesStoryboards.swift */; };
DDC8124A217617F900CB290C /* SwiftGen+SeguesStoryboards.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC81249217617F900CB290C /* SwiftGen+SeguesStoryboards.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -553,6 +552,7 @@
DD58F4BC21AEF76100D043F7 /* String+Components.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Components.swift"; sourceTree = "<group>"; };
DD6DC5B821B6A83400F9D538 /* UIViewLoading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewLoading.swift; sourceTree = "<group>"; };
DD6DC5BB21B6A8FC00F9D538 /* pia-spinner.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "pia-spinner.json"; sourceTree = "<group>"; };
DD6FB0362224355600A84F05 /* UIDevice+WiFi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+WiFi.swift"; sourceTree = "<group>"; };
DD76292721ECDFF80092DF50 /* Usage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Usage.swift; sourceTree = "<group>"; };
DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataManipulation.swift; sourceTree = "<group>"; };
DD86BAF021EF5B6D004A988F /* UIViewAutolayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewAutolayout.swift; sourceTree = "<group>"; };
......@@ -636,6 +636,7 @@
DDD824E22189969400151709 /* Preset.swift */,
DDD824E4218996CD00151709 /* Pages.swift */,
DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */,
DD6FB0362224355600A84F05 /* UIDevice+WiFi.swift */,
);
path = Util;
sourceTree = "<group>";
......@@ -1694,6 +1695,7 @@
0E3D13D91F9E273300434A48 /* GlossSignup.swift in Sources */,
84577FBF213D8EE6006DEC3D /* ViewStyles.swift in Sources */,
0E0E5B0F1F8297C500022CD0 /* SecureStore.swift in Sources */,
DD6FB0372224355600A84F05 /* UIDevice+WiFi.swift in Sources */,
0EAA388B1F9CC4C4000149CF /* InAppProduct.swift in Sources */,
DD314990218350D1008E26E8 /* SwiftGen+ScenesStoryboards.swift in Sources */,
0EAA388D1F9CC4C4000149CF /* InAppTransaction.swift in Sources */,
......
......@@ -73,8 +73,6 @@ protocol PlainStore: class {
var trustedNetworks: [String] { get set }
var connectOnUntrusted: Bool? { get set }
var disconnectOnTrusted: Bool? { get set }
}
......@@ -36,8 +36,6 @@ private protocol PreferencesStore: class {
var trustedNetworks: [String] { get set }
var connectOnUntrusted: Bool { get set }
var disconnectOnTrusted: Bool { get set }
func vpnCustomConfiguration(for vpnType: String) -> VPNCustomConfiguration?
......@@ -63,7 +61,6 @@ private extension PreferencesStore {
vpnCustomConfigurations = source.vpnCustomConfigurations
availableNetworks = source.availableNetworks
trustedNetworks = source.trustedNetworks
connectOnUntrusted = source.connectOnUntrusted
disconnectOnTrusted = source.disconnectOnTrusted
}
}
......@@ -254,16 +251,6 @@ extension Client {
}
}
/// Connect the VPN when joining an untrusted network. True by default
public fileprivate(set) var connectOnUntrusted: Bool {
get {
return accessedDatabase.plain.connectOnUntrusted ?? true
}
set {
accessedDatabase.plain.connectOnUntrusted = newValue
}
}
/// Disconnect the VPN when joining a trusted network. False by default
public fileprivate(set) var disconnectOnTrusted: Bool {
get {
......@@ -291,7 +278,7 @@ extension Client.Preferences {
isPersistentConnection = true
mace = false
useWiFiProtection = false
trustCellularData = true
trustCellularData = false
authMigrationSuccess = false
shouldConnectForAllNetworks = false
vpnType = IPSecProfile.vpnType
......@@ -299,7 +286,6 @@ extension Client.Preferences {
vpnCustomConfigurations = [:]
availableNetworks = []
trustedNetworks = []
connectOnUntrusted = true
disconnectOnTrusted = false
}
......@@ -362,9 +348,6 @@ extension Client.Preferences {
/// :nodoc:
public var trustedNetworks: [String]
/// :nodoc:
public var connectOnUntrusted: Bool
/// :nodoc:
public var disconnectOnTrusted: Bool
......@@ -396,10 +379,13 @@ extension Client.Preferences {
if (trustCellularData != target.trustCellularData) {
queue.append(VPNActionDisconnectAndReinstall())
}
if (trustedNetworks != target.trustedNetworks) {
if (trustCellularData != target.shouldConnectForAllNetworks) {
queue.append(VPNActionDisconnectAndReinstall())
}
if (connectOnUntrusted != target.connectOnUntrusted) {
if (trustCellularData != target.useWiFiProtection) {
queue.append(VPNActionDisconnectAndReinstall())
}
if (trustedNetworks != target.trustedNetworks) {
queue.append(VPNActionDisconnectAndReinstall())
}
if (disconnectOnTrusted != target.disconnectOnTrusted) {
......
......@@ -32,7 +32,7 @@ class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Preferenc
private var pendingConnectivityCheck: URLSessionDataTask?
private var wasConnected: Bool
private init() {
hasEnabledUpdates = false
......@@ -155,7 +155,7 @@ class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Preferenc
}
// MARK: Notifications
@objc private func vpnStatusDidChange(notification: Notification) {
switch accessedDatabase.transient.vpnStatus {
case .connected:
......
......@@ -57,8 +57,6 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
static let cachedNetworks = "CachedNetworks"
static let trustedNetworks = "TrustedNetworks"
static let connectOnUntrusted = "ConnectOnUntrusted"
static let disconnectOnTrusted = "DisconnectOnTrusted"
......@@ -399,18 +397,6 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
backend.set(newValue, forKey: Entries.mace)
}
}
var connectOnUntrusted: Bool? {
get {
guard let value = backend.object(forKey: Entries.connectOnUntrusted) as? Bool else {
return nil
}
return value
}
set {
backend.set(newValue, forKey: Entries.connectOnUntrusted)
}
}
var disconnectOnTrusted: Bool? {
get {
......@@ -436,7 +422,6 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
backend.removeObject(forKey: Entries.historicalServers)
backend.removeObject(forKey: Entries.cachedNetworks)
backend.removeObject(forKey: Entries.trustedNetworks)
backend.removeObject(forKey: Entries.connectOnUntrusted)
backend.removeObject(forKey: Entries.disconnectOnTrusted)
backend.removeObject(forKey: Entries.shouldConnectForAllNetworks)
backend.removeObject(forKey: Entries.useWiFiProtection)
......
......@@ -59,62 +59,79 @@ extension NetworkExtensionProfile {
vpn.isOnDemandEnabled = configuration.isOnDemand
let trustedNetworks = Client.preferences.trustedNetworks
let ruleDisconnect = NEOnDemandRuleDisconnect()
ruleDisconnect.ssidMatch = trustedNetworks
vpn.onDemandRules = []
if vpn.isOnDemandEnabled {
let wiFiRule = NEOnDemandRuleConnect()
wiFiRule.interfaceTypeMatch = .wiFi
vpn.onDemandRules = [wiFiRule]
if Client.preferences.useWiFiProtection,
Client.preferences.disconnectOnTrusted,
trustedNetworks.count > 0 {
vpn.onDemandRules?.append(ruleDisconnect)
}
}
//Configure onDemand rules
if !Client.preferences.trustCellularData {
vpn.isOnDemandEnabled = true
let cellularRule = NEOnDemandRuleConnect()
cellularRule.interfaceTypeMatch = .cellular
vpn.onDemandRules?.append(cellularRule)
if Client.preferences.useWiFiProtection,
Client.preferences.disconnectOnTrusted,
trustedNetworks.count > 0 {
vpn.onDemandRules?.append(ruleDisconnect)
}
} else {
//trust cellular data = true
if Client.preferences.disconnectOnTrusted {
let cellularRule = NEOnDemandRuleDisconnect()
cellularRule.interfaceTypeMatch = .cellular
vpn.onDemandRules?.append(cellularRule)
let ruleDisconnect = NEOnDemandRuleDisconnect()
ruleDisconnect.interfaceTypeMatch = .wiFi
ruleDisconnect.ssidMatch = trustedNetworks
if Client.preferences.useWiFiProtection {
let ruleConnect = NEOnDemandRuleConnect()
ruleConnect.interfaceTypeMatch = .wiFi
if Client.preferences.shouldConnectForAllNetworks {
vpn.onDemandRules?.append(ruleConnect)
} else {
vpn.onDemandRules?.append(contentsOf: [ruleDisconnect, ruleConnect])
}
} else {
let ruleConnect = NEOnDemandRuleConnect()
ruleConnect.interfaceTypeMatch = .wiFi
vpn.onDemandRules?.append(ruleConnect)
}
if !Client.preferences.trustCellularData {
let ruleConnect = NEOnDemandRuleConnect()
ruleConnect.interfaceTypeMatch = .cellular
vpn.onDemandRules?.append(ruleConnect)
} else {
let ruleDisconnect = NEOnDemandRuleDisconnect()
ruleDisconnect.interfaceTypeMatch = .cellular
vpn.onDemandRules?.append(ruleDisconnect)
}
} else {
let cellularRule = NEOnDemandRuleConnect()
cellularRule.interfaceTypeMatch = .cellular
vpn.onDemandRules?.append(cellularRule)
}
}
if !Client.preferences.connectOnUntrusted {
let wiFiRule = NEOnDemandRuleDisconnect()
wiFiRule.interfaceTypeMatch = .wiFi
vpn.onDemandRules = [wiFiRule]
if !Client.preferences.trustCellularData {
let cellularRule = NEOnDemandRuleDisconnect()
cellularRule.interfaceTypeMatch = .cellular
vpn.onDemandRules?.append(cellularRule)
if !Client.preferences.trustCellularData {
let ruleConnect = NEOnDemandRuleConnect()
ruleConnect.interfaceTypeMatch = .cellular
vpn.onDemandRules?.append(ruleConnect)
} else {
let ruleDisconnect = NEOnDemandRuleDisconnect()
ruleDisconnect.interfaceTypeMatch = .cellular
vpn.onDemandRules?.append(ruleDisconnect)
}
if !Client.preferences.useWiFiProtection {
let ruleConnect = NEOnDemandRuleConnect()
ruleConnect.interfaceTypeMatch = .wiFi
vpn.onDemandRules?.append(ruleConnect)
} else {
if Client.preferences.shouldConnectForAllNetworks {
let ruleConnect = NEOnDemandRuleConnect()
ruleConnect.interfaceTypeMatch = .wiFi
vpn.onDemandRules?.append(ruleConnect)
} else {
let ruleIgnore = NEOnDemandRuleIgnore()
ruleIgnore.interfaceTypeMatch = .wiFi
ruleIgnore.ssidMatch = trustedNetworks
vpn.onDemandRules?.append(ruleIgnore)
let ruleConnect = NEOnDemandRuleConnect()
ruleConnect.interfaceTypeMatch = .wiFi
vpn.onDemandRules?.append(ruleConnect)
}
}
}
}
log.debug("Configured with server: \(protocolConfiguration.serverAddress!)")
log.debug("Username: \(protocolConfiguration.username!)")
log.debug("On-demand is now \(vpn.isOnDemandEnabled ? "ENABLED" : "DISABLED")")
log.debug("Raw manager: \(vpn)")
vpn.isEnabled = true
vpn.saveToPreferences { (error) in
if let error = error {
......
//
// UIDevice+WiFi.swift
// PIALibrary-iOS
//
// Created by Jose Antonio Blaya Garcia on 25/02/2019.
// Copyright © 2019 London Trust Media. All rights reserved.
//
import Foundation
import SystemConfiguration
import UIKit
public extension UIDevice {
public var WiFiSSID: String? {
guard let interfaces = CNCopySupportedInterfaces() as? [String] else { return nil }
let key = kCNNetworkInfoKeySSID as String
for interface in interfaces {
guard let interfaceInfo = CNCopyCurrentNetworkInfo(interface as CFString) as NSDictionary? else { continue }
return interfaceInfo[key] as? String
}
return nil
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment