From 0dfdac77a967b96fc69a1bf3637ee346bcb13a98 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Sun, 3 Mar 2024 23:32:18 +0100 Subject: [PATCH] macOS: Fix some VPN debug menu commands (#2260) Task/Issue URL: https://app.asana.com/0/0/1206686508201525/f ## Description While testing I noticed some useful functionality from our debug menu (specifically rekeying and triggering the debug notification) was no longer working. This should not affect anything other than our debug commands. I'm enabling them again because it's really useful to be able to force a rekey form the app. --- .../NetworkProtectionTunnelController.swift | 14 ++++++++++++++ DuckDuckGoVPN/TunnelControllerIPCService.swift | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift index 3eb54f6f2b..5d658849b3 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift @@ -287,6 +287,20 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr } } + // MARK: - Debug Command support + + func relay(_ command: DebugCommand) async throws { + guard await isConnected, + let session = await session else { + return + } + + let errorMessage: ExtensionMessageString? = try await session.sendProviderRequest(.debugCommand(command)) + if let errorMessage { + throw TunnelFailureError(errorDescription: errorMessage.value) + } + } + // MARK: - Tunnel Configuration /// Setups the tunnel manager if it's not set up already. diff --git a/DuckDuckGoVPN/TunnelControllerIPCService.swift b/DuckDuckGoVPN/TunnelControllerIPCService.swift index 2073438e40..c8a9ce456d 100644 --- a/DuckDuckGoVPN/TunnelControllerIPCService.swift +++ b/DuckDuckGoVPN/TunnelControllerIPCService.swift @@ -29,14 +29,14 @@ import NetworkProtectionUI /// Clients can edit those defaults and this class will observe the changes and relay them to the runnel. /// final class TunnelControllerIPCService { - private let tunnelController: TunnelController + private let tunnelController: NetworkProtectionTunnelController private let networkExtensionController: NetworkExtensionController private let server: NetworkProtectionIPC.TunnelControllerIPCServer private let statusReporter: NetworkProtectionStatusReporter private var cancellables = Set() private let defaults: UserDefaults - init(tunnelController: TunnelController, + init(tunnelController: NetworkProtectionTunnelController, networkExtensionController: NetworkExtensionController, statusReporter: NetworkProtectionStatusReporter, defaults: UserDefaults = .netP) { @@ -112,6 +112,8 @@ extension TunnelControllerIPCService: IPCServerInterface { } func debugCommand(_ command: DebugCommand) async throws { + try await tunnelController.relay(command) + switch command { case .removeSystemExtension: #if NETP_SYSTEM_EXTENSION