Commit 2d4ca87b authored by Davide De Rosa's avatar Davide De Rosa
Browse files

Implement OpenVPN UDP/TCP socket choice

Enforce UDP-only if flag is unset.
parent f7d0134b
......@@ -85,12 +85,21 @@ class Bootstrapper {
// as per App Store guidelines
let pref = Client.preferences.editable()
let tunnelConfiguration = pref.vpnCustomConfiguration(for: PIATunnelProfile.vpnType) as? PIATunnelProvider.Configuration
var tunnelConfigurationBuilder = tunnelConfiguration?.builder()
if !Flags.shared.enablesMACESetting {
pref.mace = false
}
if !Flags.shared.enablesRemotePortSetting {
pref.preferredPort = nil
}
if !Flags.shared.enablesSocketSetting {
pref.preferredPort = nil
tunnelConfigurationBuilder?.socketType = .udp
}
if let newConfiguration = tunnelConfigurationBuilder?.build() {
pref.setVPNCustomConfiguration(newConfiguration, for: PIATunnelProfile.vpnType)
}
pref.commit()
Client.bootstrap()
......
......@@ -28,6 +28,8 @@
<true/>
<key>enablesRemotePortSetting</key>
<true/>
<key>enablesSocketSetting</key>
<true/>
<key>enablesDevelopmentSettings</key>
<true/>
<key>customizesVPNRenegotiation</key>
......
......@@ -40,6 +40,8 @@ class Flags: NSObject {
@objc private(set) var enablesRemotePortSetting = true
@objc private(set) var enablesSocketSetting = false
@objc private(set) var enablesDevelopmentSettings = false
@objc private(set) var customizesVPNRenegotiation = false
......
......@@ -9,6 +9,12 @@
import Foundation
import PIATunnel
extension PIATunnelProvider.SocketType: CustomStringConvertible {
public var description: String {
return rawValue
}
}
extension PIATunnelProvider.Cipher: CustomStringConvertible {
public var description: String {
return rawValue
......
......@@ -623,10 +623,13 @@ extension SettingsViewController: UITableViewDataSource, UITableViewDelegate {
}
case .vpnSocket:
let configuration = currentOpenVPNConfiguration()
cell.textLabel?.text = L10n.Settings.Connection.SocketProtocol.title
cell.detailTextLabel?.text = "UDP" // TODO: hardcoded
cell.accessoryType = .none
cell.selectionStyle = .none
cell.detailTextLabel?.text = configuration.socketType.description
if !Flags.shared.enablesSocketSetting {
cell.accessoryType = .none
cell.selectionStyle = .none
}
case .vpnPort:
cell.textLabel?.text = L10n.Settings.Connection.RemotePort.title
......@@ -747,11 +750,26 @@ extension SettingsViewController: UITableViewDataSource, UITableViewDelegate {
controller?.options = options
controller?.selectedOption = pendingPreferences.vpnType
case .vpnSocket:
guard Flags.shared.enablesSocketSetting else {
break
}
let configuration = currentOpenVPNConfiguration()
let options: [PIATunnelProvider.SocketType] = [
.udp,
.tcp
]
controller = OptionsViewController()
controller?.options = options.map { $0.rawValue }
controller?.selectedOption = configuration.socketType.rawValue
case .vpnPort:
guard Flags.shared.enablesRemotePortSetting else {
break
}
var options = Client.providers.serverProvider.currentServersConfiguration.vpnPorts.udp
let configuration = currentOpenVPNConfiguration()
let availablePorts = Client.providers.serverProvider.currentServersConfiguration.vpnPorts
var options = (configuration.socketType == .udp) ? availablePorts.udp : availablePorts.tcp
options.insert(0, at: 0)
controller = OptionsViewController()
controller?.options = options
......@@ -883,6 +901,9 @@ extension SettingsViewController: OptionsViewControllerDelegate {
case .vpnProtocolSelection:
cell.textLabel?.text = (option as? String)?.vpnTypeDescription
case .vpnSocket:
cell.textLabel?.text = (option as? String)?.description
case .vpnPort:
if let port = option as? UInt16, (port > 0) {
cell.textLabel?.text = (option as? UInt16)?.description
......@@ -916,6 +937,7 @@ extension SettingsViewController: OptionsViewControllerDelegate {
var vpnHasChanged = false
var newVPNType: String?
var newSocketType: String?
var newPort: UInt16?
var newConfiguration: PIATunnelProvider.Configuration?
......@@ -924,6 +946,15 @@ extension SettingsViewController: OptionsViewControllerDelegate {
newVPNType = option as? String
vpnHasChanged = (newVPNType != pendingPreferences.vpnType)
case .vpnSocket:
newSocketType = option as? String
let configuration = currentOpenVPNConfiguration()
var newBuilder = configuration.builder()
newBuilder.socketType = PIATunnelProvider.SocketType(rawValue: newSocketType!)!
newConfiguration = newBuilder.build()
vpnHasChanged = (newConfiguration != configuration)
case .vpnPort:
newPort = option as? UInt16
vpnHasChanged = (newPort != pendingPreferences.preferredPort)
......@@ -957,6 +988,9 @@ extension SettingsViewController: OptionsViewControllerDelegate {
if let vpnType = newVPNType {
pendingPreferences.vpnType = vpnType
}
if let _ = newSocketType {
pendingPreferences.preferredPort = nil
}
if let port = newPort, (port > 0) {
pendingPreferences.preferredPort = port
} else {
......
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