From 87527ed290af299064e0216bdf229ab0b6c389b3 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 23 May 2019 23:13:45 +0200 Subject: [PATCH] Upgrade to TunnelKit 2.0 Major reorganization. No changes in logic. Rename by_* to pod_*. --- .../PacketTunnelProvider.swift | 2 +- Passepartout-iOS/AppDelegate.swift | 6 ++-- .../ConfigurationParserResult+Alerts.swift | 10 +++--- Passepartout-iOS/Global/IssueReporter.swift | 2 +- Passepartout-iOS/Global/Theme+Cells.swift | 2 +- .../ConfigurationModificationDelegate.swift | 2 +- .../Scenes/ConfigurationViewController.swift | 20 +++++------ .../ImportedHostsViewController.swift | 6 ++-- .../Organizer/WizardHostViewController.swift | 4 +-- .../Scenes/ServiceViewController.swift | 2 +- .../Sources/Model/ConnectionProfile.swift | 2 +- .../Sources/Model/ConnectionService.swift | 30 ++++++---------- Passepartout/Sources/Model/Credentials.swift | 2 +- .../Model/ProfileNetworkSettings.swift | 6 ++-- .../Profiles/HostConnectionProfile.swift | 8 ++--- .../PlaceholderConnectionProfile.swift | 2 +- .../Profiles/ProviderConnectionProfile.swift | 2 +- .../Model/SessionProxy+Communication.swift | 6 ++-- .../Sources/Model/TransientStore.swift | 6 ++-- .../Services/InfrastructurePreset.swift | 36 +++++++++---------- .../Sources/VPN/StandardVPNProvider.swift | 4 +-- Podfile | 9 +++-- Podfile.include | 6 ++-- Podfile.lock | 33 +++++++++++------ 24 files changed, 104 insertions(+), 104 deletions(-) diff --git a/Passepartout-iOS-Tunnel/PacketTunnelProvider.swift b/Passepartout-iOS-Tunnel/PacketTunnelProvider.swift index f3c423cb..a44d369a 100644 --- a/Passepartout-iOS-Tunnel/PacketTunnelProvider.swift +++ b/Passepartout-iOS-Tunnel/PacketTunnelProvider.swift @@ -25,7 +25,7 @@ import TunnelKit -class PacketTunnelProvider: TunnelKitProvider { +class PacketTunnelProvider: OpenVPNTunnelProvider { override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) { appVersion = "\(GroupConstants.App.name) \(GroupConstants.App.versionString)" dnsTimeout = GroupConstants.VPN.dnsTimeout diff --git a/Passepartout-iOS/AppDelegate.swift b/Passepartout-iOS/AppDelegate.swift index 65c5f0e2..466cf031 100644 --- a/Passepartout-iOS/AppDelegate.swift +++ b/Passepartout-iOS/AppDelegate.swift @@ -106,11 +106,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele let passphraseCancelBlock = { _ = try? FileManager.default.removeItem(at: url) } - guard let parsingResult = ConfigurationParser.Result.from(url, withErrorAlertIn: target, passphrase: passphrase, passphraseBlock: passphraseBlock, passphraseCancelBlock: passphraseCancelBlock) else { + guard let parsingResult = OpenVPN.ConfigurationParser.Result.from(url, withErrorAlertIn: target, passphrase: passphrase, passphraseBlock: passphraseBlock, passphraseCancelBlock: passphraseCancelBlock) else { return true } if let warning = parsingResult.warning { - ConfigurationParser.Result.alertImportWarning(url: url, in: target, withWarning: warning) { + OpenVPN.ConfigurationParser.Result.alertImportWarning(url: url, in: target, withWarning: warning) { if $0 { self.handleParsingResult(parsingResult, in: target) } else { @@ -123,7 +123,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele return true } - private func handleParsingResult(_ parsingResult: ConfigurationParser.Result, in target: UIViewController) { + private func handleParsingResult(_ parsingResult: OpenVPN.ConfigurationParser.Result, in target: UIViewController) { // already presented: update parsed configuration if let nav = target as? UINavigationController, let wizard = nav.topViewController as? WizardHostViewController { diff --git a/Passepartout-iOS/Global/ConfigurationParserResult+Alerts.swift b/Passepartout-iOS/Global/ConfigurationParserResult+Alerts.swift index 19ea7509..20746548 100644 --- a/Passepartout-iOS/Global/ConfigurationParserResult+Alerts.swift +++ b/Passepartout-iOS/Global/ConfigurationParserResult+Alerts.swift @@ -1,5 +1,5 @@ // -// ConfigurationParserResult+Alerts.swift +// OpenVPN.ConfigurationParserResult+Alerts.swift // Passepartout-iOS // // Created by Davide De Rosa on 10/27/18. @@ -31,16 +31,16 @@ import Passepartout_Core private let log = SwiftyBeaver.self -extension ConfigurationParser.Result { +extension OpenVPN.ConfigurationParser.Result { static func from(_ url: URL, withErrorAlertIn viewController: UIViewController, passphrase: String?, - passphraseBlock: @escaping (String) -> Void, passphraseCancelBlock: (() -> Void)?) -> ConfigurationParser.Result? { + passphraseBlock: @escaping (String) -> Void, passphraseCancelBlock: (() -> Void)?) -> OpenVPN.ConfigurationParser.Result? { - let result: ConfigurationParser.Result + let result: OpenVPN.ConfigurationParser.Result let fm = FileManager.default log.debug("Parsing configuration URL: \(url)") do { - result = try ConfigurationParser.parsed(fromURL: url, passphrase: passphrase) + result = try OpenVPN.ConfigurationParser.parsed(fromURL: url, passphrase: passphrase) } catch let e as ConfigurationError { switch e { case .encryptionPassphrase, .unableToDecrypt(_): diff --git a/Passepartout-iOS/Global/IssueReporter.swift b/Passepartout-iOS/Global/IssueReporter.swift index 6e422fd5..0d7ad96d 100644 --- a/Passepartout-iOS/Global/IssueReporter.swift +++ b/Passepartout-iOS/Global/IssueReporter.swift @@ -92,7 +92,7 @@ class IssueReporter: NSObject { } if let url = configurationURL { do { - let parsedFile = try ConfigurationParser.parsed(fromURL: url, returnsStripped: true) + let parsedFile = try OpenVPN.ConfigurationParser.parsed(fromURL: url, returnsStripped: true) if let attachment = parsedFile.strippedLines?.joined(separator: "\n").data(using: .utf8) { vc.addAttachmentData(attachment, mimeType: AppConstants.IssueReporter.MIME.configuration, fileName: AppConstants.IssueReporter.Filenames.configuration) } diff --git a/Passepartout-iOS/Global/Theme+Cells.swift b/Passepartout-iOS/Global/Theme+Cells.swift index 01824bbf..2e2bc097 100644 --- a/Passepartout-iOS/Global/Theme+Cells.swift +++ b/Passepartout-iOS/Global/Theme+Cells.swift @@ -75,7 +75,7 @@ extension SettingTableViewCell { accessoryType = .none } - func applyVPN(_ theme: Theme, with vpnStatus: VPNStatus?, error: TunnelKitProvider.ProviderError?) { + func applyVPN(_ theme: Theme, with vpnStatus: VPNStatus?, error: OpenVPNTunnelProvider.ProviderError?) { leftTextColor = theme.palette.primaryText guard let vpnStatus = vpnStatus else { rightText = L10n.Vpn.disabled diff --git a/Passepartout-iOS/Scenes/ConfigurationModificationDelegate.swift b/Passepartout-iOS/Scenes/ConfigurationModificationDelegate.swift index 80333546..bf8d0dbb 100644 --- a/Passepartout-iOS/Scenes/ConfigurationModificationDelegate.swift +++ b/Passepartout-iOS/Scenes/ConfigurationModificationDelegate.swift @@ -27,7 +27,7 @@ import Foundation import TunnelKit protocol ConfigurationModificationDelegate: class { - func configuration(didUpdate newConfiguration: SessionProxy.Configuration) + func configuration(didUpdate newConfiguration: OpenVPN.Configuration) func configurationShouldReinstall() } diff --git a/Passepartout-iOS/Scenes/ConfigurationViewController.swift b/Passepartout-iOS/Scenes/ConfigurationViewController.swift index d1f2c5f2..5b30553d 100644 --- a/Passepartout-iOS/Scenes/ConfigurationViewController.swift +++ b/Passepartout-iOS/Scenes/ConfigurationViewController.swift @@ -35,9 +35,9 @@ class ConfigurationViewController: UIViewController, TableModelHost { private lazy var itemRefresh = UIBarButtonItem(barButtonSystemItem: .refresh, target: self, action: #selector(refresh)) - var initialConfiguration: SessionProxy.Configuration! + var initialConfiguration: OpenVPN.Configuration! - private lazy var configuration: SessionProxy.ConfigurationBuilder = initialConfiguration.builder() + private lazy var configuration: OpenVPN.ConfigurationBuilder = initialConfiguration.builder() var originalConfigurationURL: URL? @@ -138,9 +138,9 @@ class ConfigurationViewController: UIViewController, TableModelHost { log.warning("Resetting with no original configuration set? Bad table model?") return } - let parsingResult: ConfigurationParser.Result + let parsingResult: OpenVPN.ConfigurationParser.Result do { - parsingResult = try ConfigurationParser.parsed(fromURL: originalURL) + parsingResult = try OpenVPN.ConfigurationParser.parsed(fromURL: originalURL) } catch let e { log.error("Could not parse original configuration: \(e)") return @@ -373,7 +373,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat switch model.row(at: indexPath) { case .cipher: - let vc = OptionViewController() + let vc = OptionViewController() vc.title = settingCell?.leftText vc.options = [.aes128cbc, .aes192cbc, .aes256cbc, .aes128gcm, .aes192gcm, .aes256gcm] vc.selectedOption = configuration.cipher @@ -385,7 +385,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat navigationController?.pushViewController(vc, animated: true) case .digest: - let vc = OptionViewController() + let vc = OptionViewController() vc.title = settingCell?.leftText vc.options = [.sha1, .sha224, .sha256, .sha384, .sha512] vc.selectedOption = configuration.digest @@ -397,7 +397,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat navigationController?.pushViewController(vc, animated: true) case .compressionFraming: - let vc = OptionViewController() + let vc = OptionViewController() vc.title = settingCell?.leftText vc.options = [.disabled, .compLZO, .compress] vc.selectedOption = configuration.compressionFraming ?? .disabled @@ -416,7 +416,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat return } - let vc = OptionViewController() + let vc = OptionViewController() vc.title = settingCell?.leftText vc.options = [.disabled, .LZO] vc.selectedOption = configuration.compressionAlgorithm ?? .disabled @@ -449,7 +449,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat // MARK: - -private extension SessionProxy.CompressionFraming { +private extension OpenVPN.CompressionFraming { var cellDescription: String { let V = L10n.Configuration.Cells.self switch self { @@ -465,7 +465,7 @@ private extension SessionProxy.CompressionFraming { } } -private extension SessionProxy.CompressionAlgorithm { +private extension OpenVPN.CompressionAlgorithm { var cellDescription: String { let V = L10n.Configuration.Cells.self switch self { diff --git a/Passepartout-iOS/Scenes/Organizer/ImportedHostsViewController.swift b/Passepartout-iOS/Scenes/Organizer/ImportedHostsViewController.swift index e06f607a..b262f1b3 100644 --- a/Passepartout-iOS/Scenes/Organizer/ImportedHostsViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/ImportedHostsViewController.swift @@ -33,7 +33,7 @@ private let log = SwiftyBeaver.self class ImportedHostsViewController: UITableViewController { private lazy var pendingConfigurationURLs = TransientStore.shared.service.pendingConfigurationURLs().sortedCaseInsensitive() - private var parsingResult: ConfigurationParser.Result? + private var parsingResult: OpenVPN.ConfigurationParser.Result? override func viewDidLoad() { super.viewDidLoad() @@ -88,7 +88,7 @@ class ImportedHostsViewController: UITableViewController { } self.perform(segue: StoryboardSegue.Organizer.importHostSegueIdentifier, sender: cell) } - guard let parsingResult = ConfigurationParser.Result.from(url, withErrorAlertIn: self, passphrase: passphrase, passphraseBlock: passphraseBlock, passphraseCancelBlock: nil) else { + guard let parsingResult = OpenVPN.ConfigurationParser.Result.from(url, withErrorAlertIn: self, passphrase: passphrase, passphraseBlock: passphraseBlock, passphraseCancelBlock: nil) else { deselectSelectedRow() return false } @@ -96,7 +96,7 @@ class ImportedHostsViewController: UITableViewController { // postpone segue until alert dismissal if let warning = parsingResult.warning { - ConfigurationParser.Result.alertImportWarning(url: url, in: self, withWarning: warning) { + OpenVPN.ConfigurationParser.Result.alertImportWarning(url: url, in: self, withWarning: warning) { self.deselectSelectedRow() if $0 { self.perform(segue: StoryboardSegue.Organizer.importHostSegueIdentifier) diff --git a/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift b/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift index 13a38000..9a769cfe 100644 --- a/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift @@ -37,7 +37,7 @@ class WizardHostViewController: UITableViewController, TableModelHost { return TransientStore.shared.service.ids(forContext: .host).sortedCaseInsensitive() }() - var parsingResult: ConfigurationParser.Result? { + var parsingResult: OpenVPN.ConfigurationParser.Result? { didSet { useSuggestedTitle() } @@ -104,7 +104,7 @@ class WizardHostViewController: UITableViewController, TableModelHost { } let profile = HostConnectionProfile(title: enteredTitle, hostname: hostname) - let builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: result.configuration) + let builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: result.configuration) profile.parameters = builder.build() let service = TransientStore.shared.service diff --git a/Passepartout-iOS/Scenes/ServiceViewController.swift b/Passepartout-iOS/Scenes/ServiceViewController.swift index 98837dec..f11a30bd 100644 --- a/Passepartout-iOS/Scenes/ServiceViewController.swift +++ b/Passepartout-iOS/Scenes/ServiceViewController.swift @@ -1217,7 +1217,7 @@ extension ServiceViewController: TrustedNetworksModelDelegate { // MARK: - extension ServiceViewController: ConfigurationModificationDelegate { - func configuration(didUpdate newConfiguration: SessionProxy.Configuration) { + func configuration(didUpdate newConfiguration: OpenVPN.Configuration) { if let hostProfile = profile as? HostConnectionProfile { var builder = hostProfile.parameters.builder() builder.sessionConfiguration = newConfiguration diff --git a/Passepartout/Sources/Model/ConnectionProfile.swift b/Passepartout/Sources/Model/ConnectionProfile.swift index 55603f27..04d7364c 100644 --- a/Passepartout/Sources/Model/ConnectionProfile.swift +++ b/Passepartout/Sources/Model/ConnectionProfile.swift @@ -46,7 +46,7 @@ public protocol ConnectionProfile: class, EndpointDataSource, CustomStringConver var manualNetworkSettings: ProfileNetworkSettings? { get set } - func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration + func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration func with(newId: String) -> ConnectionProfile } diff --git a/Passepartout/Sources/Model/ConnectionService.swift b/Passepartout/Sources/Model/ConnectionService.swift index 0c834a3e..5f553c34 100644 --- a/Passepartout/Sources/Model/ConnectionService.swift +++ b/Passepartout/Sources/Model/ConnectionService.swift @@ -89,7 +89,7 @@ public class ConnectionService: Codable { private let keychain: Keychain - public var baseConfiguration: TunnelKitProvider.Configuration + public var baseConfiguration: OpenVPNTunnelProvider.Configuration private var cache: [ProfileKey: ConnectionProfile] @@ -124,7 +124,7 @@ public class ConnectionService: Codable { public weak var delegate: ConnectionServiceDelegate? - public init(withAppGroup appGroup: String, baseConfiguration: TunnelKitProvider.Configuration) { + public init(withAppGroup appGroup: String, baseConfiguration: OpenVPNTunnelProvider.Configuration) { guard let defaults = UserDefaults(suiteName: appGroup) else { fatalError("No entitlements for group '\(appGroup)'") } @@ -157,7 +157,7 @@ public class ConnectionService: Codable { self.defaults = defaults keychain = Keychain(group: appGroup) - baseConfiguration = try container.decode(TunnelKitProvider.Configuration.self, forKey: .baseConfiguration) + baseConfiguration = try container.decode(OpenVPNTunnelProvider.Configuration.self, forKey: .baseConfiguration) activeProfileKey = try container.decodeIfPresent(ProfileKey.self, forKey: .activeProfileKey) preferences = try container.decode(EditablePreferences.self, forKey: .preferences) @@ -281,20 +281,10 @@ public class ConnectionService: Codable { profile = providerProfile case .host: - let hostProfile = try decoder.decode(HostConnectionProfile.self, from: data) - - // XXX: migrate old endpointProtocols - if hostProfile.parameters.sessionConfiguration.endpointProtocols == nil { - var sessionBuilder = hostProfile.parameters.sessionConfiguration.builder() - sessionBuilder.endpointProtocols = hostProfile.parameters.endpointProtocols - var parametersBuilder = hostProfile.parameters.builder() - parametersBuilder.sessionConfiguration = sessionBuilder.build() - hostProfile.parameters = parametersBuilder.build() - } - - // XXX: re-read routing policies for - - profile = hostProfile +// let hostProfile = try decoder.decode(HostConnectionProfile.self, from: data) +// +// profile = hostProfile + break } cache[key] = profile } catch let e { @@ -350,8 +340,8 @@ public class ConnectionService: Codable { } // can fail due to passphrase (migration is non-interactive) - if let result = try? ConfigurationParser.parsed(fromURL: url) { - host.parameters = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: result.configuration).build() + if let result = try? OpenVPN.ConfigurationParser.parsed(fromURL: url) { + host.parameters = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: result.configuration).build() } else { // fall back to the safer option @@ -602,7 +592,7 @@ public class ConnectionService: Codable { try? FileManager.default.removeItem(at: url) } - public var vpnLastError: TunnelKitProvider.ProviderError? { + public var vpnLastError: OpenVPNTunnelProvider.ProviderError? { return baseConfiguration.lastError(in: appGroup) } diff --git a/Passepartout/Sources/Model/Credentials.swift b/Passepartout/Sources/Model/Credentials.swift index 1225fc47..9735fdf5 100644 --- a/Passepartout/Sources/Model/Credentials.swift +++ b/Passepartout/Sources/Model/Credentials.swift @@ -26,7 +26,7 @@ import Foundation import TunnelKit -public typealias Credentials = SessionProxy.Credentials +public typealias Credentials = OpenVPN.Credentials public extension Credentials { var isEmpty: Bool { diff --git a/Passepartout/Sources/Model/ProfileNetworkSettings.swift b/Passepartout/Sources/Model/ProfileNetworkSettings.swift index 1a72af6d..2d643bfb 100644 --- a/Passepartout/Sources/Model/ProfileNetworkSettings.swift +++ b/Passepartout/Sources/Model/ProfileNetworkSettings.swift @@ -49,7 +49,7 @@ public class ProfileNetworkChoices: Codable { } public class ProfileNetworkSettings: Codable, CustomStringConvertible { - public var gatewayPolicies: [SessionProxy.RoutingPolicy]? + public var gatewayPolicies: [OpenVPN.RoutingPolicy]? public var dnsServers: [String]? @@ -72,7 +72,7 @@ public class ProfileNetworkSettings: Codable, CustomStringConvertible { gatewayPolicies = [.IPv4, .IPv6] } - public init(from configuration: SessionProxy.Configuration) { + public init(from configuration: OpenVPN.Configuration) { gatewayPolicies = configuration.routingPolicies dnsDomainName = configuration.searchDomain dnsServers = configuration.dnsServers @@ -114,7 +114,7 @@ public class ProfileNetworkSettings: Codable, CustomStringConvertible { } } -extension SessionProxy.ConfigurationBuilder { +extension OpenVPN.ConfigurationBuilder { public mutating func applyGateway(from choices: ProfileNetworkChoices, settings: ProfileNetworkSettings) { switch choices.gateway { case .client: diff --git a/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift b/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift index 7469bcb3..1b3bebcf 100644 --- a/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift +++ b/Passepartout/Sources/Model/Profiles/HostConnectionProfile.swift @@ -31,13 +31,13 @@ public class HostConnectionProfile: ConnectionProfile, Codable, Equatable { public let hostname: String - public var parameters: TunnelKitProvider.Configuration + public var parameters: OpenVPNTunnelProvider.Configuration public init(title: String, hostname: String) { self.title = title self.hostname = hostname - let sessionConfiguration = SessionProxy.ConfigurationBuilder().build() - parameters = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionConfiguration).build() + let sessionConfiguration = OpenVPN.ConfigurationBuilder().build() + parameters = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionConfiguration).build() } // MARK: ConnectionProfile @@ -58,7 +58,7 @@ public class HostConnectionProfile: ConnectionProfile, Codable, Equatable { public var manualNetworkSettings: ProfileNetworkSettings? - public func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration { + public func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration { guard let endpointProtocols = parameters.sessionConfiguration.endpointProtocols, !endpointProtocols.isEmpty else { preconditionFailure("No endpointProtocols") } diff --git a/Passepartout/Sources/Model/Profiles/PlaceholderConnectionProfile.swift b/Passepartout/Sources/Model/Profiles/PlaceholderConnectionProfile.swift index 43c267a1..5bd833bf 100644 --- a/Passepartout/Sources/Model/Profiles/PlaceholderConnectionProfile.swift +++ b/Passepartout/Sources/Model/Profiles/PlaceholderConnectionProfile.swift @@ -39,7 +39,7 @@ public class PlaceholderConnectionProfile: ConnectionProfile { public var manualNetworkSettings: ProfileNetworkSettings? - public func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration { + public func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration { fatalError("Generating configuration from a PlaceholderConnectionProfile") } diff --git a/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift b/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift index 04c76279..df928da2 100644 --- a/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift +++ b/Passepartout/Sources/Model/Profiles/ProviderConnectionProfile.swift @@ -114,7 +114,7 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable { return true } - public func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration { + public func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration { guard let pool = pool else { preconditionFailure("Nil pool?") } diff --git a/Passepartout/Sources/Model/SessionProxy+Communication.swift b/Passepartout/Sources/Model/SessionProxy+Communication.swift index ba8f0001..8e9a3e63 100644 --- a/Passepartout/Sources/Model/SessionProxy+Communication.swift +++ b/Passepartout/Sources/Model/SessionProxy+Communication.swift @@ -26,14 +26,14 @@ import Foundation import TunnelKit -public extension SessionProxy.ConfigurationBuilder { -// mutating func copyCommunication(from other: SessionProxy.ConfigurationBuilder) { +public extension OpenVPN.ConfigurationBuilder { +// mutating func copyCommunication(from other: OpenVPN.ConfigurationBuilder) { // cipher = other.cipher // digest = other.digest // compressionFraming = other.compressionFraming // } - func canCommunicate(with other: SessionProxy.Configuration) -> Bool { + func canCommunicate(with other: OpenVPN.Configuration) -> Bool { return (cipher == other.cipher) && ((digest == other.digest) || fallbackCipher.embedsDigest) && diff --git a/Passepartout/Sources/Model/TransientStore.swift b/Passepartout/Sources/Model/TransientStore.swift index 35aace91..3ec4c3cc 100644 --- a/Passepartout/Sources/Model/TransientStore.swift +++ b/Passepartout/Sources/Model/TransientStore.swift @@ -75,9 +75,9 @@ public class TransientStore { } } - public static var baseVPNConfiguration: TunnelKitProvider.ConfigurationBuilder { - let sessionBuilder = SessionProxy.ConfigurationBuilder() - var builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) + public static var baseVPNConfiguration: OpenVPNTunnelProvider.ConfigurationBuilder { + let sessionBuilder = OpenVPN.ConfigurationBuilder() + var builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) builder.mtu = 1250 builder.shouldDebug = true // builder.debugLogFormat = "$Dyyyy-MM-dd HH:mm:ss.SSS$d $L $N.$F:$l - $M" diff --git a/Passepartout/Sources/Services/InfrastructurePreset.swift b/Passepartout/Sources/Services/InfrastructurePreset.swift index 75b6da2e..0cb8caf3 100644 --- a/Passepartout/Sources/Services/InfrastructurePreset.swift +++ b/Passepartout/Sources/Services/InfrastructurePreset.swift @@ -26,7 +26,7 @@ import Foundation import TunnelKit -// supports a subset of TunnelKitProvider.Configuration +// supports a subset of OpenVPNTunnelProvider.Configuration // ignores new JSON keys public struct InfrastructurePreset: Codable { @@ -90,7 +90,7 @@ public struct InfrastructurePreset: Codable { public let comment: String - public let configuration: TunnelKitProvider.Configuration + public let configuration: OpenVPNTunnelProvider.Configuration public let external: [ExternalKey: String]? @@ -107,13 +107,13 @@ public struct InfrastructurePreset: Codable { case .ca: let filename = pattern.replacingOccurrences(of: "${id}", with: pool.id) let caURL = baseURL.appendingPathComponent(filename) - return CryptoContainer(pem: try String(contentsOf: caURL)) + return OpenVPN.CryptoContainer(pem: try String(contentsOf: caURL)) case .wrapKeyData: let filename = pattern.replacingOccurrences(of: "${id}", with: pool.id) let tlsKeyURL = baseURL.appendingPathComponent(filename) let file = try String(contentsOf: tlsKeyURL) - return StaticKey(file: file, direction: .client) + return OpenVPN.StaticKey(file: file, direction: .client) case .hostname: return pattern.replacingOccurrences(of: "${id}", with: pool.id) @@ -124,19 +124,19 @@ public struct InfrastructurePreset: Codable { return nil } - public func injectExternalConfiguration(_ configuration: inout TunnelKitProvider.ConfigurationBuilder, with infrastructureName: Infrastructure.Name, pool: Pool) throws { + public func injectExternalConfiguration(_ configuration: inout OpenVPNTunnelProvider.ConfigurationBuilder, with infrastructureName: Infrastructure.Name, pool: Pool) throws { guard let external = external, !external.isEmpty else { return } var sessionBuilder = configuration.sessionConfiguration.builder() if let _ = external[.ca] { - sessionBuilder.ca = try externalConfiguration(forKey: .ca, infrastructureName: infrastructureName, pool: pool) as? CryptoContainer + sessionBuilder.ca = try externalConfiguration(forKey: .ca, infrastructureName: infrastructureName, pool: pool) as? OpenVPN.CryptoContainer } if let _ = external[.wrapKeyData] { if let dummyWrap = sessionBuilder.tlsWrap { - if let staticKey = try externalConfiguration(forKey: .wrapKeyData, infrastructureName: infrastructureName, pool: pool) as? StaticKey { - sessionBuilder.tlsWrap = SessionProxy.TLSWrap(strategy: dummyWrap.strategy, key: staticKey) + if let staticKey = try externalConfiguration(forKey: .wrapKeyData, infrastructureName: infrastructureName, pool: pool) as? OpenVPN.StaticKey { + sessionBuilder.tlsWrap = OpenVPN.TLSWrap(strategy: dummyWrap.strategy, key: staticKey) } } } @@ -168,17 +168,17 @@ public struct InfrastructurePreset: Codable { let cfgContainer = try container.nestedContainer(keyedBy: ConfigurationKeys.self, forKey: .configuration) - var sessionBuilder = SessionProxy.ConfigurationBuilder() - sessionBuilder.cipher = try cfgContainer.decode(SessionProxy.Cipher.self, forKey: .cipher) - if let digest = try cfgContainer.decodeIfPresent(SessionProxy.Digest.self, forKey: .digest) { + var sessionBuilder = OpenVPN.ConfigurationBuilder() + sessionBuilder.cipher = try cfgContainer.decode(OpenVPN.Cipher.self, forKey: .cipher) + if let digest = try cfgContainer.decodeIfPresent(OpenVPN.Digest.self, forKey: .digest) { sessionBuilder.digest = digest } - sessionBuilder.compressionFraming = try cfgContainer.decode(SessionProxy.CompressionFraming.self, forKey: .compressionFraming) - sessionBuilder.compressionAlgorithm = try cfgContainer.decodeIfPresent(SessionProxy.CompressionAlgorithm.self, forKey: .compressionAlgorithm) ?? .disabled - sessionBuilder.ca = try cfgContainer.decodeIfPresent(CryptoContainer.self, forKey: .ca) - sessionBuilder.clientCertificate = try cfgContainer.decodeIfPresent(CryptoContainer.self, forKey: .clientCertificate) - sessionBuilder.clientKey = try cfgContainer.decodeIfPresent(CryptoContainer.self, forKey: .clientKey) - sessionBuilder.tlsWrap = try cfgContainer.decodeIfPresent(SessionProxy.TLSWrap.self, forKey: .tlsWrap) + sessionBuilder.compressionFraming = try cfgContainer.decode(OpenVPN.CompressionFraming.self, forKey: .compressionFraming) + sessionBuilder.compressionAlgorithm = try cfgContainer.decodeIfPresent(OpenVPN.CompressionAlgorithm.self, forKey: .compressionAlgorithm) ?? .disabled + sessionBuilder.ca = try cfgContainer.decodeIfPresent(OpenVPN.CryptoContainer.self, forKey: .ca) + sessionBuilder.clientCertificate = try cfgContainer.decodeIfPresent(OpenVPN.CryptoContainer.self, forKey: .clientCertificate) + sessionBuilder.clientKey = try cfgContainer.decodeIfPresent(OpenVPN.CryptoContainer.self, forKey: .clientKey) + sessionBuilder.tlsWrap = try cfgContainer.decodeIfPresent(OpenVPN.TLSWrap.self, forKey: .tlsWrap) sessionBuilder.keepAliveInterval = try cfgContainer.decodeIfPresent(TimeInterval.self, forKey: .keepAliveSeconds) sessionBuilder.renegotiatesAfter = try cfgContainer.decodeIfPresent(TimeInterval.self, forKey: .renegotiatesAfterSeconds) sessionBuilder.endpointProtocols = try cfgContainer.decode([EndpointProtocol].self, forKey: .endpointProtocols) @@ -189,7 +189,7 @@ public struct InfrastructurePreset: Codable { // default to server settings sessionBuilder.routingPolicies = nil - let builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) + let builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) configuration = builder.build() } diff --git a/Passepartout/Sources/VPN/StandardVPNProvider.swift b/Passepartout/Sources/VPN/StandardVPNProvider.swift index 73bc9d20..746e1a90 100644 --- a/Passepartout/Sources/VPN/StandardVPNProvider.swift +++ b/Passepartout/Sources/VPN/StandardVPNProvider.swift @@ -198,7 +198,7 @@ public class StandardVPNProvider: VPNProvider { return } do { - try session.sendProviderMessage(TunnelKitProvider.Message.dataCount.data) { (data) in + try session.sendProviderMessage(OpenVPNTunnelProvider.Message.dataCount.data) { (data) in guard let data = data, data.count == 16 else { DispatchQueue.main.async { completionHandler(nil) @@ -250,7 +250,7 @@ public class StandardVPNProvider: VPNProvider { private static func requestDebugLog(session: NETunnelProviderSession, completionHandler: @escaping (String?) -> Void) { do { - try session.sendProviderMessage(TunnelKitProvider.Message.requestLog.data) { (data) in + try session.sendProviderMessage(OpenVPNTunnelProvider.Message.requestLog.data) { (data) in guard let data = data, !data.isEmpty else { completionHandler(nil) return diff --git a/Podfile b/Podfile index 826862da..b5830bff 100644 --- a/Podfile +++ b/Podfile @@ -5,13 +5,12 @@ use_frameworks! load 'Podfile.include' $tunnelkit_name = 'TunnelKit' -$tunnelkit_specs = ['Core', 'AppExtension', 'LZO'] -#$tunnelkit_specs = ['OpenVPN', 'LZO'] +$tunnelkit_specs = ['Protocols/OpenVPN', 'Extra/LZO'] def shared_pods - by_version('~> 1.7.1', $tunnelkit_name, $tunnelkit_specs) - #by_git('d06b2e1', $tunnelkit_name, $tunnelkit_specs) - #by_path('..', $tunnelkit_name, $tunnelkit_specs) + #pod_version $tunnelkit_name, $tunnelkit_specs, '~> 2.0.0' + pod_git $tunnelkit_name, $tunnelkit_specs, 'f3edd6e' + #pod_path $tunnelkit_name, $tunnelkit_specs, '..' pod 'SSZipArchive' end diff --git a/Podfile.include b/Podfile.include index 999cd34d..34817cbc 100644 --- a/Podfile.include +++ b/Podfile.include @@ -1,18 +1,18 @@ $git_root = "https://github.com/passepartoutvpn" -def by_version(version, name, specs) +def pod_version(name, specs, version) specs.each { |s| pod "#{name}/#{s}", version } end -def by_git(sha, name, specs) +def pod_git(name, specs, sha) specs.each { |s| pod "#{name}/#{s}", :git => "#{$git_root}/#{name.downcase}", :commit => sha } end -def by_path(root, name, specs) +def pod_path(name, specs, root) specs.each { |s| pod "#{name}/#{s}", :path => "#{root}/#{name.downcase}" } diff --git a/Podfile.lock b/Podfile.lock index bd71d838..6a47fa6b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,22 +1,24 @@ PODS: - MBProgressHUD (1.1.0) - OpenSSL-Apple (1.1.0j.2) - - SSZipArchive (2.1.4) + - SSZipArchive (2.2.1) - SwiftyBeaver (1.7.0) - - TunnelKit/AppExtension (1.7.1): + - TunnelKit/AppExtension (2.0.0): - SwiftyBeaver - TunnelKit/Core - - TunnelKit/Core (1.7.1): + - TunnelKit/Core (2.0.0): - OpenSSL-Apple (~> 1.1.0j.2) - SwiftyBeaver - - TunnelKit/LZO (1.7.1) + - TunnelKit/Extra/LZO (2.0.0) + - TunnelKit/Protocols/OpenVPN (2.0.0): + - TunnelKit/AppExtension + - TunnelKit/Core DEPENDENCIES: - MBProgressHUD - SSZipArchive - - TunnelKit/AppExtension (~> 1.7.1) - - TunnelKit/Core (~> 1.7.1) - - TunnelKit/LZO (~> 1.7.1) + - TunnelKit/Extra/LZO (from `https://github.com/passepartoutvpn/tunnelkit`, commit `f3edd6e`) + - TunnelKit/Protocols/OpenVPN (from `https://github.com/passepartoutvpn/tunnelkit`, commit `f3edd6e`) SPEC REPOS: https://github.com/cocoapods/specs.git: @@ -24,15 +26,24 @@ SPEC REPOS: - OpenSSL-Apple - SSZipArchive - SwiftyBeaver - - TunnelKit + +EXTERNAL SOURCES: + TunnelKit: + :commit: f3edd6e + :git: https://github.com/passepartoutvpn/tunnelkit + +CHECKOUT OPTIONS: + TunnelKit: + :commit: f3edd6e + :git: https://github.com/passepartoutvpn/tunnelkit SPEC CHECKSUMS: MBProgressHUD: e7baa36a220447d8aeb12769bf0585582f3866d9 OpenSSL-Apple: e88e1eb314acb4a05e2348069790c4aa49f6d319 - SSZipArchive: 41455d4b8d2b6ab93990820b50dc697c2554a322 + SSZipArchive: 8e859da2520142e09166bc9161967db296e9d02f SwiftyBeaver: 4cc0080d2e23f980652e28978db11a5c9da39165 - TunnelKit: d1e02dea5cb58ea0d4dbfcdcb387e653d148d800 + TunnelKit: 821c15bb87aafae69eb8c63e4cc46d883fff8797 -PODFILE CHECKSUM: fad46c04b9c9bee54cc740d6a4af257553ff635f +PODFILE CHECKSUM: b45e8f98f20b6c63f2735d1f038fb2e415601fbd COCOAPODS: 1.6.1