From 3ed23a5bffe36e07a14c791d58ae7e7f0cd624f0 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Wed, 14 Aug 2024 01:55:54 +0200 Subject: [PATCH] VPN now recovers from WireGuard closing utun (#3084) Task/Issue URL: https://app.asana.com/0/0/1208000338328853/f iOS: https://github.com/duckduckgo/iOS/pull/3204 BSK: https://github.com/duckduckgo/BrowserServicesKit/pull/931 ## Description If we detect an error while updating the tunnel configuration we now cancel the tunnel so Apple recreates the virtual interface. I believe the underlying issue is WireGuard should not "touch" the virtual interface at all, as that responsibility is owned by Apple. --- DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- .../NetworkProtectionPixelEvent.swift | 15 +++++++++++---- .../EventMapping+NetworkProtectionError.swift | 1 + .../MacPacketTunnelProvider.swift | 6 ++++-- LocalPackages/DataBrokerProtection/Package.swift | 2 +- LocalPackages/NetworkProtectionMac/Package.swift | 2 +- LocalPackages/SubscriptionUI/Package.swift | 2 +- .../NetworkProtectionPixelEventTests.swift | 14 ++++++++++---- 9 files changed, 32 insertions(+), 16 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 0a3f086eae..6633cc4470 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -13465,7 +13465,7 @@ repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 183.0.1; + version = 184.0.0; }; }; 9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index f252c26951..dfc932907d 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/BrowserServicesKit", "state" : { - "revision" : "f0220c164618c7ca1cbf276db644d71711b0c76a", - "version" : "183.0.1" + "revision" : "c6ce430371032930d770b0388cbe44a2d40ad729", + "version" : "184.0.0" } }, { diff --git a/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift b/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift index 6b0a86cfec..3a89fcb611 100644 --- a/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift +++ b/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift @@ -98,7 +98,8 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { case networkProtectionWireguardErrorInvalidState(reason: String) case networkProtectionWireguardErrorFailedDNSResolution case networkProtectionWireguardErrorCannotSetNetworkSettings(_ error: Error) - case networkProtectionWireguardErrorCannotStartWireguardBackend(code: Int32) + case networkProtectionWireguardErrorCannotStartWireguardBackend(_ error: Error) + case networkProtectionWireguardErrorCannotSetWireguardConfig(_ error: Error) case networkProtectionNoAuthTokenFoundError @@ -290,6 +291,9 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { case .networkProtectionWireguardErrorCannotStartWireguardBackend: return "netp_wireguard_error_cannot_start_wireguard_backend" + case .networkProtectionWireguardErrorCannotSetWireguardConfig: + return "netp_wireguard_error_cannot_set_wireguard_config" + case .networkProtectionNoAuthTokenFoundError: return "netp_no_auth_token_found_error" @@ -378,8 +382,10 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { return parameters case .networkProtectionWireguardErrorCannotSetNetworkSettings(let error): return error.pixelParameters - case .networkProtectionWireguardErrorCannotStartWireguardBackend(code: let code): - return [PixelKit.Parameters.errorCode: String(code)] + case .networkProtectionWireguardErrorCannotStartWireguardBackend(let error): + return error.pixelParameters + case .networkProtectionWireguardErrorCannotSetWireguardConfig(let error): + return error.pixelParameters case .networkProtectionClientFailedToFetchServerStatus(let error): return error?.pixelParameters case .networkProtectionClientFailedToParseServerStatusResponse(let error): @@ -458,6 +464,8 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { .networkProtectionTunnelWakeFailure(let error), .networkProtectionClientFailedToParseRedeemResponse(let error), .networkProtectionWireguardErrorCannotSetNetworkSettings(let error), + .networkProtectionWireguardErrorCannotStartWireguardBackend(let error), + .networkProtectionWireguardErrorCannotSetWireguardConfig(let error), .networkProtectionRekeyFailure(let error), .networkProtectionUnhandledError(_, _, let error), .networkProtectionSystemExtensionActivationFailure(let error), @@ -507,7 +515,6 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { .networkProtectionWireguardErrorCannotLocateTunnelFileDescriptor, .networkProtectionWireguardErrorInvalidState, .networkProtectionWireguardErrorFailedDNSResolution, - .networkProtectionWireguardErrorCannotStartWireguardBackend, .networkProtectionNoAuthTokenFoundError, .networkProtectionRekeyAttempt, .networkProtectionRekeyCompleted, diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/EventMapping+NetworkProtectionError.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/EventMapping+NetworkProtectionError.swift index fc47c35d55..93107416d4 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/EventMapping+NetworkProtectionError.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/EventMapping+NetworkProtectionError.swift @@ -82,6 +82,7 @@ extension EventMapping where Event == NetworkProtectionError { .wireGuardDnsResolution, .wireGuardSetNetworkSettings, .startWireGuardBackend, + .setWireguardConfig, .failedToRetrieveAuthToken, .failedToFetchServerStatus, .failedToParseServerStatusResponse: diff --git a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift index c4633c14bc..46a84aeca7 100644 --- a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift +++ b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift @@ -110,8 +110,10 @@ final class MacPacketTunnelProvider: PacketTunnelProvider { domainEvent = .networkProtectionWireguardErrorFailedDNSResolution case .wireGuardSetNetworkSettings(let error): domainEvent = .networkProtectionWireguardErrorCannotSetNetworkSettings(error) - case .startWireGuardBackend(let code): - domainEvent = .networkProtectionWireguardErrorCannotStartWireguardBackend(code: code) + case .startWireGuardBackend(let error): + domainEvent = .networkProtectionWireguardErrorCannotStartWireguardBackend(error) + case .setWireguardConfig(let error): + domainEvent = .networkProtectionWireguardErrorCannotSetWireguardConfig(error) case .noAuthTokenFound: domainEvent = .networkProtectionNoAuthTokenFoundError case .failedToFetchServerStatus(let error): diff --git a/LocalPackages/DataBrokerProtection/Package.swift b/LocalPackages/DataBrokerProtection/Package.swift index fa17f1c540..f6320f6d43 100644 --- a/LocalPackages/DataBrokerProtection/Package.swift +++ b/LocalPackages/DataBrokerProtection/Package.swift @@ -29,7 +29,7 @@ let package = Package( targets: ["DataBrokerProtection"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "183.0.1"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "184.0.0"), .package(path: "../SwiftUIExtensions"), .package(path: "../XPCHelper"), ], diff --git a/LocalPackages/NetworkProtectionMac/Package.swift b/LocalPackages/NetworkProtectionMac/Package.swift index 4b72f71fe9..2b498a855e 100644 --- a/LocalPackages/NetworkProtectionMac/Package.swift +++ b/LocalPackages/NetworkProtectionMac/Package.swift @@ -32,7 +32,7 @@ let package = Package( .library(name: "VPNAppLauncher", targets: ["VPNAppLauncher"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "183.0.1"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "184.0.0"), .package(url: "https://github.com/airbnb/lottie-spm", exact: "4.4.3"), .package(path: "../AppLauncher"), .package(path: "../UDSHelper"), diff --git a/LocalPackages/SubscriptionUI/Package.swift b/LocalPackages/SubscriptionUI/Package.swift index 31b26c3215..ff322c42e1 100644 --- a/LocalPackages/SubscriptionUI/Package.swift +++ b/LocalPackages/SubscriptionUI/Package.swift @@ -12,7 +12,7 @@ let package = Package( targets: ["SubscriptionUI"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "183.0.1"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "184.0.0"), .package(path: "../SwiftUIExtensions") ], targets: [ diff --git a/UnitTests/NetworkProtection/NetworkProtectionPixelEventTests.swift b/UnitTests/NetworkProtection/NetworkProtectionPixelEventTests.swift index cd60e9adf7..cd27726b43 100644 --- a/UnitTests/NetworkProtection/NetworkProtectionPixelEventTests.swift +++ b/UnitTests/NetworkProtection/NetworkProtectionPixelEventTests.swift @@ -322,12 +322,18 @@ final class NetworkProtectionPixelEventTests: XCTestCase { underlyingErrors: [TestError.underlyingError]), file: #filePath, line: #line) - fire(NetworkProtectionPixelEvent.networkProtectionWireguardErrorCannotStartWireguardBackend(code: 1), + fire(NetworkProtectionPixelEvent.networkProtectionWireguardErrorCannotStartWireguardBackend(TestError.testError), frequency: .dailyAndCount, and: .expect(pixelName: "m_mac_netp_wireguard_error_cannot_start_wireguard_backend", - customFields: [ - PixelKit.Parameters.errorCode: "1" - ]), + error: TestError.testError, + underlyingErrors: [TestError.underlyingError]), + file: #filePath, + line: #line) + fire(NetworkProtectionPixelEvent.networkProtectionWireguardErrorCannotSetWireguardConfig(TestError.testError), + frequency: .dailyAndCount, + and: .expect(pixelName: "m_mac_netp_wireguard_error_cannot_set_wireguard_config", + error: TestError.testError, + underlyingErrors: [TestError.underlyingError]), file: #filePath, line: #line) fire(NetworkProtectionPixelEvent.networkProtectionNoAuthTokenFoundError,