From e615e35dd35bd9f9f9c3f6f3724cf27841eff184 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Wed, 7 Aug 2024 20:29:34 +0200 Subject: [PATCH 1/6] Changes our VPN to reconnect when failing to set wgSetConfig --- DuckDuckGo.xcodeproj/project.pbxproj | 4 ++-- .../xcshareddata/swiftpm/Package.resolved | 9 --------- .../NetworkProtectionPixelEvent.swift | 13 +++++++++++-- .../EventMapping+NetworkProtectionError.swift | 1 + .../MacPacketTunnelProvider.swift | 2 ++ 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 82a428455c..48b7e50ccd 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -13437,8 +13437,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { - kind = exactVersion; - version = "180.0.0-1"; + kind = revision; + revision = 1d7e5bfa30851a7f8f3ce97490d1b9652cfd4f82; }; }; 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 8f3c473b25..57a0b8a720 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -27,15 +27,6 @@ "version" : "3.0.0" } }, - { - "identity" : "browserserviceskit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/duckduckgo/BrowserServicesKit", - "state" : { - "revision" : "1dabef4fd0afa84317625d8327ee2bf30b173872", - "version" : "180.0.0-1" - } - }, { "identity" : "content-scope-scripts", "kind" : "remoteSourceControl", diff --git a/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift b/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift index 6b0a86cfec..975fe691f7 100644 --- a/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift +++ b/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift @@ -99,6 +99,7 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { case networkProtectionWireguardErrorFailedDNSResolution case networkProtectionWireguardErrorCannotSetNetworkSettings(_ error: Error) case networkProtectionWireguardErrorCannotStartWireguardBackend(code: Int32) + case networkProtectionWireguardErrorCannotSetWireguardConfig(errorCode: Int64) 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): + case .networkProtectionWireguardErrorCannotStartWireguardBackend(let code): return [PixelKit.Parameters.errorCode: String(code)] + case .networkProtectionWireguardErrorCannotSetWireguardConfig(let errorCode): + return [PixelKit.Parameters.errorCode: String(errorCode)] case .networkProtectionClientFailedToFetchServerStatus(let error): return error?.pixelParameters case .networkProtectionClientFailedToParseServerStatusResponse(let error): @@ -507,7 +513,6 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { .networkProtectionWireguardErrorCannotLocateTunnelFileDescriptor, .networkProtectionWireguardErrorInvalidState, .networkProtectionWireguardErrorFailedDNSResolution, - .networkProtectionWireguardErrorCannotStartWireguardBackend, .networkProtectionNoAuthTokenFoundError, .networkProtectionRekeyAttempt, .networkProtectionRekeyCompleted, @@ -516,6 +521,10 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { .networkProtectionDNSUpdateCustom, .networkProtectionDNSUpdateDefault: return nil + case .networkProtectionWireguardErrorCannotStartWireguardBackend(let code): + return NSError(domain: "WireGuardAdapter", code: Int(code)) + case .networkProtectionWireguardErrorCannotSetWireguardConfig(let errorCode): + return NSError(domain: "WireGuardAdapter", code: Int(errorCode)) } } } 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 6b31b50cb0..c64843a45f 100644 --- a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift +++ b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift @@ -112,6 +112,8 @@ final class MacPacketTunnelProvider: PacketTunnelProvider { domainEvent = .networkProtectionWireguardErrorCannotSetNetworkSettings(error) case .startWireGuardBackend(let code): domainEvent = .networkProtectionWireguardErrorCannotStartWireguardBackend(code: code) + case .setWireguardConfig(let errorCode): + domainEvent = .networkProtectionWireguardErrorCannotSetWireguardConfig(errorCode: errorCode) case .noAuthTokenFound: domainEvent = .networkProtectionNoAuthTokenFoundError case .failedToFetchServerStatus(let error): From 886784356f6350f7018631e6cdf5a5f45321eb35 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Wed, 7 Aug 2024 20:30:01 +0200 Subject: [PATCH 2/6] Updates BSK --- .../xcshareddata/swiftpm/Package.resolved | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 57a0b8a720..478e07b372 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -27,6 +27,14 @@ "version" : "3.0.0" } }, + { + "identity" : "browserserviceskit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/duckduckgo/BrowserServicesKit", + "state" : { + "revision" : "1d7e5bfa30851a7f8f3ce97490d1b9652cfd4f82" + } + }, { "identity" : "content-scope-scripts", "kind" : "remoteSourceControl", From 29a641f75318e2cd8df798194e60cacbe4a036b7 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Tue, 13 Aug 2024 18:48:53 +0200 Subject: [PATCH 3/6] Updates BSK --- DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 2 +- .../NetworkProtectionPixelEvent.swift | 18 ++++++++---------- .../MacPacketTunnelProvider.swift | 8 ++++---- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 56c54cca16..e26d74f545 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -13465,7 +13465,7 @@ repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { kind = revision; - revision = 1456893364717471f1caeabe2b9871d6951fcdcf; + revision = eb0125b24249c562ef2505807f782bb41803f786; }; }; 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 ba731ead95..9b23cc4611 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,7 +32,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/BrowserServicesKit", "state" : { - "revision" : "1456893364717471f1caeabe2b9871d6951fcdcf" + "revision" : "eb0125b24249c562ef2505807f782bb41803f786" } }, { diff --git a/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift b/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift index 975fe691f7..3a89fcb611 100644 --- a/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift +++ b/DuckDuckGo/NetworkProtection/AppAndExtensionAndAgentTargets/NetworkProtectionPixelEvent.swift @@ -98,8 +98,8 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { case networkProtectionWireguardErrorInvalidState(reason: String) case networkProtectionWireguardErrorFailedDNSResolution case networkProtectionWireguardErrorCannotSetNetworkSettings(_ error: Error) - case networkProtectionWireguardErrorCannotStartWireguardBackend(code: Int32) - case networkProtectionWireguardErrorCannotSetWireguardConfig(errorCode: Int64) + case networkProtectionWireguardErrorCannotStartWireguardBackend(_ error: Error) + case networkProtectionWireguardErrorCannotSetWireguardConfig(_ error: Error) case networkProtectionNoAuthTokenFoundError @@ -382,10 +382,10 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { return parameters case .networkProtectionWireguardErrorCannotSetNetworkSettings(let error): return error.pixelParameters - case .networkProtectionWireguardErrorCannotStartWireguardBackend(let code): - return [PixelKit.Parameters.errorCode: String(code)] - case .networkProtectionWireguardErrorCannotSetWireguardConfig(let errorCode): - return [PixelKit.Parameters.errorCode: String(errorCode)] + 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): @@ -464,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), @@ -521,10 +523,6 @@ enum NetworkProtectionPixelEvent: PixelKitEventV2 { .networkProtectionDNSUpdateCustom, .networkProtectionDNSUpdateDefault: return nil - case .networkProtectionWireguardErrorCannotStartWireguardBackend(let code): - return NSError(domain: "WireGuardAdapter", code: Int(code)) - case .networkProtectionWireguardErrorCannotSetWireguardConfig(let errorCode): - return NSError(domain: "WireGuardAdapter", code: Int(errorCode)) } } } diff --git a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift index dd824e25d4..46a84aeca7 100644 --- a/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift +++ b/DuckDuckGo/NetworkProtection/NetworkExtensionTargets/NetworkExtensionTargets/MacPacketTunnelProvider.swift @@ -110,10 +110,10 @@ final class MacPacketTunnelProvider: PacketTunnelProvider { domainEvent = .networkProtectionWireguardErrorFailedDNSResolution case .wireGuardSetNetworkSettings(let error): domainEvent = .networkProtectionWireguardErrorCannotSetNetworkSettings(error) - case .startWireGuardBackend(let code): - domainEvent = .networkProtectionWireguardErrorCannotStartWireguardBackend(code: code) - case .setWireguardConfig(let errorCode): - domainEvent = .networkProtectionWireguardErrorCannotSetWireguardConfig(errorCode: errorCode) + case .startWireGuardBackend(let error): + domainEvent = .networkProtectionWireguardErrorCannotStartWireguardBackend(error) + case .setWireguardConfig(let error): + domainEvent = .networkProtectionWireguardErrorCannotSetWireguardConfig(error) case .noAuthTokenFound: domainEvent = .networkProtectionNoAuthTokenFoundError case .failedToFetchServerStatus(let error): From ae315de0c864460646f24a5aa9b7bbf021ddef4d Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Tue, 13 Aug 2024 19:06:09 +0200 Subject: [PATCH 4/6] Fixes some unit tests --- .../NetworkProtectionPixelEventTests.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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, From 23fe64125d706964f8bc3ba87a54f40433bf0047 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Tue, 13 Aug 2024 19:35:48 +0200 Subject: [PATCH 5/6] Updates BSK --- DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index e26d74f545..b3ac1630ea 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -13465,7 +13465,7 @@ repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { kind = revision; - revision = eb0125b24249c562ef2505807f782bb41803f786; + revision = c538181b02990b2862c80684f297c183bf74b934; }; }; 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 9b23cc4611..faaeb6664f 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -27,14 +27,6 @@ "version" : "3.0.0" } }, - { - "identity" : "browserserviceskit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/duckduckgo/BrowserServicesKit", - "state" : { - "revision" : "eb0125b24249c562ef2505807f782bb41803f786" - } - }, { "identity" : "content-scope-scripts", "kind" : "remoteSourceControl", From 3b961ce1ef2a8759fc73e593c97e4da58556c59f Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Tue, 13 Aug 2024 19:38:49 +0200 Subject: [PATCH 6/6] Updates BSK --- .../xcshareddata/swiftpm/Package.resolved | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index faaeb6664f..385298d57a 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -27,6 +27,14 @@ "version" : "3.0.0" } }, + { + "identity" : "browserserviceskit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/duckduckgo/BrowserServicesKit", + "state" : { + "revision" : "c538181b02990b2862c80684f297c183bf74b934" + } + }, { "identity" : "content-scope-scripts", "kind" : "remoteSourceControl",