Apply proxy settings if present

Fixes #74
This commit is contained in:
Davide De Rosa 2019-04-12 08:14:18 +02:00
parent ef9f3c6d0a
commit 904e7bae21
2 changed files with 22 additions and 0 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Added
- Basic support for proxy settings (no PAC). [#74](https://github.com/keeshux/tunnelkit/issues/74)
### Changed ### Changed
- Make `hostname` optional and pick `resolvedAddresses` if nil. - Make `hostname` optional and pick `resolvedAddresses` if nil.

View File

@ -555,10 +555,22 @@ extension TunnelKitProvider: SessionProxyDelegate {
dnsSettings.searchDomains = [searchDomain] dnsSettings.searchDomains = [searchDomain]
} }
var proxySettings: NEProxySettings?
if let httpsProxy = cfg.sessionConfiguration.httpsProxy ?? reply.options.httpsProxy {
proxySettings = NEProxySettings()
proxySettings?.httpsServer = httpsProxy.neProxy()
proxySettings?.httpsEnabled = true
} else if let httpProxy = cfg.sessionConfiguration.httpProxy ?? reply.options.httpProxy {
proxySettings = NEProxySettings()
proxySettings?.httpServer = httpProxy.neProxy()
proxySettings?.httpEnabled = true
}
let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: remoteAddress) let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: remoteAddress)
newSettings.ipv4Settings = ipv4Settings newSettings.ipv4Settings = ipv4Settings
newSettings.ipv6Settings = ipv6Settings newSettings.ipv6Settings = ipv6Settings
newSettings.dnsSettings = dnsSettings newSettings.dnsSettings = dnsSettings
newSettings.proxySettings = proxySettings
setTunnelNetworkSettings(newSettings, completionHandler: completionHandler) setTunnelNetworkSettings(newSettings, completionHandler: completionHandler)
} }
@ -671,3 +683,9 @@ extension TunnelKitProvider {
return error as? ProviderError ?? .linkError return error as? ProviderError ?? .linkError
} }
} }
private extension Proxy {
func neProxy() -> NEProxyServer {
return NEProxyServer(address: address, port: Int(port))
}
}