diff --git a/Sources/PIALibrary/Client+Configuration.swift b/Sources/PIALibrary/Client+Configuration.swift index 28dfd3d1..56e098a8 100644 --- a/Sources/PIALibrary/Client+Configuration.swift +++ b/Sources/PIALibrary/Client+Configuration.swift @@ -225,7 +225,12 @@ extension Client { enablesServerPings = false minPingInterval = 120000 + availableVPNProfiles = [] + + #if os(tvOS) availableVPNProfiles = [IKEv2Profile()] + #endif + vpnProfileName = "Private Internet Access" vpnReconnectionDelay = 2000 diff --git a/Sources/PIALibrary/Client+Preferences.swift b/Sources/PIALibrary/Client+Preferences.swift index 62bba705..a6f16eee 100644 --- a/Sources/PIALibrary/Client+Preferences.swift +++ b/Sources/PIALibrary/Client+Preferences.swift @@ -307,6 +307,12 @@ extension Client { allMaps[vpnType] = customConfiguration.serialized() accessedDatabase.plain.vpnCustomConfigurationMaps = allMaps } + + #if os(iOS) + public func setVpnTypeToWireguard() { + self.vpnType = PIAWGTunnelProfile.vpnType + } + #endif /// The `String` array of available WiFi networks public fileprivate(set) var availableNetworks: [String] { @@ -399,6 +405,16 @@ extension Client { accessedDatabase.plain.timeToConnectVPN = newValue } } + + /// Store a bool that represents whether we already attempted to migrate to wireguard + public var wireguardMigrationPerformed: Bool { + get { + return accessedDatabase.plain.wireguardMigrationPerformed + } + set { + accessedDatabase.plain.wireguardMigrationPerformed = newValue + } + } /// Store a bool that represents the status of leak protection property public var leakProtection: Bool { @@ -481,7 +497,12 @@ extension Client.Preferences { useWiFiProtection = true trustCellularData = false nmtMigrationSuccess = false + vpnType = PIAWGTunnelProfile.vpnType + + #if os(tvOS) vpnType = IKEv2Profile.vpnType + #endif + vpnDisconnectsOnSleep = false vpnCustomConfigurations = [:] availableNetworks = [] diff --git a/Sources/PIALibrary/Persistence/PlainStore.swift b/Sources/PIALibrary/Persistence/PlainStore.swift index 986c634a..5d1ffe81 100644 --- a/Sources/PIALibrary/Persistence/PlainStore.swift +++ b/Sources/PIALibrary/Persistence/PlainStore.swift @@ -72,6 +72,8 @@ protocol PlainStore: class { var lastVPNConnectionAttempt: Double { get set } var timeToConnectVPN: Double { get set } + + var wireguardMigrationPerformed: Bool { get set } var leakProtection: Bool { get set } diff --git a/Sources/PIALibrary/Persistence/UserDefaultsStore.swift b/Sources/PIALibrary/Persistence/UserDefaultsStore.swift index 76b4a2c7..b33da4bd 100644 --- a/Sources/PIALibrary/Persistence/UserDefaultsStore.swift +++ b/Sources/PIALibrary/Persistence/UserDefaultsStore.swift @@ -106,6 +106,8 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess { static let lastVPNConnectionAttempt = "lastVPNConnectionAttempt" static let timeToConnectVPN = "timeToConnectVPN" + + static let wireguardMigrationPerformed = "WireguardMigrationPerformed" static let leakProtection = "LeakProtection" @@ -441,6 +443,18 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess { backend.set(newValue, forKey: Entries.timeToConnectVPN) } } + + var wireguardMigrationPerformed: Bool { + get { + if backend.object(forKey: Entries.wireguardMigrationPerformed) == nil { + backend.set(false, forKey: Entries.wireguardMigrationPerformed) + } + return backend.bool(forKey: Entries.wireguardMigrationPerformed) + } + set { + backend.set(newValue, forKey: Entries.wireguardMigrationPerformed) + } + } var leakProtection: Bool { get { diff --git a/Sources/PIALibrary/VPN/IKEv2Profile.swift b/Sources/PIALibrary/VPN/IKEv2Profile.swift index 9a806a65..0226646d 100644 --- a/Sources/PIALibrary/VPN/IKEv2Profile.swift +++ b/Sources/PIALibrary/VPN/IKEv2Profile.swift @@ -34,7 +34,7 @@ public class IKEv2Profile: NetworkExtensionProfile { return NEVPNManager.shared() } - init() { + public init() { } // MARK: VPNProfile diff --git a/Sources/PIALibrary/VPN/PIATunnelProfile.swift b/Sources/PIALibrary/VPN/PIATunnelProfile.swift index a0b6cb8d..b2010933 100644 --- a/Sources/PIALibrary/VPN/PIATunnelProfile.swift +++ b/Sources/PIALibrary/VPN/PIATunnelProfile.swift @@ -75,6 +75,7 @@ public class PIATunnelProfile: NetworkExtensionProfile { callback?(error) return } + self.doSave(vpn, withConfiguration: configuration, force: true) { (error) in if let _ = error { callback?(error) diff --git a/Sources/PIALibrary/VPN/PIAWGTunnelProfile.swift b/Sources/PIALibrary/VPN/PIAWGTunnelProfile.swift index 04823f62..c610de03 100644 --- a/Sources/PIALibrary/VPN/PIAWGTunnelProfile.swift +++ b/Sources/PIALibrary/VPN/PIAWGTunnelProfile.swift @@ -152,6 +152,7 @@ public class PIAWGTunnelProfile: NetworkExtensionProfile { callback?(error) return } + self.doSave(vpn, withConfiguration: configuration, force: true) { (error) in if let _ = error { callback?(error)