Unverified Commit 1dfc06e6 authored by Davide De Rosa's avatar Davide De Rosa Committed by GitHub

Merge pull request #6 from pia-foss/develop

Develop 1.1.2
parents 3880846a 03182824
Pod::Spec.new do |s|
s.name = "PIALibrary"
s.version = "1.1.1"
s.version = "1.1.2"
s.summary = "PIA client library in Swift."
s.homepage = "https://www.privateinternetaccess.com/"
......@@ -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"
p.dependency "PIATunnel", "~> 1.1.3"
p.dependency "PIALibrary/Library"
end
......
......@@ -1272,7 +1272,6 @@
"${PODS_ROOT}/OpenSSL-Apple/frameworks/iPhone/openssl.framework",
"${BUILT_PRODUCTS_DIR}/PIATunnel/PIATunnel.framework",
"${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/SBObjectiveCWrapper/SBObjectiveCWrapper.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyBeaver/SwiftyBeaver.framework",
);
name = "[CP] Embed Pods Frameworks";
......@@ -1282,7 +1281,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PIATunnel.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SBObjectiveCWrapper.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyBeaver.framework",
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -1302,7 +1300,6 @@
"${PODS_ROOT}/OpenSSL-Apple/frameworks/iPhone/openssl.framework",
"${BUILT_PRODUCTS_DIR}/PIATunnel/PIATunnel.framework",
"${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/SBObjectiveCWrapper/SBObjectiveCWrapper.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyBeaver/SwiftyBeaver.framework",
);
name = "[CP] Embed Pods Frameworks";
......@@ -1312,7 +1309,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PIATunnel.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SBObjectiveCWrapper.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyBeaver.framework",
);
runOnlyForDeploymentPostprocessing = 0;
......
......@@ -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.
......
......@@ -76,6 +76,8 @@ extension Client {
/// Sets the interval before which pings are not repeated.
public var minPingInterval: Int
private(set) var customServers: [Server]
// MARK: Connectivity
/// Notifies connectivity updates e.g. current IP addresses.
......@@ -169,6 +171,7 @@ extension Client {
)
serversUpdateWhenNetworkDownDelay = 10000
verifiesServersSignature = true
customServers = []
enablesServerPings = false
minPingInterval = 120000
......@@ -197,7 +200,7 @@ extension Client {
#endif
}
// MARK: Web
// MARK: WebServices
/**
Sets base URL for web services in a determined environment.
......@@ -209,6 +212,17 @@ extension Client {
baseUrls[environment] = url
}
// MARK: Server
/**
Inserts a custom server on top on the server list.
- Parameter server: The server.
*/
public func addCustomServer(_ server: Server) {
customServers.append(server)
}
// MARK: VPN
/**
......
......@@ -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) {
......
......@@ -106,7 +106,7 @@ class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Preferenc
return
}
log.info("Checking network connectivity...")
log.debug("Checking network connectivity...")
accessedDatabase.transient.publicIP = nil
accessedDatabase.transient.vpnIP = nil
Macros.postNotification(.PIADaemonsDidUpdateConnectivity)
......@@ -121,7 +121,7 @@ class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Preferenc
log.error("Failed to check network connectivity (error: \(error?.localizedDescription ?? "")")
guard (self.failedConnectivityAttempts < self.accessedConfiguration.connectivityMaxAttempts) else {
log.info("Giving up, network is unreachable")
log.debug("Giving up, network is unreachable")
self.failedConnectivityAttempts = 0
self.accessedDatabase.transient.isInternetReachable = false
Macros.postNotification(.PIADaemonsDidUpdateConnectivity)
......@@ -129,7 +129,7 @@ class ConnectivityDaemon: Daemon, ConfigurationAccess, DatabaseAccess, Preferenc
}
let delay = self.accessedConfiguration.connectivityRetryDelay
log.info("Retrying network connectivity in \(delay) milliseconds...")
log.debug("Retrying network connectivity in \(delay) milliseconds...")
Macros.dispatch(after: .milliseconds(delay)) {
self.checkConnectivityOrRetry()
}
......
......@@ -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]
}
......
......@@ -31,18 +31,9 @@ class DefaultServerProvider: ServerProvider, ConfigurationAccess, DatabaseAccess
return accessedDatabase.plain.cachedServers
}
set {
accessedDatabase.plain.cachedServers = newValue
if accessedConfiguration.isDevelopment {
let chipotle = Server(
name: "chipotle251",
country: "US",
hostname: "chipotle251.privateinternetaccess.com",
bestOpenVPNAddressForTCP: nil,
bestOpenVPNAddressForUDP: Server.Address(hostname: "108.61.57.211", port: 8080),
pingAddress: nil
)
accessedDatabase.plain.cachedServers.insert(chipotle, at: 0)
}
var servers = newValue
servers.insert(contentsOf: accessedConfiguration.customServers, at: 0)
accessedDatabase.plain.cachedServers = servers
Macros.postNotification(.PIAServerDidUpdateCurrentServers, [
.servers: newValue
......
......@@ -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,10 +167,19 @@ 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
cfg.providerConfiguration = configuration.customConfiguration?.serialized()
var customCfg = configuration.customConfiguration
if let piaCfg = customCfg as? PIATunnelProvider.Configuration {
var builder = piaCfg.builder()
if let bestAddress = configuration.server.bestOpenVPNAddressForUDP?.hostname { // XXX: UDP address = TCP address
builder.resolvedAddresses = [bestAddress]
}
customCfg = builder.build()
}
cfg.providerConfiguration = customCfg?.serialized()
return cfg
}
......
......@@ -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 {
......
......@@ -17,7 +17,11 @@ class VPNTests: XCTestCase {
Client.database = Client.Database(group: "group.com.privateinternetaccess")
Client.providers.vpnProvider = MockVPNProvider()
Client.preferences.vpnDisconnectsOnSleep = true
let prefs = Client.preferences.editable()
prefs.vpnDisconnectsOnSleep = true
prefs.commit()
Client.bootstrap()
}
......
......@@ -6,8 +6,8 @@ abstract_target 'PIALibrary' do
pod 'Gloss', '~> 2'
pod 'Alamofire', '~> 4'
pod 'ReachabilitySwift'
#pod 'PIATunnel', :git => 'https://github.com/pia-foss/tunnel-apple.git', :commit => 'a224c2bd5d9755b61b6900907bc469c1a268c916'
pod 'PIATunnel', '~> 1.1'
#pod 'PIATunnel', :git => 'https://github.com/pia-foss/tunnel-apple.git', :commit => 'dfe7f3c'
pod 'PIATunnel', '~> 1.1.3'
target 'PIALibrary-iOS' do
platform :ios, '9.0'
......
......@@ -2,25 +2,22 @@ PODS:
- Alamofire (4.7.2)
- Gloss (2.0.1)
- OpenSSL-Apple (1.1.0h)
- PIATunnel (1.1.1):
- PIATunnel/AppExtension (= 1.1.1)
- PIATunnel/Core (= 1.1.1)
- PIATunnel/AppExtension (1.1.1):
- 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.1):
- PIATunnel/Core (1.1.3):
- OpenSSL-Apple (~> 1.1.0h)
- SBObjectiveCWrapper
- SwiftyBeaver
- ReachabilitySwift (4.1.0)
- SBObjectiveCWrapper (1.4.0):
- SwiftyBeaver (~> 1.4.0)
- SwiftyBeaver (1.4.4)
DEPENDENCIES:
- Alamofire (~> 4)
- Gloss (~> 2)
- PIATunnel (~> 1.1)
- PIATunnel (~> 1.1.3)
- ReachabilitySwift
- SwiftyBeaver (~> 1.4)
......@@ -31,18 +28,16 @@ SPEC REPOS:
- OpenSSL-Apple
- PIATunnel
- ReachabilitySwift
- SBObjectiveCWrapper
- SwiftyBeaver
SPEC CHECKSUMS:
Alamofire: e4fa87002c137ba2d8d634d2c51fabcda0d5c223
Gloss: 1e8743f8de1fbe14a97f220ff901cba91ae5f8f8
OpenSSL-Apple: cd153d705ef350eb834ae7ff5f21f792b51ed208
PIATunnel: bba311b4d274c66d3a5c4a0ed6285f8a7b55e781
PIATunnel: b869c1cb9844931e969d24a585483b7e16e1a582
ReachabilitySwift: 6849231cd4e06559f3b9ef4a97a0a0f96d41e09f
SBObjectiveCWrapper: 854ea56b37cd0031af2b1d6e12c2f965fc4ff86d
SwiftyBeaver: 25bd76281f49ca989ec2e3cbde9af89c15bc1432
PODFILE CHECKSUM: b6759e1e16582c875ff80faa25e63aedf62d5a7f
PODFILE CHECKSUM: 3e4aec82d84584c5df779a4becf3ebe2f3a6a3ee
COCOAPODS: 1.5.3
Markdown is supported
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