Upgrade to TunnelKit 1.6.0

- Make cipher/digest/compressionFraming optional
- Move endpointProtocols inside SessionProxy.Configuration
- Rename OptionsError to ConfigurationError
This commit is contained in:
Davide De Rosa 2019-04-04 11:21:51 +02:00
parent cb2917a0a8
commit 1904687a22
11 changed files with 71 additions and 47 deletions

View File

@ -41,7 +41,7 @@ extension ConfigurationParser.ParsingResult {
log.debug("Parsing configuration URL: \(url)") log.debug("Parsing configuration URL: \(url)")
do { do {
result = try ConfigurationParser.parsed(fromURL: url, passphrase: passphrase) result = try ConfigurationParser.parsed(fromURL: url, passphrase: passphrase)
} catch let e as ConfigurationParser.ParsingError { } catch let e as ConfigurationError {
switch e { switch e {
case .encryptionPassphrase, .unableToDecrypt(_): case .encryptionPassphrase, .unableToDecrypt(_):
let alert = Macros.alert(url.normalizedFilename, L10n.ParsedFile.Alerts.EncryptionPassphrase.message) let alert = Macros.alert(url.normalizedFilename, L10n.ParsedFile.Alerts.EncryptionPassphrase.message)
@ -85,7 +85,7 @@ extension ConfigurationParser.ParsingResult {
vc.present(alert, animated: true, completion: nil) vc.present(alert, animated: true, completion: nil)
} }
static func alertImportWarning(url: URL, in vc: UIViewController, withWarning warning: ConfigurationParser.ParsingError, completionHandler: @escaping (Bool) -> Void) { static func alertImportWarning(url: URL, in vc: UIViewController, withWarning warning: ConfigurationError, completionHandler: @escaping (Bool) -> Void) {
let message = details(forWarning: warning) let message = details(forWarning: warning)
let alert = Macros.alert(url.normalizedFilename, L10n.ParsedFile.Alerts.PotentiallyUnsupported.message(message)) let alert = Macros.alert(url.normalizedFilename, L10n.ParsedFile.Alerts.PotentiallyUnsupported.message(message))
alert.addDefaultAction(L10n.Global.ok) { alert.addDefaultAction(L10n.Global.ok) {
@ -98,8 +98,12 @@ extension ConfigurationParser.ParsingResult {
} }
private static func localizedMessage(forError error: Error) -> String { private static func localizedMessage(forError error: Error) -> String {
if let appError = error as? ConfigurationParser.ParsingError { if let appError = error as? ConfigurationError {
switch appError { switch appError {
case .malformed(let option):
log.error("Could not parse configuration URL: malformed option, \(option)")
return L10n.ParsedFile.Alerts.Malformed.message(option)
case .missingConfiguration(let option): case .missingConfiguration(let option):
log.error("Could not parse configuration URL: missing configuration, \(option)") log.error("Could not parse configuration URL: missing configuration, \(option)")
return L10n.ParsedFile.Alerts.Missing.message(option) return L10n.ParsedFile.Alerts.Missing.message(option)
@ -116,8 +120,11 @@ extension ConfigurationParser.ParsingResult {
return L10n.ParsedFile.Alerts.Parsing.message(error.localizedDescription) return L10n.ParsedFile.Alerts.Parsing.message(error.localizedDescription)
} }
private static func details(forWarning warning: ConfigurationParser.ParsingError) -> String { private static func details(forWarning warning: ConfigurationError) -> String {
switch warning { switch warning {
case .malformed(let option):
return option
case .missingConfiguration(let option): case .missingConfiguration(let option):
return option return option

View File

@ -99,10 +99,12 @@ class WizardHostViewController: UITableViewController, TableModelHost {
guard let result = parsingResult else { guard let result = parsingResult else {
return return
} }
guard let hostname = result.configuration.hostname else {
let profile = HostConnectionProfile(title: enteredTitle, hostname: result.hostname) return
var builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: result.configuration) }
builder.endpointProtocols = result.protocols
let profile = HostConnectionProfile(title: enteredTitle, hostname: hostname)
let builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: result.configuration)
profile.parameters = builder.build() profile.parameters = builder.build()
let service = TransientStore.shared.service let service = TransientStore.shared.service

View File

@ -56,6 +56,7 @@
"wizards.host.sections.existing.header" = "Existing profiles"; "wizards.host.sections.existing.header" = "Existing profiles";
"wizards.host.alerts.existing.message" = "A host profile with the same title already exists. Replace it?"; "wizards.host.alerts.existing.message" = "A host profile with the same title already exists. Replace it?";
"parsed_file.alerts.malformed.message" = "The configuration file contains a malformed option (%@).";
"parsed_file.alerts.missing.message" = "The configuration file lacks a required option (%@)."; "parsed_file.alerts.missing.message" = "The configuration file lacks a required option (%@).";
"parsed_file.alerts.unsupported.message" = "The configuration file contains an unsupported option (%@)."; "parsed_file.alerts.unsupported.message" = "The configuration file contains an unsupported option (%@).";
"parsed_file.alerts.potentially_unsupported.message" = "The configuration file is correct but contains a potentially unsupported option (%@).\n\nConnectivity may break depending on server settings."; "parsed_file.alerts.potentially_unsupported.message" = "The configuration file is correct but contains a potentially unsupported option (%@).\n\nConnectivity may break depending on server settings.";

View File

@ -36,7 +36,7 @@ public class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
public init(title: String, hostname: String) { public init(title: String, hostname: String) {
self.title = title self.title = title
self.hostname = hostname self.hostname = hostname
let sessionConfiguration = SessionProxy.ConfigurationBuilder(ca: CryptoContainer(pem: "")).build() let sessionConfiguration = SessionProxy.ConfigurationBuilder().build()
parameters = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionConfiguration).build() parameters = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionConfiguration).build()
} }
@ -55,7 +55,9 @@ public class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
} }
public func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration { public func generate(from configuration: TunnelKitProvider.Configuration, preferences: Preferences) throws -> TunnelKitProvider.Configuration {
precondition(!parameters.endpointProtocols.isEmpty) guard let endpointProtocols = parameters.sessionConfiguration.endpointProtocols, !endpointProtocols.isEmpty else {
preconditionFailure("No endpointProtocols")
}
// XXX: copy paste, error prone // XXX: copy paste, error prone
var builder = parameters.builder() var builder = parameters.builder()
@ -91,7 +93,7 @@ public extension HostConnectionProfile {
} }
var protocols: [EndpointProtocol] { var protocols: [EndpointProtocol] {
return parameters.endpointProtocols return parameters.sessionConfiguration.endpointProtocols ?? []
} }
var canCustomizeEndpoint: Bool { var canCustomizeEndpoint: Bool {

View File

@ -130,10 +130,10 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
} }
if let proto = manualProtocol { if let proto = manualProtocol {
builder.endpointProtocols = [proto] builder.sessionConfiguration.endpointProtocols = [proto]
} else { } else {
builder.endpointProtocols = preset.configuration.endpointProtocols builder.sessionConfiguration.endpointProtocols = preset.configuration.sessionConfiguration.endpointProtocols
// builder.endpointProtocols = [ // builder.sessionConfiguration.endpointProtocols = [
// EndpointProtocol(.udp, 8080), // EndpointProtocol(.udp, 8080),
// EndpointProtocol(.tcp, 443) // EndpointProtocol(.tcp, 443)
// ] // ]
@ -163,7 +163,7 @@ public extension ProviderConnectionProfile {
} }
var protocols: [EndpointProtocol] { var protocols: [EndpointProtocol] {
return preset?.configuration.endpointProtocols ?? [] return preset?.configuration.sessionConfiguration.endpointProtocols ?? []
} }
var canCustomizeEndpoint: Bool { var canCustomizeEndpoint: Bool {

View File

@ -63,7 +63,7 @@ public class TransientStore {
} }
public static var baseVPNConfiguration: TunnelKitProvider.ConfigurationBuilder { public static var baseVPNConfiguration: TunnelKitProvider.ConfigurationBuilder {
let sessionBuilder = SessionProxy.ConfigurationBuilder(ca: CryptoContainer(pem: "")) let sessionBuilder = SessionProxy.ConfigurationBuilder()
var builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) var builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build())
builder.mtu = 1250 builder.mtu = 1250
builder.shouldDebug = true builder.shouldDebug = true

View File

@ -79,7 +79,7 @@ public struct InfrastructurePreset: Codable {
public let configuration: TunnelKitProvider.Configuration public let configuration: TunnelKitProvider.Configuration
public func hasProtocol(_ proto: EndpointProtocol) -> Bool { public func hasProtocol(_ proto: EndpointProtocol) -> Bool {
return configuration.endpointProtocols.index(of: proto) != nil return configuration.sessionConfiguration.endpointProtocols?.index(of: proto) != nil
} }
// MARK: Codable // MARK: Codable
@ -91,50 +91,56 @@ public struct InfrastructurePreset: Codable {
comment = try container.decode(String.self, forKey: .comment) comment = try container.decode(String.self, forKey: .comment)
let cfgContainer = try container.nestedContainer(keyedBy: ConfigurationKeys.self, forKey: .configuration) let cfgContainer = try container.nestedContainer(keyedBy: ConfigurationKeys.self, forKey: .configuration)
let ca = try cfgContainer.decode(CryptoContainer.self, forKey: .ca)
var sessionBuilder = SessionProxy.ConfigurationBuilder(ca: ca) var sessionBuilder = SessionProxy.ConfigurationBuilder()
sessionBuilder.cipher = try cfgContainer.decode(SessionProxy.Cipher.self, forKey: .cipher) sessionBuilder.cipher = try cfgContainer.decode(SessionProxy.Cipher.self, forKey: .cipher)
if let digest = try cfgContainer.decodeIfPresent(SessionProxy.Digest.self, forKey: .digest) { if let digest = try cfgContainer.decodeIfPresent(SessionProxy.Digest.self, forKey: .digest) {
sessionBuilder.digest = digest sessionBuilder.digest = digest
} }
sessionBuilder.clientCertificate = try cfgContainer.decodeIfPresent(CryptoContainer.self, forKey: .clientCertificate)
sessionBuilder.clientKey = try cfgContainer.decodeIfPresent(CryptoContainer.self, forKey: .clientKey)
sessionBuilder.compressionFraming = try cfgContainer.decode(SessionProxy.CompressionFraming.self, forKey: .compressionFraming) sessionBuilder.compressionFraming = try cfgContainer.decode(SessionProxy.CompressionFraming.self, forKey: .compressionFraming)
sessionBuilder.compressionAlgorithm = try cfgContainer.decodeIfPresent(SessionProxy.CompressionAlgorithm.self, forKey: .compressionAlgorithm) ?? .disabled sessionBuilder.compressionAlgorithm = try cfgContainer.decodeIfPresent(SessionProxy.CompressionAlgorithm.self, forKey: .compressionAlgorithm) ?? .disabled
sessionBuilder.ca = try cfgContainer.decode(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.tlsWrap = try cfgContainer.decodeIfPresent(SessionProxy.TLSWrap.self, forKey: .tlsWrap)
sessionBuilder.keepAliveInterval = try cfgContainer.decodeIfPresent(TimeInterval.self, forKey: .keepAliveSeconds) sessionBuilder.keepAliveInterval = try cfgContainer.decodeIfPresent(TimeInterval.self, forKey: .keepAliveSeconds)
sessionBuilder.renegotiatesAfter = try cfgContainer.decodeIfPresent(TimeInterval.self, forKey: .renegotiatesAfterSeconds) sessionBuilder.renegotiatesAfter = try cfgContainer.decodeIfPresent(TimeInterval.self, forKey: .renegotiatesAfterSeconds)
sessionBuilder.usesPIAPatches = try cfgContainer.decodeIfPresent(Bool.self, forKey: .usesPIAPatches) ?? false sessionBuilder.endpointProtocols = try cfgContainer.decode([EndpointProtocol].self, forKey: .endpointProtocols)
sessionBuilder.checksEKU = try cfgContainer.decodeIfPresent(Bool.self, forKey: .checksEKU) ?? false sessionBuilder.checksEKU = try cfgContainer.decodeIfPresent(Bool.self, forKey: .checksEKU) ?? false
sessionBuilder.randomizeEndpoint = try cfgContainer.decodeIfPresent(Bool.self, forKey: .randomizeEndpoint) ?? false sessionBuilder.randomizeEndpoint = try cfgContainer.decodeIfPresent(Bool.self, forKey: .randomizeEndpoint) ?? false
sessionBuilder.usesPIAPatches = try cfgContainer.decodeIfPresent(Bool.self, forKey: .usesPIAPatches) ?? false
var builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) let builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build())
builder.endpointProtocols = try cfgContainer.decode([EndpointProtocol].self, forKey: .endpointProtocols)
configuration = builder.build() configuration = builder.build()
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
guard let ca = configuration.sessionConfiguration.ca else {
fatalError("Could not encode nil ca")
}
guard let endpointProtocols = configuration.sessionConfiguration.endpointProtocols else {
fatalError("Could not encode nil endpointProtocols")
}
var container = encoder.container(keyedBy: PresetKeys.self) var container = encoder.container(keyedBy: PresetKeys.self)
try container.encode(id, forKey: .id) try container.encode(id, forKey: .id)
try container.encode(name, forKey: .name) try container.encode(name, forKey: .name)
try container.encode(comment, forKey: .comment) try container.encode(comment, forKey: .comment)
var cfgContainer = container.nestedContainer(keyedBy: ConfigurationKeys.self, forKey: .configuration) var cfgContainer = container.nestedContainer(keyedBy: ConfigurationKeys.self, forKey: .configuration)
try cfgContainer.encode(configuration.endpointProtocols, forKey: .endpointProtocols)
try cfgContainer.encode(configuration.sessionConfiguration.cipher, forKey: .cipher) try cfgContainer.encode(configuration.sessionConfiguration.cipher, forKey: .cipher)
try cfgContainer.encode(configuration.sessionConfiguration.digest, forKey: .digest) try cfgContainer.encode(configuration.sessionConfiguration.digest, forKey: .digest)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.ca, forKey: .ca)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.clientCertificate, forKey: .clientCertificate)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.clientKey, forKey: .clientKey)
try cfgContainer.encode(configuration.sessionConfiguration.compressionFraming, forKey: .compressionFraming) try cfgContainer.encode(configuration.sessionConfiguration.compressionFraming, forKey: .compressionFraming)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.compressionAlgorithm, forKey: .compressionAlgorithm) try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.compressionAlgorithm, forKey: .compressionAlgorithm)
try cfgContainer.encode(ca, forKey: .ca)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.clientCertificate, forKey: .clientCertificate)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.clientKey, forKey: .clientKey)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.tlsWrap, forKey: .tlsWrap) try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.tlsWrap, forKey: .tlsWrap)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.keepAliveInterval, forKey: .keepAliveSeconds) try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.keepAliveInterval, forKey: .keepAliveSeconds)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.renegotiatesAfter, forKey: .renegotiatesAfterSeconds) try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.renegotiatesAfter, forKey: .renegotiatesAfterSeconds)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.usesPIAPatches, forKey: .usesPIAPatches) try cfgContainer.encode(endpointProtocols, forKey: .endpointProtocols)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.checksEKU, forKey: .checksEKU) try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.checksEKU, forKey: .checksEKU)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.randomizeEndpoint, forKey: .randomizeEndpoint) try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.randomizeEndpoint, forKey: .randomizeEndpoint)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.usesPIAPatches, forKey: .usesPIAPatches)
} }
} }

View File

@ -419,6 +419,12 @@ public enum L10n {
/// Please enter the encryption passphrase. /// Please enter the encryption passphrase.
public static let message = L10n.tr("Localizable", "parsed_file.alerts.encryption_passphrase.message") public static let message = L10n.tr("Localizable", "parsed_file.alerts.encryption_passphrase.message")
} }
public enum Malformed {
/// The configuration file contains a malformed option (%@).
public static func message(_ p1: String) -> String {
return L10n.tr("Localizable", "parsed_file.alerts.malformed.message", p1)
}
}
public enum Missing { public enum Missing {
/// The configuration file lacks a required option (%@). /// The configuration file lacks a required option (%@).
public static func message(_ p1: String) -> String { public static func message(_ p1: String) -> String {

View File

@ -3,10 +3,10 @@ platform :ios, '11.0'
use_frameworks! use_frameworks!
def shared_pods def shared_pods
#pod 'TunnelKit', '~> 1.5.0' #pod 'TunnelKit', '~> 1.6.0'
#pod 'TunnelKit/LZO', '~> 1.5.0' #pod 'TunnelKit/LZO', '~> 1.6.0'
pod 'TunnelKit', :git => 'https://github.com/keeshux/tunnelkit', :commit => 'ccb6329' pod 'TunnelKit', :git => 'https://github.com/keeshux/tunnelkit', :commit => '7333ea2'
pod 'TunnelKit/LZO', :git => 'https://github.com/keeshux/tunnelkit', :commit => 'ccb6329' pod 'TunnelKit/LZO', :git => 'https://github.com/keeshux/tunnelkit', :commit => '7333ea2'
#pod 'TunnelKit', :path => '../../personal/tunnelkit' #pod 'TunnelKit', :path => '../../personal/tunnelkit'
#pod 'TunnelKit/LZO', :path => '../../personal/tunnelkit' #pod 'TunnelKit/LZO', :path => '../../personal/tunnelkit'
end end

View File

@ -2,21 +2,21 @@ PODS:
- MBProgressHUD (1.1.0) - MBProgressHUD (1.1.0)
- OpenSSL-Apple (1.1.0i.2) - OpenSSL-Apple (1.1.0i.2)
- SwiftyBeaver (1.7.0) - SwiftyBeaver (1.7.0)
- TunnelKit (1.5.3): - TunnelKit (1.6.0):
- TunnelKit/AppExtension (= 1.5.3) - TunnelKit/AppExtension (= 1.6.0)
- TunnelKit/Core (= 1.5.3) - TunnelKit/Core (= 1.6.0)
- TunnelKit/AppExtension (1.5.3): - TunnelKit/AppExtension (1.6.0):
- SwiftyBeaver - SwiftyBeaver
- TunnelKit/Core - TunnelKit/Core
- TunnelKit/Core (1.5.3): - TunnelKit/Core (1.6.0):
- OpenSSL-Apple (~> 1.1.0i.2) - OpenSSL-Apple (~> 1.1.0i.2)
- SwiftyBeaver - SwiftyBeaver
- TunnelKit/LZO (1.5.3) - TunnelKit/LZO (1.6.0)
DEPENDENCIES: DEPENDENCIES:
- MBProgressHUD - MBProgressHUD
- TunnelKit (from `https://github.com/keeshux/tunnelkit`, commit `ccb6329`) - TunnelKit (from `https://github.com/keeshux/tunnelkit`, commit `7333ea2`)
- TunnelKit/LZO (from `https://github.com/keeshux/tunnelkit`, commit `ccb6329`) - TunnelKit/LZO (from `https://github.com/keeshux/tunnelkit`, commit `7333ea2`)
SPEC REPOS: SPEC REPOS:
https://github.com/cocoapods/specs.git: https://github.com/cocoapods/specs.git:
@ -26,20 +26,20 @@ SPEC REPOS:
EXTERNAL SOURCES: EXTERNAL SOURCES:
TunnelKit: TunnelKit:
:commit: ccb6329 :commit: 7333ea2
:git: https://github.com/keeshux/tunnelkit :git: https://github.com/keeshux/tunnelkit
CHECKOUT OPTIONS: CHECKOUT OPTIONS:
TunnelKit: TunnelKit:
:commit: ccb6329 :commit: 7333ea2
:git: https://github.com/keeshux/tunnelkit :git: https://github.com/keeshux/tunnelkit
SPEC CHECKSUMS: SPEC CHECKSUMS:
MBProgressHUD: e7baa36a220447d8aeb12769bf0585582f3866d9 MBProgressHUD: e7baa36a220447d8aeb12769bf0585582f3866d9
OpenSSL-Apple: 37a8c0b04df4bb8971deef4671cc29222861319c OpenSSL-Apple: 37a8c0b04df4bb8971deef4671cc29222861319c
SwiftyBeaver: 4cc0080d2e23f980652e28978db11a5c9da39165 SwiftyBeaver: 4cc0080d2e23f980652e28978db11a5c9da39165
TunnelKit: 21f5d336698d2de6126232f6b5d7e9be4d999af0 TunnelKit: cd10ff6f4368e82414a72e6a111dae369252964e
PODFILE CHECKSUM: cc0564f2cee9d614d40e73ea13d19c96e0ddb1f2 PODFILE CHECKSUM: ab7fe69f86411d5848909b12bfeb846d738d004d
COCOAPODS: 1.6.1 COCOAPODS: 1.6.1

View File

@ -3,7 +3,7 @@
# [Passepartout][about-website] # [Passepartout][about-website]
![iOS 11+](https://img.shields.io/badge/ios-11+-green.svg) ![iOS 11+](https://img.shields.io/badge/ios-11+-green.svg)
[![TunnelKit 1.5.x](https://img.shields.io/badge/tunnelkit-1.5-d69c68.svg)][dep-tunnelkit] [![TunnelKit 1.6.x](https://img.shields.io/badge/tunnelkit-1.6-d69c68.svg)][dep-tunnelkit]
[![License GPLv3](https://img.shields.io/badge/license-GPLv3-lightgray.svg)](LICENSE) [![License GPLv3](https://img.shields.io/badge/license-GPLv3-lightgray.svg)](LICENSE)
[![Join Reddit](https://img.shields.io/badge/discuss-Reddit-orange.svg)][about-reddit] [![Join Reddit](https://img.shields.io/badge/discuss-Reddit-orange.svg)][about-reddit]
[![Join Telegram](https://img.shields.io/badge/chat-Telegram-blue.svg)][about-telegram] [![Join Telegram](https://img.shields.io/badge/chat-Telegram-blue.svg)][about-telegram]