1

I'm trying to start the vpn provider from a container application

After I successfully activated the extension, and started the process by sending xpc request to the network extension, I've tried to load the provider and start getting notifications about handleNewFlow

I use the following callback to signal process has started, in order to start the configuration phase.

extension NetworkExtensionManager: OSSystemExtensionRequestDelegate {
...
    func request(_ request: OSSystemExtensionRequest, 
                didFinishWithResult result: OSSystemExtensionRequest.Result) {
...

After loadAllPreferences, I've set the manager from which I'd like to load the provider:

NEAppProxyProviderManager.loadAllFromPreferences { [self] (managers, error) in
            assert(Thread.isMainThread)
            if let error = error {
                print(error.localizedDescription)
            } else {
                let manager = managers?.first ?? NEAppProxyProviderManager()
                let proto = (manager.protocolConfiguration as? NETunnelProviderProtocol) ?? NETunnelProviderProtocol()
                proto.serverAddress = "myHost"
                proto.providerBundleIdentifier = "myExtensionBundle"
                proto.providerConfiguration = ["key": "val"]
                manager.localizedDescription = "myApp"
                manager.protocolConfiguration = proto
                manager.isEnabled = true

Then I extract the connection out of the manager and use it to start the tunnel provider (hopefully this operation will create a new item under System Preferences --> Network)

let session = manager.connection as! NETunnelProviderSession
do {
  os_log(" manager.connection status: \(session.status.rawValue)")
  try session.startVPNTunnel(options: nil)
}
catch {
  os_log("failed to initProviderManager app proxy provider, \(error.localizedDescription)")
  print(error)
}

However, I've got the following error message from the exception thrown out of this line session.startVPNTunnel :

failed to initProviderManager app proxy provider, The operation couldn’t be completed. (NEVPNErrorDomain error 1.)

Looking for the error name I found this NEVPNErrorConfigurationInvalid

Perhaps you can help me figure out where I go wrong in my attempt to start the tunnel provider ?

Thanks !

Zohar81
  • 4,554
  • 5
  • 29
  • 82

0 Answers0