Skip to content

Commit

Permalink
VPN Domain exclusions (internal release) (#918)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1207936340790549/f

iOS PR: duckduckgo/iOS#3164
macOS PR: duckduckgo/macos-browser#3045

What kind of version bump will this require?: Patch

## Description

Adds BSK support for implements domain exclusions in macOS for internal
users only.
  • Loading branch information
diegoreymendez committed Aug 6, 2024
1 parent 92ecebf commit 2ed4b00
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum VPNCommand: Codable {
case removeSystemExtension
case removeVPNConfiguration
case sendTestNotification
case restartAdapter
case uninstallVPN
case disableConnectOnDemandAndShutDown
case quitAgent
Expand Down
23 changes: 23 additions & 0 deletions Sources/NetworkProtection/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
excludedRoutes: settings.excludedRanges,
dnsSettings: settings.dnsSettings,
regenerateKey: regenerateKey)

case .useConfiguration(let newTunnelConfiguration):
tunnelConfiguration = newTunnelConfiguration
}
Expand Down Expand Up @@ -1139,6 +1140,8 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
case .removeVPNConfiguration:
// Since the VPN configuration is being removed we may as well reset all state
handleResetAllState(completionHandler: completionHandler)
case .restartAdapter:
handleRestartAdapter(completionHandler: completionHandler)
case .uninstallVPN:
// Since the VPN configuration is being removed we may as well reset all state
handleResetAllState(completionHandler: completionHandler)
Expand Down Expand Up @@ -1170,6 +1173,26 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
}
}

private func handleRestartAdapter(completionHandler: ((Data?) -> Void)? = nil) {
Task {
do {
let tunnelConfiguration = try await generateTunnelConfiguration(serverSelectionMethod: currentServerSelectionMethod,
includedRoutes: includedRoutes ?? [],
excludedRoutes: settings.excludedRanges,
dnsSettings: settings.dnsSettings,
regenerateKey: false)

try await updateTunnelConfiguration(updateMethod: .useConfiguration(tunnelConfiguration),
reassert: false,
regenerateKey: false)

completionHandler?(nil)
} catch {
completionHandler?(nil)
}
}
}

private func handleGetLastErrorMessage(completionHandler: ((Data?) -> Void)? = nil) {
let response = controllerErrorStore.lastErrorMessage.map(ExtensionMessageString.init)
completionHandler?(response?.rawValue)
Expand Down
3 changes: 0 additions & 3 deletions Sources/NetworkProtection/WireGuardKit/WireGuardAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,6 @@ public class WireGuardAdapter {
}

if reassert {
// Tell the system that the tunnel is going to reconnect using new WireGuard
// configuration.
// This will broadcast the `NEVPNStatusDidChange` notification to the GUI process.
self.packetTunnelProvider?.reasserting = true
}

Expand Down

0 comments on commit 2ed4b00

Please sign in to comment.