Unverified Commit 03182824 authored by Davide De Rosa's avatar Davide De Rosa Committed by GitHub
Browse files

Merge pull request #7 from pia-foss/upgrade-tunnel-api

Update API to PIATunnel 1.1.3
parents 4222ee22 8bc6b900
......@@ -38,7 +38,7 @@ Pod::Spec.new do |s|
p.frameworks = "NetworkExtension"
p.pod_target_xcconfig = { "APPLICATION_EXTENSION_API_ONLY" => "YES" }
p.dependency "PIATunnel", "~> 1.1.2"
p.dependency "PIATunnel", "~> 1.1.3"
p.dependency "PIALibrary/Library"
end
......
......@@ -23,8 +23,6 @@ protocol PlainStore: class {
var cachedServers: [Server] { get set }
var preferredServer: Server? { get set }
var preferredPort: UInt16? { get set }
func ping(forServerIdentifier serverIdentifier: String) -> Int?
......
......@@ -23,9 +23,6 @@ public struct VPNConfiguration {
/// The `Server` to connect to.
public let server: Server
/// A custom port to connect to.
public let port: UInt16?
/// When `true`, the VPN will connect on demand.
public let isOnDemand: Bool
......@@ -43,9 +40,6 @@ public struct VPNConfiguration {
/// - Seealso: `VPNProfile`
public protocol VPNCustomConfiguration {
/// Returns `true` if connects via TCP.
var isTCP: Bool { get }
/**
Returns a dictionary representation of this configuration.
......
......@@ -14,8 +14,6 @@ private let log = SwiftyBeaver.self
private protocol PreferencesStore: class {
var preferredServer: Server? { get set }
var preferredPort: UInt16? { get set }
var isPersistentConnection: Bool { get set }
var mace: Bool { get set }
......@@ -38,7 +36,6 @@ private extension PreferencesStore {
func load(from source: PreferencesStore) {
preferredServer = source.preferredServer
preferredPort = source.preferredPort
isPersistentConnection = source.isPersistentConnection
mace = source.mace
vpnType = source.vpnType
......@@ -79,16 +76,6 @@ extension Client {
}
}
/// The preferred server port, in case it's applicable for the current VPN protocol.
public var preferredPort: UInt16? {
get {
return accessedDatabase.plain.preferredPort
}
set {
accessedDatabase.plain.preferredPort = newValue
}
}
/// Enables automatic VPN reconnection.
public fileprivate(set) var isPersistentConnection: Bool {
get {
......@@ -195,7 +182,6 @@ extension Client.Preferences {
fileprivate init() {
preferredServer = nil
preferredPort = nil
isPersistentConnection = true
mace = false
vpnType = IPSecProfile.vpnType
......@@ -229,9 +215,6 @@ extension Client.Preferences {
/// :nodoc:
public var preferredServer: Server?
/// :nodoc:
public var preferredPort: UInt16?
/// :nodoc:
public var isPersistentConnection: Bool
......@@ -281,9 +264,6 @@ extension Client.Preferences {
if !isPreferredServer(equalTo: target.preferredServer) {
queue.append(VPNActionReinstall())
}
if !isPreferredPort(equalTo: target.preferredPort) {
queue.append(VPNActionReconnect())
}
if (vpnType != target.vpnType) {
queue.append(VPNActionDisconnectAndReinstall())
}
......@@ -306,16 +286,6 @@ extension Client.Preferences {
return (preferredServer == server)
}
private func isPreferredPort(equalTo port: UInt16?) -> Bool {
guard let preferredPort = preferredPort else {
return (port == nil)
}
guard let port = port else {
return false
}
return (preferredPort == port)
}
/**
Returns `true` if the VPN needs to reconnect to make the pending changes effective.
......@@ -328,9 +298,6 @@ extension Client.Preferences {
if (mace != target.mace) {
return true
}
if !isPreferredPort(equalTo: target.preferredPort) {
return true
}
if let configuration = vpnCustomConfigurations[vpnType],
let targetConfiguration = target.activeVPNCustomConfiguration,
!configuration.isEqual(to: targetConfiguration) {
......
......@@ -26,8 +26,6 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
static let preferredServer = "CurrentRegion" // legacy
static let preferredPort = "PreferredPort"
static let pingByServerIdentifier = "PingByServerIdentifier"
static let vpnType = "VPNType"
......@@ -148,19 +146,6 @@ class UserDefaultsStore: PlainStore, ConfigurationAccess {
}
}
var preferredPort: UInt16? {
get {
let port = backend.integer(forKey: Entries.preferredPort)
guard (port > 0) else {
return nil
}
return UInt16(port)
}
set {
backend.set(newValue, forKey: Entries.preferredPort)
}
}
func ping(forServerIdentifier serverIdentifier: String) -> Int? {
return pingByServerIdentifier[serverIdentifier]
}
......
......@@ -243,24 +243,11 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
let customConfiguration = accessedPreferences.vpnCustomConfiguration(for: profile.vpnType)
var port = accessedPreferences.preferredPort
if (port == nil), let cfg = customConfiguration {
let targetServer = accessedProviders.serverProvider.targetServer
if cfg.isTCP {
port = targetServer.bestOpenVPNAddressForTCP?.port ??
accessedDatabase.transient.serversConfiguration.vpnPorts.tcp.first
} else {
port = targetServer.bestOpenVPNAddressForUDP?.port ??
accessedDatabase.transient.serversConfiguration.vpnPorts.udp.first
}
}
return VPNConfiguration(
name: accessedConfiguration.vpnProfileName,
username: currentUser.credentials.username,
passwordReference: currentPasswordReference,
server: accessedProviders.serverProvider.targetServer,
port: port,
isOnDemand: accessedPreferences.isPersistentConnection,
disconnectsOnSleep: accessedPreferences.vpnDisconnectsOnSleep,
customConfiguration: customConfiguration
......
......@@ -12,8 +12,6 @@ import NetworkExtension
/// Implementation of `VPNProfile` providing OpenVPN connectivity.
public class PIATunnelProfile: NetworkExtensionProfile {
private static let defaultPort: UInt16 = 1194
private let bundleIdentifier: String
/**
......@@ -169,8 +167,7 @@ public class PIATunnelProfile: NetworkExtensionProfile {
cfg.username = configuration.username
cfg.passwordReference = configuration.passwordReference
let port = configuration.port ?? PIATunnelProfile.defaultPort
cfg.serverAddress = "\(configuration.server.hostname):\(port)"
cfg.serverAddress = configuration.server.hostname
cfg.providerBundleIdentifier = bundleIdentifier
var customCfg = configuration.customConfiguration
......
......@@ -11,10 +11,6 @@ import PIATunnel
/// :nodoc:
extension PIATunnelProvider.Configuration: VPNCustomConfiguration {
public var isTCP: Bool {
return (socketType == .tcp)
}
public func serialized() -> [String: Any] {
return generatedProviderConfiguration()
}
......@@ -26,7 +22,7 @@ extension PIATunnelProvider.Configuration: VPNCustomConfiguration {
guard (appGroup == other.appGroup) else {
return false
}
guard (socketType == other.socketType) else {
guard (endpointProtocols == other.endpointProtocols) else {
return false
}
guard (cipher == other.cipher) else {
......
......@@ -7,7 +7,7 @@ abstract_target 'PIALibrary' do
pod 'Alamofire', '~> 4'
pod 'ReachabilitySwift'
#pod 'PIATunnel', :git => 'https://github.com/pia-foss/tunnel-apple.git', :commit => 'dfe7f3c'
pod 'PIATunnel', '~> 1.1.2'
pod 'PIATunnel', '~> 1.1.3'
target 'PIALibrary-iOS' do
platform :ios, '9.0'
......
......@@ -2,13 +2,13 @@ PODS:
- Alamofire (4.7.2)
- Gloss (2.0.1)
- OpenSSL-Apple (1.1.0h)
- PIATunnel (1.1.2):
- PIATunnel/AppExtension (= 1.1.2)
- PIATunnel/Core (= 1.1.2)
- PIATunnel/AppExtension (1.1.2):
- PIATunnel (1.1.3):
- PIATunnel/AppExtension (= 1.1.3)
- PIATunnel/Core (= 1.1.3)
- PIATunnel/AppExtension (1.1.3):
- PIATunnel/Core
- SwiftyBeaver
- PIATunnel/Core (1.1.2):
- PIATunnel/Core (1.1.3):
- OpenSSL-Apple (~> 1.1.0h)
- SwiftyBeaver
- ReachabilitySwift (4.1.0)
......@@ -17,7 +17,7 @@ PODS:
DEPENDENCIES:
- Alamofire (~> 4)
- Gloss (~> 2)
- PIATunnel (~> 1.1.2)
- PIATunnel (~> 1.1.3)
- ReachabilitySwift
- SwiftyBeaver (~> 1.4)
......@@ -34,10 +34,10 @@ SPEC CHECKSUMS:
Alamofire: e4fa87002c137ba2d8d634d2c51fabcda0d5c223
Gloss: 1e8743f8de1fbe14a97f220ff901cba91ae5f8f8
OpenSSL-Apple: cd153d705ef350eb834ae7ff5f21f792b51ed208
PIATunnel: c86cb855e2fb5ad217e6123884ec61fae736636f
PIATunnel: b869c1cb9844931e969d24a585483b7e16e1a582
ReachabilitySwift: 6849231cd4e06559f3b9ef4a97a0a0f96d41e09f
SwiftyBeaver: 25bd76281f49ca989ec2e3cbde9af89c15bc1432
PODFILE CHECKSUM: 1ab050612d892c5a6d50032b1aabac0094b289f3
PODFILE CHECKSUM: 3e4aec82d84584c5df779a4becf3ebe2f3a6a3ee
COCOAPODS: 1.5.3
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