Commit 77c59f1b authored by Davide De Rosa's avatar Davide De Rosa
Browse files

Add local socket type for OpenVPN

nil is automatic (UDP with fallback to TCP).
parent cfff30eb
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import Foundation import Foundation
import PIALibrary import PIALibrary
import PIATunnel
import SwiftyBeaver import SwiftyBeaver
private let log = SwiftyBeaver.self private let log = SwiftyBeaver.self
...@@ -25,6 +26,8 @@ class AppPreferences { ...@@ -25,6 +26,8 @@ class AppPreferences {
static let themeCode = "Theme" // reuse 2.2 key static let themeCode = "Theme" // reuse 2.2 key
static let lastVPNConnectionStatus = "LastVPNConnectionStatus" static let lastVPNConnectionStatus = "LastVPNConnectionStatus"
static let piaSocketType = "PIASocketType"
} }
static let shared = AppPreferences() static let shared = AppPreferences()
...@@ -81,6 +84,23 @@ class AppPreferences { ...@@ -81,6 +84,23 @@ class AppPreferences {
defaults.set(newValue.rawValue, forKey: Entries.lastVPNConnectionStatus) defaults.set(newValue.rawValue, forKey: Entries.lastVPNConnectionStatus)
} }
} }
// nil = automatic
var piaSocketType: PIATunnelProvider.SocketType? {
get {
guard let rawValue = defaults.string(forKey: Entries.piaSocketType) else {
return nil
}
return PIATunnelProvider.SocketType(rawValue: rawValue)
}
set {
if let rawValue = newValue?.rawValue {
defaults.set(rawValue, forKey: Entries.piaSocketType)
} else {
defaults.removeObject(forKey: Entries.piaSocketType)
}
}
}
private init() { private init() {
guard let defaults = UserDefaults(suiteName: AppConstants.appGroup) else { guard let defaults = UserDefaults(suiteName: AppConstants.appGroup) else {
...@@ -124,8 +144,8 @@ class AppPreferences { ...@@ -124,8 +144,8 @@ class AppPreferences {
// otherwise, app version < 2.1 (local defaults/keychain) // otherwise, app version < 2.1 (local defaults/keychain)
// it used to be here in app version <= 2.0 // it used to be here in app version <= 2.0
let oldKeychain = Keychain() let oldKeychain = PIALibrary.Keychain()
let newKeychain = Keychain(team: AppConstants.teamId, group: AppConstants.appGroup) let newKeychain = PIALibrary.Keychain(team: AppConstants.teamId, group: AppConstants.appGroup)
// migrate credentials from local to shared keychain // migrate credentials from local to shared keychain
if let legacyPassword = try? oldKeychain.password(for: loggedUsername) { if let legacyPassword = try? oldKeychain.password(for: loggedUsername) {
......
...@@ -110,15 +110,17 @@ class Bootstrapper { ...@@ -110,15 +110,17 @@ class Bootstrapper {
// automatic // automatic
let tunnelConfiguration = pref.vpnCustomConfiguration(for: PIATunnelProfile.vpnType) as? PIATunnelProvider.Configuration let tunnelConfiguration = pref.vpnCustomConfiguration(for: PIATunnelProfile.vpnType) as? PIATunnelProvider.Configuration
if tunnelConfiguration?.endpointProtocols.isEmpty ?? true { if tunnelConfiguration?.endpointProtocols.isEmpty ?? true {
AppPreferences.shared.piaSocketType = nil
var tunnelConfigurationBuilder = tunnelConfiguration?.builder() var tunnelConfigurationBuilder = tunnelConfiguration?.builder()
let vpnPorts = Client.providers.serverProvider.currentServersConfiguration.vpnPorts let vpnPorts = Client.providers.serverProvider.currentServersConfiguration.vpnPorts
var protos: [PIATunnelProvider.EndpointProtocol] = [] var protos: [PIATunnelProvider.EndpointProtocol] = []
for port in vpnPorts.udp { for port in vpnPorts.udp {
protos.append(PIATunnelProvider.EndpointProtocol(.udp, port, .pia)) protos.append(PIATunnelProvider.EndpointProtocol(.udp, port, .pia))
} }
// for port in vpnPorts.tcp { for port in vpnPorts.tcp {
// protos.append(PIATunnelProvider.EndpointProtocol(.tcp, port, .pia)) protos.append(PIATunnelProvider.EndpointProtocol(.tcp, port, .pia))
// } }
tunnelConfigurationBuilder?.endpointProtocols = protos tunnelConfigurationBuilder?.endpointProtocols = protos
if let newConfiguration = tunnelConfigurationBuilder?.build() { if let newConfiguration = tunnelConfigurationBuilder?.build() {
pref.setVPNCustomConfiguration(newConfiguration, for: PIATunnelProfile.vpnType) pref.setVPNCustomConfiguration(newConfiguration, for: PIATunnelProfile.vpnType)
......
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