Hi All, I am currently working on a Network Extension App for MacOS using 3 types of extensions provided by Apple's Network Extension Framework.
Content Filter, App Proxy (Want to get/capture/log all HTTP/HTTPS traffic), DNS Proxy (Want to get/capture/log all DNS records). Later parse into human readable format.
- Is my selection of network extension types correct for the intended logs I need?
I am able to run with one extension: Main App(Xcode Target1) <-> Content Filter Extension. Here there is a singleton class IPCConnection between App(ViewController.swift) which is working fine with NEMachServiceName from Info.plist of ContentFilter Extension(Xcode Target2)
However, when I add an App Proxy extension as a new Xcode Target3, I think the App and extension's communication getting messed up and App not getting started/Crashing. Here, In the same Main App, I am adding new separate IPCConnection for this extension.
Here is the project organization/folder structure.
MyNetworkExtension
├──MyNetworkExtension(Xcode Target1)
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ ├── Info.plist
│ ├── MyNetworkExtension.entitlement
│ | ── Main
│ |-----ViewController.swift
│ └── Base.lproj
│ └── Main.storyboard
├── ContentFilterExtension(Xcode Target2)
│ ├── ContentFilterExtension.entitlement
│ │ ├── FilterDataProvider.swift
│ │ ├── Info.plist
│ │ ├── IPCConnection.swift
│ │ └── main.swift
├── AppProxyProviderExtension(Xcode Target3)
│ ├── AppProxyProviderExtension.entitlement
│ │ ├── AppProxyIPCConnection.swift
│ │ ├── AppProxyProvider.swift
│ │ ├── Info.plist
│ │ └── main.swift
└── Frameworks
├── libbsm.tbd
└── NetworkExtension.framework
- Is my Approach for creating a single Network Extension App with Multiple extensions correct or is there any better approach of project organization that will make future modifications/working easier and makes the maintenance better?
I want to keep the logic for each extension separate while having the same, single Main App that manages everything(installing, activating, managing identifiers, extensions, etc).
-
What's the best approach to establish a Communication from MainApp to each extension separately, without affecting one another? Is it good idea to establish 3 separate IPC Connections(each is a singleton class) for each extension?
-
Are there any suggestions you can provide that relates to my use case of capturing all the network traffic logs(including HTTP/HTTPS, DNS Records, etc), especially on App to Extension Communication, where my app unable to keep multiple IPC Connections and maintain them separately?
I've been working on it for a while, and still unable to make the Network Extension App work with multiple extensions(each as a new Xcode target).
Main App with single extension is working fine, but if I add new extension, App getting crashed. I suspect it's due to XPC/IPC connection things!
I really appreciate any support on this either directly or by any suggestions/resources that will help me get better understand and make some progress.
Please reach out if in case any clarifications or specific information that's needed to better understand my questions.
Thank you very much
We do allow you to embed multiple network extensions in the same app. That’s true on all our platforms, although the mechanics vary based on whether you’re using a system extension (sysex) or an app extension (appex). For more info about what packaging is supported on what platforms, see TN3134 Network Extension provider deployment.
It sounds like you’re using a sysexes, and that presents a decision point:
- You can have multiple independent sysex, each with a single NE provider.
- Or you can have a single sysex with multiple NE providers.
The latter is generally easier to wrangle. In that case you have a single sysex target with multiple NE provider subclasses linked into the resulting executable, and then list all of those in the NEProviderClasses
dictionary in your sysex’s Info.plist
.
IMPORTANT If you set things up this way there’s a single sysex process and all of your NE providers run within that. This has pros (you can share data between them) and cons (if one crashes, they all crash).
Of specific interest is:
- You have to configure each provider independently using its corresponding
NEXxxProviderManager
type. So, even though they’re all in the same sysex, you can enable and disable each one at will. - If you use XPC to talk to your sysex, there’s only one named endpoint, identified by the
NEMachServiceName
property.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"