5

I'm trying to implement a packet sniffer similar to Charles for iOS using iOS's NetworkExtension framework.

Objective

So, that's a big goal and I'm breaking it down into a tiny piece right now: I want to see the os_log from my NEPacketTunnelProvider (bottom box in diagram)

enter image description here

What I have done so far

  1. I have created a NetworkExtension target on type PacketTunnel. This is the code snippet in the 3rd box in the diagram titled "NEPacketTunnelProvider".
  2. I have included the "app groups", "personal VPN", and "Network extension" capabilities from within XCode.

Question

I am looking in the Console.app to see the output from os_log("STARTING TUNNEL!!!!"). When I load the configuration and make the call to startVPNTunnel(), why is my TunnelProvider code never called?

I have verified that startVPNTunnel() is being called by placing a breakpoint in my code.

wheresmycookie
  • 683
  • 3
  • 16
  • 39
  • Have you achieved this local Tunnel Provider? – GGirotto Mar 17 '20 at 13:31
  • I have the same issue. Did you manage to find a solution? All my entitlements are setup right, im looking at logs in Console.app. I added Sandbox to my entitlements (both) with value YES. Still can not get the NEPacketTunnelProvider subclasses override startTunnel to log – sam k Apr 17 '20 at 16:47

2 Answers2

4

There are a good number of reasons why your network extension process may not be starting:

  1. I would put a breakpoint on the os_log("STARTING TUNNEL!!!!") and attach to your network extension process in Xcode via Debug -> Attach to Process by PID or Name... before you attempt to start the VPN
  2. The network extension must extend the bundle id of the containing app. E.g. if the containing app is com.example.vpn then the network extension might be com.example.vpn.tunnel.
  3. Ensure that your Network Extension Info.plist contains the NSExtension dictionary with NSExtensionPointIdentifier and NSExtensionPrincipalClass containing com.apple.networkextension.packet-tunnel and your NEPacketTunnelProvider class (e.g. $(PRODUCT_MODULE_NAME).PacketTunnelProvider) respectively.
  4. Is the Packet Tunnel Provider Network Extension entitlement applied to both the containing application and the network extension?
  5. If you are implementing a Packet Tunnel Provider, you do not want to enable the Personal VPN entitlement.
Jordan Johnson
  • 669
  • 3
  • 16
  • 1
    I actually learned that there was a license agreement that somebody on the team had to accept before I could use the extension, but there was no error thrown. That said, this is a really useful checklist, so I'll accept in case anybody is having issues in the future. Thanks! – wheresmycookie Jun 19 '19 at 12:40
  • Hey @wheresmycookie may you help in same case my startTunnel is also not calling in extension – Abhimanyu Daspan Sep 04 '19 at 09:58
  • @AbhimanyuRathore can you provide more information? What have you tried and what issues do you currently have? – wheresmycookie Sep 04 '19 at 15:57
  • Dear @wheresmycookie first of all thanks for response. I created an app with packet tunnel extension and followed all 2 app ids instructions ant set everything . but my extension "startTunnel" is not calling :( I am trying to connect a IKEv2 Server ( which is connected with NEVPNManager ) successfully. also loaded Configuration Profile in iPad Successfully by apple's guideline:- https://developer.apple.com/documentation/networkextension/netunnelprovidermanager – Abhimanyu Daspan Sep 05 '19 at 05:38
  • 1
    VPN Status is stuck in "Connecting" rather than "Connected" :( – Abhimanyu Daspan Sep 05 '19 at 05:39
  • there I want your support to convert this in to connected + StartTunnel Call – Abhimanyu Daspan Sep 05 '19 at 05:40
1

in startVPNTunnel func ,you should call setTunnelNetworkSettings,then the tunnel will started, after that ,you can read/write packet.

setTunnelNetworkSettings(nil) {  error in
            pendingStartCompletion(error)
            
 }
loader
  • 81
  • 9