diff --git a/Configuration/AppStore.xcconfig b/Configuration/AppStore.xcconfig index 30ec838615..4bf15b00f3 100644 --- a/Configuration/AppStore.xcconfig +++ b/Configuration/AppStore.xcconfig @@ -95,3 +95,21 @@ DBP_APP_GROUP[config=CI][sdk=*] = $(DBP_BASE_APP_GROUP).debug DBP_APP_GROUP[config=Review][sdk=*] = $(DBP_BASE_APP_GROUP).review DBP_APP_GROUP[config=Debug][sdk=*] = $(DBP_BASE_APP_GROUP).debug DBP_APP_GROUP[config=Release][sdk=*] = $(DBP_BASE_APP_GROUP) + +// IPC + +// IMPORTANT: The reason this app group was created is because IPC through +// Unix Domain Sockets requires the socket file path to be no longer than +// 108 characters. Sandboxing requirements force us to place said socket +// within an app group container. +// +// Name coding: +// - ipc.a = ipc app store release +// - ipc.a.d = ipc app store debug +// - ipc.a.r = ipc app store review +// +IPC_APP_GROUP_BASE = $(DEVELOPMENT_TEAM).com.ddg.ipc.a +IPC_APP_GROUP[config=CI][sdk=*] = $(IPC_APP_GROUP_BASE).d +IPC_APP_GROUP[config=Review][sdk=*] = $(IPC_APP_GROUP_BASE).r +IPC_APP_GROUP[config=Debug][sdk=*] = $(IPC_APP_GROUP_BASE).d +IPC_APP_GROUP[config=Release][sdk=*] = $(IPC_APP_GROUP_BASE) diff --git a/Configuration/DeveloperID.xcconfig b/Configuration/DeveloperID.xcconfig index 34dca062eb..ddbe7edc51 100644 --- a/Configuration/DeveloperID.xcconfig +++ b/Configuration/DeveloperID.xcconfig @@ -45,16 +45,6 @@ NETP_APP_GROUP[config=Review][sdk=*] = $(NETP_BASE_APP_GROUP).review NETP_APP_GROUP[config=Debug][sdk=*] = $(NETP_BASE_APP_GROUP).debug NETP_APP_GROUP[config=Release][sdk=*] = $(NETP_BASE_APP_GROUP) -// It's important to try and keep this app group short since some IPC -// mechanisms require really short paths. For instance Unix Domain Sockets -// support paths of up to 108 bytes in length -// (di = developer ID) -BASE_IPC_APP_GROUP = $(DEVELOPMENT_TEAM).com.duckduckgo.di.ipc -IPC_APP_GROUP[config=CI][sdk=macos*] = $(BASE_IPC_APP_GROUP).debug -IPC_APP_GROUP[config=Review][sdk=macos*] = $(BASE_IPC_APP_GROUP).review -IPC_APP_GROUP[config=Debug][sdk=macos*] = $(BASE_IPC_APP_GROUP).debug -IPC_APP_GROUP[config=Release][sdk=macos*] = $(BASE_IPC_APP_GROUP) - SUBSCRIPTION_BASE_APP_GROUP = $(DEVELOPMENT_TEAM).$(MAIN_BUNDLE_IDENTIFIER_PREFIX).subscription SUBSCRIPTION_APP_GROUP[config=CI][sdk=*] = $(SUBSCRIPTION_BASE_APP_GROUP).debug SUBSCRIPTION_APP_GROUP[config=Review][sdk=*] = $(SUBSCRIPTION_BASE_APP_GROUP).review @@ -110,3 +100,21 @@ DBP_APP_GROUP[config=CI][sdk=*] = $(DBP_BASE_APP_GROUP).debug DBP_APP_GROUP[config=Review][sdk=*] = $(DBP_BASE_APP_GROUP).review DBP_APP_GROUP[config=Debug][sdk=*] = $(DBP_BASE_APP_GROUP).debug DBP_APP_GROUP[config=Release][sdk=*] = $(DBP_BASE_APP_GROUP) + +// IPC + +// IMPORTANT: The reason this app group was created is because IPC through +// Unix Domain Sockets requires the socket file path to be no longer than +// 108 characters. Sandboxing requirements force us to place said socket +// within an app group container. +// +// Name coding: +// - ipc.d = ipc developer id release +// - ipc.d.d = ipc developer id debug +// - ipc.d.r = ipc developer id review +// +IPC_APP_GROUP_BASE = $(DEVELOPMENT_TEAM).com.ddg.ipc +IPC_APP_GROUP[config=CI][sdk=*] = $(IPC_APP_GROUP_BASE).d +IPC_APP_GROUP[config=Review][sdk=*] = $(IPC_APP_GROUP_BASE).r +IPC_APP_GROUP[config=Debug][sdk=*] = $(IPC_APP_GROUP_BASE).d +IPC_APP_GROUP[config=Release][sdk=*] = $(IPC_APP_GROUP_BASE) diff --git a/DuckDuckGo/Common/Extensions/BundleExtension.swift b/DuckDuckGo/Common/Extensions/BundleExtension.swift index 30d3ab26c8..65a7e638ab 100644 --- a/DuckDuckGo/Common/Extensions/BundleExtension.swift +++ b/DuckDuckGo/Common/Extensions/BundleExtension.swift @@ -138,6 +138,7 @@ extension Bundle { enum BundleGroup { case netP + case ipc case dbp case subs @@ -145,6 +146,8 @@ enum BundleGroup { switch self { case .dbp: return "DBP_APP_GROUP" + case .ipc: + return "IPC_APP_GROUP" case .netP: return "NETP_APP_GROUP" case .subs: diff --git a/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/NetworkProtectionIPCTunnelController.swift b/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/NetworkProtectionIPCTunnelController.swift index f112c33568..95b6398669 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/NetworkProtectionIPCTunnelController.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/NetworkProtectionIPCTunnelController.swift @@ -66,7 +66,7 @@ final class NetworkProtectionIPCTunnelController { self.loginItemsManager = loginItemsManager self.ipcClient = ipcClient - let socketFileURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: Bundle.main.appGroup(bundle: .netP))!.appendingPathComponent("vpn.sock") + let socketFileURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: Bundle.main.appGroup(bundle: .ipc))!.appendingPathComponent("vpn.ipc") self.udsClient = UDSClient(socketFileURL: socketFileURL, log: .networkProtectionIPCLog) self.pixelKit = pixelKit diff --git a/DuckDuckGoVPN/TunnelControllerIPCService.swift b/DuckDuckGoVPN/TunnelControllerIPCService.swift index 3ac6e3169a..011ce69b0d 100644 --- a/DuckDuckGoVPN/TunnelControllerIPCService.swift +++ b/DuckDuckGoVPN/TunnelControllerIPCService.swift @@ -50,7 +50,7 @@ final class TunnelControllerIPCService { self.statusReporter = statusReporter self.defaults = defaults - let socketFileURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: Bundle.main.appGroup(bundle: .netP))!.appendingPathComponent("vpn.sock") + let socketFileURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: Bundle.main.appGroup(bundle: .ipc))!.appendingPathComponent("vpn.ipc") udsServer = UDSServer(socketFileURL: socketFileURL, log: .networkProtectionIPCLog) diff --git a/LocalPackages/UDSHelper/Sources/UDSHelper/FileManager+shorterPath.swift b/LocalPackages/UDSHelper/Sources/UDSHelper/FileManager+shorterPath.swift index 5c315e3ea8..11416db44c 100644 --- a/LocalPackages/UDSHelper/Sources/UDSHelper/FileManager+shorterPath.swift +++ b/LocalPackages/UDSHelper/Sources/UDSHelper/FileManager+shorterPath.swift @@ -56,7 +56,11 @@ extension FileManager { // Just make extra sure there's no pre-existing file at the shortened file path //try? removeItem(at: shortenedFileURL) - try createSymbolicLink(at: shortenedFileURL, withDestinationURL: fileURL) + do { + try createSymbolicLink(at: shortenedFileURL, withDestinationURL: fileURL) + } catch { + print(error.localizedDescription) + } return shortenedFileURL } @@ -74,7 +78,7 @@ extension FileManager { let directoryURL = socketFileURL.deletingLastPathComponent() let shortenedDirectoryURL = try shortenURL(for: directoryURL, symlinkName: symlinkName) let shortSocketURL = shortenedDirectoryURL.appendingPathComponent(socketFileURL.lastPathComponent) -/* + do { try removeItem(at: shortSocketURL) } catch let error as CocoaError { @@ -85,7 +89,7 @@ extension FileManager { default: throw error } - }*/ + } return shortSocketURL } diff --git a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSClient.swift b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSClient.swift index 9acb7fdcee..07c984c4ee 100644 --- a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSClient.swift +++ b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSClient.swift @@ -65,7 +65,7 @@ public actor UDSClient { /// Establishes a new connection /// private func connect() async throws -> NWConnection { - let shortSocketURL: URL + /*let shortSocketURL: URL do { shortSocketURL = try urlShortener.shorten(socketFileURL, symlinkName: "appgroup") @@ -75,12 +75,12 @@ public actor UDSClient { type: .error, String(describing: error)) throw error - } + }*/ - os_log("UDSClient - Connecting to shortened path: %{public}@", log: log, type: .info, shortSocketURL.path) + //os_log("UDSClient - Connecting to shortened path: %{public}@", log: log, type: .info, shortSocketURL.path) - let endpoint = NWEndpoint.unix(path: shortSocketURL.path) - let parameters = NWParameters() + let endpoint = NWEndpoint.unix(path: socketFileURL.path) + let parameters = NWParameters.tcp let connection = NWConnection(to: endpoint, using: parameters) internalConnection = connection diff --git a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSServer.swift b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSServer.swift index c3c8eae628..de46bdea13 100644 --- a/LocalPackages/UDSHelper/Sources/UDSHelper/UDSServer.swift +++ b/LocalPackages/UDSHelper/Sources/UDSHelper/UDSServer.swift @@ -101,10 +101,10 @@ public final class UDSServer { let params = NWParameters() let shortSocketURL = try fileManager.shortenSocketURL(socketFileURL: socketFileURL, symlinkName: "appgroup") - os_log("UDSServer - Listening on shortened path: %{public}@", log: log, type: .info, shortSocketURL.path) + //os_log("UDSServer - Listening on shortened path: %{public}@", log: log, type: .info, shortSocketURL.path) params.defaultProtocolStack.transportProtocol = NWProtocolTCP.Options() - params.requiredLocalEndpoint = NWEndpoint.unix(path: shortSocketURL.path) + params.requiredLocalEndpoint = NWEndpoint.unix(path: socketFileURL.path) params.allowLocalEndpointReuse = true listener = try NWListener(using: params)