Upgrade TunnelKit with configuration refactoring

This commit is contained in:
Davide De Rosa 2018-10-25 20:08:22 +02:00
parent ae9c32e9f5
commit 542a3e3721
13 changed files with 82 additions and 72 deletions

View File

@ -27,7 +27,7 @@ import Foundation
import TunnelKit
protocol ConfigurationModificationDelegate: class {
func configuration(didUpdate newConfiguration: TunnelKitProvider.Configuration)
func configuration(didUpdate newConfiguration: SessionProxy.Configuration)
func configurationShouldReinstall()
}

View File

@ -34,9 +34,9 @@ class ConfigurationViewController: UIViewController, TableModelHost {
private lazy var itemRefresh = UIBarButtonItem(barButtonSystemItem: .refresh, target: self, action: #selector(refresh))
var initialConfiguration: TunnelKitProvider.Configuration!
var initialConfiguration: SessionProxy.Configuration!
private lazy var configuration: TunnelKitProvider.ConfigurationBuilder = initialConfiguration.builder()
private lazy var configuration: SessionProxy.ConfigurationBuilder = initialConfiguration.builder()
var isEditable = false
@ -129,12 +129,12 @@ class ConfigurationViewController: UIViewController, TableModelHost {
log.warning("Could not parse original configuration: \(e)")
return
}
initialConfiguration = originalConfiguration
configuration = originalConfiguration.builder()
initialConfiguration = originalConfiguration.sessionConfiguration
configuration = initialConfiguration.builder()
itemRefresh.isEnabled = true // allow for manual reconnection
tableView.reloadData()
delegate?.configuration(didUpdate: originalConfiguration)
delegate?.configuration(didUpdate: initialConfiguration)
}
@IBAction private func refresh() {
@ -270,8 +270,8 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
case .keepAlive:
cell.leftText = L10n.Configuration.Cells.KeepAlive.caption
let V = L10n.Configuration.Cells.KeepAlive.Value.self
if let keepAlive = configuration.keepAliveSeconds, keepAlive > 0 {
cell.rightText = V.seconds(keepAlive)
if let keepAlive = configuration.keepAliveInterval, keepAlive > 0 {
cell.rightText = V.seconds(Int(keepAlive))
} else {
cell.rightText = V.never
}
@ -281,7 +281,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
case .renegSeconds:
cell.leftText = L10n.Configuration.Cells.RenegotiationSeconds.caption
let V = L10n.Configuration.Cells.RenegotiationSeconds.Value.self
if let reneg = configuration.renegotiatesAfterSeconds, reneg > 0 {
if let reneg = configuration.renegotiatesAfter, reneg > 0 {
cell.rightText = V.after(TimeInterval(reneg).localized)
} else {
cell.rightText = V.never

View File

@ -129,7 +129,7 @@ extension ProviderPresetViewController: UITableViewDataSource, UITableViewDelega
case .techDetails:
let vc = StoryboardScene.Main.configurationIdentifier.instantiate()
vc.title = preset.name
vc.initialConfiguration = preset.configuration
vc.initialConfiguration = preset.configuration.sessionConfiguration
navigationController?.pushViewController(vc, animated: true)
}
}

View File

@ -153,7 +153,7 @@ class ServiceViewController: UIViewController, TableModelHost {
case .hostParametersSegueIdentifier:
let vc = destination as? ConfigurationViewController
vc?.title = L10n.Service.Cells.Host.Parameters.caption
vc?.initialConfiguration = uncheckedHostProfile.parameters
vc?.initialConfiguration = uncheckedHostProfile.parameters.sessionConfiguration
vc?.isEditable = true
vc?.originalConfigurationURL = ProfileConfigurationFactory.shared.configurationURL(for: uncheckedHostProfile)
vc?.delegate = self
@ -595,10 +595,10 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.leftText = L10n.Service.Cells.Host.Parameters.caption
let V = L10n.Service.Cells.Host.Parameters.Value.self
if !parameters.cipher.embedsDigest {
cell.rightText = V.cipherDigest(parameters.cipher.genericName, parameters.digest.genericName)
if !parameters.sessionConfiguration.cipher.embedsDigest {
cell.rightText = V.cipherDigest(parameters.sessionConfiguration.cipher.genericName, parameters.sessionConfiguration.digest.genericName)
} else {
cell.rightText = V.cipher(parameters.cipher.genericName)
cell.rightText = V.cipher(parameters.sessionConfiguration.cipher.genericName)
}
return cell
@ -973,9 +973,11 @@ extension ServiceViewController: TrustedNetworksModelDelegate {
// MARK: -
extension ServiceViewController: ConfigurationModificationDelegate {
func configuration(didUpdate newConfiguration: TunnelKitProvider.Configuration) {
func configuration(didUpdate newConfiguration: SessionProxy.Configuration) {
if let hostProfile = profile as? HostConnectionProfile {
hostProfile.parameters = newConfiguration
var builder = hostProfile.parameters.builder()
builder.sessionConfiguration = newConfiguration
hostProfile.parameters = builder.build()
}
reloadSelectedRow()
}

View File

@ -41,7 +41,7 @@
0E6BE13A20CFB76800A6DD36 /* ApplicationError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6BE13920CFB76800A6DD36 /* ApplicationError.swift */; };
0E6BE13F20CFBAB300A6DD36 /* DebugLogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6BE13E20CFBAB300A6DD36 /* DebugLogViewController.swift */; };
0E89DFC5213DF7AE00741BA1 /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFC4213DF7AE00741BA1 /* Preferences.swift */; };
0E89DFC8213E8FC500741BA1 /* TunnelKitProvider+Communication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFC7213E8FC500741BA1 /* TunnelKitProvider+Communication.swift */; };
0E89DFC8213E8FC500741BA1 /* SessionProxy+Communication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFC7213E8FC500741BA1 /* SessionProxy+Communication.swift */; };
0E89DFCE213EEDFA00741BA1 /* WizardProviderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFCD213EEDFA00741BA1 /* WizardProviderViewController.swift */; };
0E89DFD0213F223400741BA1 /* Wizard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFCF213F223400741BA1 /* Wizard.swift */; };
0E8D97E221388B52006FB4A0 /* InfrastructurePreset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E8D97E121388B52006FB4A0 /* InfrastructurePreset.swift */; };
@ -159,7 +159,7 @@
0E6BE13920CFB76800A6DD36 /* ApplicationError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationError.swift; sourceTree = "<group>"; };
0E6BE13E20CFBAB300A6DD36 /* DebugLogViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugLogViewController.swift; sourceTree = "<group>"; };
0E89DFC4213DF7AE00741BA1 /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
0E89DFC7213E8FC500741BA1 /* TunnelKitProvider+Communication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TunnelKitProvider+Communication.swift"; sourceTree = "<group>"; };
0E89DFC7213E8FC500741BA1 /* SessionProxy+Communication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+Communication.swift"; sourceTree = "<group>"; };
0E89DFCD213EEDFA00741BA1 /* WizardProviderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WizardProviderViewController.swift; sourceTree = "<group>"; };
0E89DFCF213F223400741BA1 /* Wizard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Wizard.swift; sourceTree = "<group>"; };
0E8D97E121388B52006FB4A0 /* InfrastructurePreset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfrastructurePreset.swift; sourceTree = "<group>"; };
@ -382,7 +382,7 @@
0ED38AE621404F100004D387 /* EndpointDataSource.swift */,
0E89DFC4213DF7AE00741BA1 /* Preferences.swift */,
0E2D11B9217DBEDE0096822C /* ProfileConfigurationFactory.swift */,
0E89DFC7213E8FC500741BA1 /* TunnelKitProvider+Communication.swift */,
0E89DFC7213E8FC500741BA1 /* SessionProxy+Communication.swift */,
0E2B494120FD16540094784C /* TransientStore.swift */,
0E4C9CB820DB9BC600A0C59C /* TrustedNetworks.swift */,
0EBE3A8F213C6F4000BFA2F5 /* TrustPolicy.swift */,
@ -837,7 +837,7 @@
0E2D11BA217DBEDE0096822C /* ProfileConfigurationFactory.swift in Sources */,
0EBE3A90213C6F4000BFA2F5 /* TrustPolicy.swift in Sources */,
0E6BE13F20CFBAB300A6DD36 /* DebugLogViewController.swift in Sources */,
0E89DFC8213E8FC500741BA1 /* TunnelKitProvider+Communication.swift in Sources */,
0E89DFC8213E8FC500741BA1 /* SessionProxy+Communication.swift in Sources */,
0ED38AEA214054A50004D387 /* OptionViewController.swift in Sources */,
0EFD943E215BE10800529B64 /* IssueReporter.swift in Sources */,
0EBE3AAC213DEB8800BFA2F5 /* ConnectionProfileHolder.swift in Sources */,

View File

@ -42,7 +42,8 @@ class AppConstants {
class VPN {
static func tunnelConfiguration() -> TunnelKitProvider.Configuration {
var builder = TunnelKitProvider.ConfigurationBuilder(ca: CryptoContainer(pem: ""))
let sessionBuilder = SessionProxy.ConfigurationBuilder(ca: CryptoContainer(pem: ""))
var builder = TunnelKitProvider.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"

View File

@ -34,7 +34,8 @@ class HostConnectionProfile: ConnectionProfile, Codable, Equatable {
init(title: String, hostname: String) {
self.title = title
self.hostname = hostname
parameters = TunnelKitProvider.ConfigurationBuilder(ca: CryptoContainer(pem: "")).build()
let sessionConfiguration = SessionProxy.ConfigurationBuilder(ca: CryptoContainer(pem: "")).build()
parameters = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionConfiguration).build()
}
// MARK: ConnectionProfile

View File

@ -1,5 +1,5 @@
//
// TunnelKitProvider+Communication.swift
// SessionProxy+Communication.swift
// Passepartout
//
// Created by Davide De Rosa on 9/4/18.
@ -26,15 +26,16 @@
import Foundation
import TunnelKit
extension TunnelKitProvider.ConfigurationBuilder {
// mutating func copyCommunication(from other: TunnelKitProvider.ConfigurationBuilder) {
extension SessionProxy.ConfigurationBuilder {
// mutating func copyCommunication(from other: SessionProxy.ConfigurationBuilder) {
// cipher = other.cipher
// digest = other.digest
// compressionFraming = other.compressionFraming
// }
func canCommunicate(with other: TunnelKitProvider.Configuration) -> Bool {
return (cipher == other.cipher) &&
func canCommunicate(with other: SessionProxy.Configuration) -> Bool {
return
(cipher == other.cipher) &&
((digest == other.digest) || cipher.embedsDigest) &&
(compressionFraming == other.compressionFraming)
}

View File

@ -84,18 +84,21 @@ struct InfrastructurePreset: Codable {
let cfgContainer = try container.nestedContainer(keyedBy: ConfigurationKeys.self, forKey: .configuration)
let ca = try cfgContainer.decode(CryptoContainer.self, forKey: .ca)
var builder = TunnelKitProvider.ConfigurationBuilder(ca: ca)
builder.endpointProtocols = try cfgContainer.decode([TunnelKitProvider.EndpointProtocol].self, forKey: .endpointProtocols)
builder.cipher = try cfgContainer.decode(SessionProxy.Cipher.self, forKey: .cipher)
var sessionBuilder = SessionProxy.ConfigurationBuilder(ca: ca)
sessionBuilder.cipher = try cfgContainer.decode(SessionProxy.Cipher.self, forKey: .cipher)
if let digest = try cfgContainer.decodeIfPresent(SessionProxy.Digest.self, forKey: .digest) {
builder.digest = digest
sessionBuilder.digest = digest
}
builder.clientCertificate = try cfgContainer.decodeIfPresent(CryptoContainer.self, forKey: .clientCertificate)
builder.clientKey = try cfgContainer.decodeIfPresent(CryptoContainer.self, forKey: .clientKey)
builder.compressionFraming = try cfgContainer.decode(SessionProxy.CompressionFraming.self, forKey: .compressionFraming)
builder.keepAliveSeconds = try cfgContainer.decodeIfPresent(Int.self, forKey: .keepAliveSeconds)
builder.renegotiatesAfterSeconds = try cfgContainer.decodeIfPresent(Int.self, forKey: .renegotiatesAfterSeconds)
builder.usesPIAPatches = try cfgContainer.decodeIfPresent(Bool.self, forKey: .usesPIAPatches) ?? false
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.keepAliveInterval = try cfgContainer.decodeIfPresent(TimeInterval.self, forKey: .keepAliveSeconds)
sessionBuilder.renegotiatesAfter = try cfgContainer.decodeIfPresent(TimeInterval.self, forKey: .renegotiatesAfterSeconds)
sessionBuilder.usesPIAPatches = try cfgContainer.decodeIfPresent(Bool.self, forKey: .usesPIAPatches) ?? false
var builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build())
builder.endpointProtocols = try cfgContainer.decode([TunnelKitProvider.EndpointProtocol].self, forKey: .endpointProtocols)
configuration = builder.build()
}
@ -107,14 +110,15 @@ struct InfrastructurePreset: Codable {
var cfgContainer = container.nestedContainer(keyedBy: ConfigurationKeys.self, forKey: .configuration)
try cfgContainer.encode(configuration.endpointProtocols, forKey: .endpointProtocols)
try cfgContainer.encode(configuration.cipher, forKey: .cipher)
try cfgContainer.encode(configuration.digest, forKey: .digest)
try cfgContainer.encodeIfPresent(configuration.ca, forKey: .ca)
try cfgContainer.encodeIfPresent(configuration.clientCertificate, forKey: .clientCertificate)
try cfgContainer.encodeIfPresent(configuration.clientKey, forKey: .clientKey)
try cfgContainer.encode(configuration.compressionFraming, forKey: .compressionFraming)
try cfgContainer.encodeIfPresent(configuration.keepAliveSeconds, forKey: .keepAliveSeconds)
try cfgContainer.encodeIfPresent(configuration.renegotiatesAfterSeconds, forKey: .renegotiatesAfterSeconds)
try cfgContainer.encodeIfPresent(configuration.usesPIAPatches, forKey: .usesPIAPatches)
try cfgContainer.encode(configuration.sessionConfiguration.cipher, forKey: .cipher)
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.encodeIfPresent(configuration.sessionConfiguration.keepAliveInterval, forKey: .keepAliveSeconds)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.renegotiatesAfter, forKey: .renegotiatesAfterSeconds)
try cfgContainer.encodeIfPresent(configuration.sessionConfiguration.usesPIAPatches, forKey: .usesPIAPatches)
}
}

View File

@ -75,8 +75,8 @@ extension TunnelKitProvider.Configuration {
var optCA: CryptoContainer?
var clientCertificate: CryptoContainer?
var clientKey: CryptoContainer?
var keepAliveSeconds: Int?
var renegotiateAfterSeconds: Int?
var keepAliveSeconds: TimeInterval?
var renegotiateAfterSeconds: TimeInterval?
var keyDirection: StaticKey.Direction?
var tlsStrategy: SessionProxy.TLSWrap.Strategy?
var tlsKeyLines: [Substring]?
@ -202,13 +202,13 @@ extension TunnelKitProvider.Configuration {
guard let arg = $0.first else {
return
}
keepAliveSeconds = Int(arg)
keepAliveSeconds = TimeInterval(arg)
}
Regex.renegSec.enumerateArguments(in: line) {
guard let arg = $0.first else {
return
}
renegotiateAfterSeconds = Int(arg)
renegotiateAfterSeconds = TimeInterval(arg)
}
Regex.fragment.enumerateArguments(in: line) { (_) in
unsupportedError = ApplicationError.unsupportedConfiguration(option: "fragment")
@ -270,16 +270,17 @@ extension TunnelKitProvider.Configuration {
}
}
var builder = TunnelKitProvider.ConfigurationBuilder(ca: ca)
var sessionBuilder = SessionProxy.ConfigurationBuilder(ca: ca)
sessionBuilder.cipher = cipher ?? .aes128cbc
sessionBuilder.digest = digest ?? .sha1
sessionBuilder.compressionFraming = compressionFraming
sessionBuilder.tlsWrap = tlsWrap
sessionBuilder.clientCertificate = clientCertificate
sessionBuilder.clientKey = clientKey
sessionBuilder.keepAliveInterval = keepAliveSeconds
sessionBuilder.renegotiatesAfter = renegotiateAfterSeconds
var builder = TunnelKitProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build())
builder.endpointProtocols = endpointProtocols
builder.cipher = cipher ?? .aes128cbc
builder.digest = digest ?? .sha1
builder.compressionFraming = compressionFraming
builder.tlsWrap = tlsWrap
builder.clientCertificate = clientCertificate
builder.clientKey = clientKey
builder.keepAliveSeconds = keepAliveSeconds
builder.renegotiatesAfterSeconds = renegotiateAfterSeconds
return (hostname, builder.build())
}

View File

@ -40,8 +40,8 @@ class FileConfigurationTests: XCTestCase {
func testPIA() throws {
let cfg = try TunnelKitProvider.Configuration.parsed(from: url(withName: "pia-hungary")).1
XCTAssertEqual(cfg.cipher, .aes128cbc)
XCTAssertEqual(cfg.digest, .sha1)
XCTAssertEqual(cfg.sessionConfiguration.cipher, .aes128cbc)
XCTAssertEqual(cfg.sessionConfiguration.digest, .sha1)
}
private func url(withName name: String) -> URL {

View File

@ -3,7 +3,7 @@ use_frameworks!
def shared_pods
#pod 'TunnelKit', '~> 1.1.2'
pod 'TunnelKit', :git => 'https://github.com/keeshux/tunnelkit', :commit => '6995b88'
pod 'TunnelKit', :git => 'https://github.com/keeshux/tunnelkit', :commit => 'd94733f'
#pod 'TunnelKit', :path => '../tunnelkit'
end

View File

@ -2,19 +2,19 @@ PODS:
- MBProgressHUD (1.1.0)
- OpenSSL-Apple (1.1.0i-v2)
- SwiftyBeaver (1.6.1)
- TunnelKit (1.2.2):
- TunnelKit/AppExtension (= 1.2.2)
- TunnelKit/Core (= 1.2.2)
- TunnelKit/AppExtension (1.2.2):
- TunnelKit (1.3.0):
- TunnelKit/AppExtension (= 1.3.0)
- TunnelKit/Core (= 1.3.0)
- TunnelKit/AppExtension (1.3.0):
- SwiftyBeaver
- TunnelKit/Core
- TunnelKit/Core (1.2.2):
- TunnelKit/Core (1.3.0):
- OpenSSL-Apple (~> 1.1.0h)
- SwiftyBeaver
DEPENDENCIES:
- MBProgressHUD
- TunnelKit (from `https://github.com/keeshux/tunnelkit`, commit `6995b88`)
- TunnelKit (from `https://github.com/keeshux/tunnelkit`, commit `d94733f`)
SPEC REPOS:
https://github.com/cocoapods/specs.git:
@ -24,20 +24,20 @@ SPEC REPOS:
EXTERNAL SOURCES:
TunnelKit:
:commit: 6995b88
:commit: d94733f
:git: https://github.com/keeshux/tunnelkit
CHECKOUT OPTIONS:
TunnelKit:
:commit: 6995b88
:commit: d94733f
:git: https://github.com/keeshux/tunnelkit
SPEC CHECKSUMS:
MBProgressHUD: e7baa36a220447d8aeb12769bf0585582f3866d9
OpenSSL-Apple: a93b8f2eec8783ff40d9a9304de180ab68bb647c
SwiftyBeaver: ccfcdf85a04d429f1633f668650b0ce8020bda3a
TunnelKit: 15c88f0cef7b926883566a9455e912a1e55f4048
TunnelKit: 8e747cac28959ebfdfa4eeab589c933f1856c0fb
PODFILE CHECKSUM: 159cfb999715d0ff9a22a7824f3b25dea9908ef0
PODFILE CHECKSUM: 38237684ab2fdb5e262da936fd6932218abca0b4
COCOAPODS: 1.6.0.beta.2