Search code examples
swiftxcodetunnelnetworkextensionwireguard

When using TunnelKit in iOS VPN app, iPhone Settings -> VPN is connected, but I have no access to internet


QUESTION: What am I missing in implementation of TunnelKit in order to use it's tunneling capabilities and have internet access?

I started making a VPN iOS app and decided to use TunnelKit library: https://github.com/passepartoutvpn/tunnelkit

I followed README installation and setup steps and managed to get the app running. When activating VPN (calling connect() function) I managed to get it to be on when checking iPhone Settings -> VPN Settings. Issue: I don't have access to internet, cannot load any website.

Then I tried downloading the repo for TunnelKit: https://github.com/passepartoutvpn/tunnelkit and using demo app to test if my server side is working properly or is there some issue with the library. Still the same, VPN is connected but no access to internet.

Then I decided to test server side with WireGuard VPN app: https://apps.apple.com/de/app/wireguard/id1451685025?l=en-GB&mt=12

And also another Free VPN app.

They both managed to set the VPN to connected AND TO HAVE internet access.

Now I don't know where to look anymore. At first I'd say there's an issue on library itself but there was no "Issue" raised on their GitHub page.

Points of interest:

PacketTunnelProvider:

    import Foundation
    import TunnelKitWireGuardAppExtension
    
    class PacketTunnelProvider: WireGuardTunnelProvider {
        override func startTunnel(options: [String: NSObject]? = nil) async throws {
            try await super.startTunnel(options: options)
        }
    }

My project settings looks like this: (https://i.sstatic.net/zRZpG.png)

App entitlements: (https://i.sstatic.net/dPgUm.png)

WireGuardNetworkExtension: (https://i.sstatic.net/GIJee.png)


Solution

  • I think your "options" (configurations) have some missing parts,

    PeerConfiguration with public key and, allowedIPs as an array, endpoint, preSharedKey (obligatory)

    InterfaceConfiguration with private key and, DNSServers as an array, Addresses (IPAddressRange), MTU

    must be set and correct format.

    Also you can check your Network extension (PacketTunnelProvider) using os_log and Console app from Mac. Is it throwing any error?