From d87cd375dba4de229943c4af98aec94d67d49296 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 1 Feb 2024 00:18:00 +0530 Subject: [PATCH] Apple: Add 'debug' to network extension name in debug configuration (#3459) Supersedes PR #3395. When testing this, might have to remove the tunnel config in Settings.app before running this. --------- Co-authored-by: Jamil --- .../apple/Firezone.xcodeproj/project.pbxproj | 4 +-- .../FirezoneKit/Stores/TunnelStore.swift | 35 +++++++++++++------ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/swift/apple/Firezone.xcodeproj/project.pbxproj b/swift/apple/Firezone.xcodeproj/project.pbxproj index d7fcb8725..1767cff9b 100644 --- a/swift/apple/Firezone.xcodeproj/project.pbxproj +++ b/swift/apple/Firezone.xcodeproj/project.pbxproj @@ -586,7 +586,7 @@ MARKETING_VERSION = 1.0.0; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-lconnlib"; - PRODUCT_BUNDLE_IDENTIFIER = "$(inherited).network-extension"; + PRODUCT_BUNDLE_IDENTIFIER = "$(inherited).debug.network-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "$(IOS_NE_PROVISIONING_PROFILE_IDENTIFIER)"; @@ -671,7 +671,7 @@ "LIBRARY_SEARCH_PATHS[arch=x86_64]" = "$(CONNLIB_TARGET_DIR)/x86_64-apple-darwin/debug"; MARKETING_VERSION = 1.0.0; OTHER_LDFLAGS = "-lconnlib"; - PRODUCT_BUNDLE_IDENTIFIER = "$(inherited).network-extension"; + PRODUCT_BUNDLE_IDENTIFIER = "$(inherited).debug.network-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "$(MACOS_NE_PROVISIONING_PROFILE_IDENTIFIER)"; diff --git a/swift/apple/FirezoneKit/Sources/FirezoneKit/Stores/TunnelStore.swift b/swift/apple/FirezoneKit/Sources/FirezoneKit/Stores/TunnelStore.swift index f8afce07e..fcb06e0b5 100644 --- a/swift/apple/FirezoneKit/Sources/FirezoneKit/Stores/TunnelStore.swift +++ b/swift/apple/FirezoneKit/Sources/FirezoneKit/Stores/TunnelStore.swift @@ -89,7 +89,7 @@ public final class TunnelStore: ObservableObject { return } let tunnel = NETunnelProviderManager() - tunnel.localizedDescription = "Firezone" + tunnel.localizedDescription = NETunnelProviderManager.firezoneNetworkExtensionDescription() tunnel.protocolConfiguration = basicProviderProtocol() try await tunnel.saveToPreferences() logger.log("\(#function): Tunnel created") @@ -140,9 +140,8 @@ public final class TunnelStore: ObservableObject { func basicProviderProtocol() -> NETunnelProviderProtocol { let protocolConfiguration = NETunnelProviderProtocol() - protocolConfiguration.providerBundleIdentifier = Bundle.main.bundleIdentifier.map { - "\($0).network-extension" - } + protocolConfiguration.providerBundleIdentifier = + NETunnelProviderManager.firezoneNetworkExtensionBundleIdentifier() protocolConfiguration.serverAddress = AdvancedSettings.defaultValue.apiURLString protocolConfiguration.providerConfiguration = [ TunnelProviderKeys.keyConnlibLogFilter: @@ -490,21 +489,35 @@ extension NETunnelProviderManager { // Ensure the tunnel config has required values populated, because // to even sign out, we need saveToPreferences() to succeed. if let protocolConfiguration = protocolConfiguration as? NETunnelProviderProtocol { - protocolConfiguration.providerBundleIdentifier = Bundle.main.bundleIdentifier.map { - "\($0).network-extension" - } + protocolConfiguration.providerBundleIdentifier = + Self.firezoneNetworkExtensionBundleIdentifier() if protocolConfiguration.serverAddress?.isEmpty ?? true { protocolConfiguration.serverAddress = "unknown-server" } } else { let protocolConfiguration = NETunnelProviderProtocol() - protocolConfiguration.providerBundleIdentifier = Bundle.main.bundleIdentifier.map { - "\($0).network-extension" - } + protocolConfiguration.providerBundleIdentifier = + Self.firezoneNetworkExtensionBundleIdentifier() protocolConfiguration.serverAddress = "unknown-server" } if localizedDescription?.isEmpty ?? true { - localizedDescription = "Firezone" + localizedDescription = Self.firezoneNetworkExtensionDescription() } } + + static func firezoneNetworkExtensionBundleIdentifier() -> String? { + #if DEBUG + Bundle.main.bundleIdentifier.map { "\($0).debug.network-extension" } + #else + Bundle.main.bundleIdentifier.map { "\($0).network-extension" } + #endif + } + + static func firezoneNetworkExtensionDescription() -> String { + #if DEBUG + "Firezone (Debug)" + #else + "Firezone" + #endif + } }