diff --git a/CHANGELOG.md b/CHANGELOG.md index 37282f5..abf2247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Basic support for proxy settings (no PAC). [#74](https://github.com/keeshux/tunnelkit/issues/74) + ### Changed - Make `hostname` optional and pick `resolvedAddresses` if nil. diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift index dfd42ff..f81ff3c 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift @@ -554,11 +554,23 @@ extension TunnelKitProvider: SessionProxyDelegate { if let searchDomain = 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) newSettings.ipv4Settings = ipv4Settings newSettings.ipv6Settings = ipv6Settings newSettings.dnsSettings = dnsSettings + newSettings.proxySettings = proxySettings setTunnelNetworkSettings(newSettings, completionHandler: completionHandler) } @@ -671,3 +683,9 @@ extension TunnelKitProvider { return error as? ProviderError ?? .linkError } } + +private extension Proxy { + func neProxy() -> NEProxyServer { + return NEProxyServer(address: address, port: Int(port)) + } +}