Add SessionProxy.Configuration.randomizeEndpoint

This commit is contained in:
Davide De Rosa 2019-03-25 10:17:47 +01:00
parent 9c0205614b
commit 42227fcc00
2 changed files with 26 additions and 6 deletions

View File

@ -67,7 +67,8 @@ extension TunnelKitProvider {
keepAliveInterval: nil,
renegotiatesAfter: nil,
usesPIAPatches: nil,
dnsServers: nil
dnsServers: nil,
randomizeEndpoint: false
),
shouldDebug: false,
debugLogFormat: nil,
@ -186,10 +187,11 @@ extension TunnelKitProvider {
throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[\(S.tlsWrap)]")
}
}
sessionConfigurationBuilder.keepAliveInterval = providerConfiguration[S.keepAlive] as? TimeInterval
sessionConfigurationBuilder.renegotiatesAfter = providerConfiguration[S.renegotiatesAfter] as? TimeInterval
sessionConfigurationBuilder.usesPIAPatches = providerConfiguration[S.usesPIAPatches] as? Bool ?? false
sessionConfigurationBuilder.keepAliveInterval = providerConfiguration[S.keepAlive] as? TimeInterval ?? ConfigurationBuilder.defaults.sessionConfiguration.keepAliveInterval
sessionConfigurationBuilder.renegotiatesAfter = providerConfiguration[S.renegotiatesAfter] as? TimeInterval ?? ConfigurationBuilder.defaults.sessionConfiguration.renegotiatesAfter
sessionConfigurationBuilder.usesPIAPatches = providerConfiguration[S.usesPIAPatches] as? Bool ?? ConfigurationBuilder.defaults.sessionConfiguration.usesPIAPatches
sessionConfigurationBuilder.dnsServers = providerConfiguration[S.dnsServers] as? [String]
sessionConfigurationBuilder.randomizeEndpoint = providerConfiguration[S.randomizeEndpoint] as? Bool ?? ConfigurationBuilder.defaults.sessionConfiguration.randomizeEndpoint
sessionConfiguration = sessionConfigurationBuilder.build()
shouldDebug = providerConfiguration[S.debug] as? Bool ?? ConfigurationBuilder.defaults.shouldDebug
@ -261,6 +263,8 @@ extension TunnelKitProvider {
static let dnsServers = "DNSServers"
static let randomizeEndpoint = "RandomizeEndpoint"
// MARK: Debugging
static let debug = "Debug"
@ -426,6 +430,9 @@ extension TunnelKitProvider {
if let dnsServers = sessionConfiguration.dnsServers {
dict[S.dnsServers] = dnsServers
}
if let randomizeEndpoint = sessionConfiguration.randomizeEndpoint {
dict[S.randomizeEndpoint] = randomizeEndpoint
}
if let debugLogFormat = debugLogFormat {
dict[S.debugLogFormat] = debugLogFormat
}
@ -508,6 +515,9 @@ extension TunnelKitProvider {
if let dnsServers = sessionConfiguration.dnsServers {
log.info("\tCustom DNS servers: \(dnsServers.maskedDescription)")
}
if sessionConfiguration.randomizeEndpoint ?? false {
log.info("\tRandomize endpoint: true")
}
log.info("\tDebug: \(shouldDebug)")
log.info("\tMasks private data: \(masksPrivateData ?? true)")
}

View File

@ -174,6 +174,9 @@ extension SessionProxy {
/// Optionally override the server DNS entries.
public var dnsServers: [String]?
/// Optionally randomize endpoint order.
public var randomizeEndpoint: Bool?
/// :nodoc:
public init(ca: CryptoContainer) {
cipher = .aes128cbc
@ -189,6 +192,7 @@ extension SessionProxy {
renegotiatesAfter = nil
usesPIAPatches = false
dnsServers = nil
randomizeEndpoint = false
}
/**
@ -210,7 +214,8 @@ extension SessionProxy {
keepAliveInterval: keepAliveInterval,
renegotiatesAfter: renegotiatesAfter,
usesPIAPatches: usesPIAPatches,
dnsServers: dnsServers
dnsServers: dnsServers,
randomizeEndpoint: randomizeEndpoint
)
}
}
@ -257,6 +262,9 @@ extension SessionProxy {
/// - Seealso: `SessionProxy.ConfigurationBuilder.dnsServers`
public let dnsServers: [String]?
/// - Seealso: `SessionProxy.ConfigurationBuilder.randomizeEndpoint`
public let randomizeEndpoint: Bool?
/**
Returns a `SessionProxy.ConfigurationBuilder` to use this configuration as a starting point for a new one.
@ -276,6 +284,7 @@ extension SessionProxy {
builder.renegotiatesAfter = renegotiatesAfter
builder.usesPIAPatches = usesPIAPatches
builder.dnsServers = dnsServers
builder.randomizeEndpoint = randomizeEndpoint
return builder
}
@ -295,7 +304,8 @@ extension SessionProxy {
(lhs.keepAliveInterval == rhs.keepAliveInterval) &&
(lhs.renegotiatesAfter == rhs.renegotiatesAfter) &&
(lhs.usesPIAPatches == rhs.usesPIAPatches) &&
(lhs.dnsServers == rhs.dnsServers)
(lhs.dnsServers == rhs.dnsServers) &&
(lhs.randomizeEndpoint == rhs.randomizeEndpoint)
}
}
}