TunnelProvider Crashing with Fatal Error in WireGuard Kit VPN Application

Title: TunnelProvider Crashing with Fatal Error in WireGuard Kit VPN Application

Body:

Hi everyone,

I’m working on building a VPN application based on the WireGuard Kit, but I’m encountering a strange issue where the TunnelProvider crashes with a fatal error. I would really appreciate any help or insights on how to resolve this problem.

Here’s a detailed description of the issue:

Error Message:

Fatal error: self must be a properly aligned pointer for types Pointee and T

Logs:

default17:46:09.277187+0300TunnelProviderExtension /private/var/containers/Bundle/Application/60D347EC-2894-45C1-B131-7C14350A8DC9/***.app/PlugIns/TunnelProvider.appex/TunnelProvider of type: (null) launched.
default17:46:09.277236+0300TunnelProviderHello, I’m launching as euid = 501, uid = 501, personaid = 1000, type = DEFAULT, name = 
default17:59:54.991718+0300TunnelProvider[Extension ***.***.*****.TunnelProvider]: Calling startTunnelWithOptions with options 0x0
default17:59:54.991831+0300TunnelProviderRequesting app group container lookup; personaid = 1000, type = DEFAULT, name = ACC421CC-07D3-4B7A-A105-E3667FCF6E7F, origin [pid = 3112, personaid = 99], proximate [pid = 3495, personaid = 199], identifier = , euid = 501, uid = 501, platform = 2
default17:59:54.995994+0300TunnelProvider[LOG] Starting tunnel from the OS directly, rather than the app
default17:59:54.996017+0300TunnelProvider[LOG] Loaded configuration from provider configuration.
default17:59:54.996438+0300TunnelProvidernw_path_evaluator_start [99AE5F38-3D18-4F00-9306-95AE30A04EA2  generic, multipath service: 1, attribution: developer]
path: satisfied (Path is satisfied), interface: pdp_ip0[lte], scoped, ipv6, dns, expensive, uses cell
default17:59:54.996507+0300TunnelProvidernw_path_libinfo_path_check [AE278BF5-3C14-4694-AC4E-B39EE4493A5D Hostname#4fec4f59:1024 tcp, legacy-socket, attribution: developer]
libinfo check path: satisfied (Path is satisfied), interface: pdp_ip0[lte], scoped, ipv6, dns, expensive, uses cell
default17:59:55.001566+0300TunnelProviderSwift/arm64-apple-ios.swiftinterface:24059: Fatal error: self must be a properly aligned pointer for types Pointee and T

VPN Configuration I’m Using (Free VPN) that works on macOS official app:

[Interface]
Address = 192.168.6.217/32
DNS = 1.1.1.1,8.8.8.8
PrivateKey = mCFRvM8LShpTq6Zhanr8yCu65zYAiGB4jUWCli/EAWo=

[Peer]
publickey=/34Vt3UbFYMBM7UIVGl/AEoGFXPHrdwylJL7zKamHB0=
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = az1.vpnjantit.com:1024

iOS Code:

private func connect() async throws {
    NETunnelProviderManager.loadAllFromPreferences { (managers, error) in
        guard error == nil else {
            print("Error loading managers: \(error!)")
            return
        }
        
        let manager = managers?.first ?? NETunnelProviderManager()
        
        let protocolConfiguration = NETunnelProviderProtocol()
        protocolConfiguration.providerBundleIdentifier = "***.***.*****.TunnelProvider"
        
        let wgQuickConfig = """
        [Interface]
        Address = 192.168.6.217/32
        DNS = 1.1.1.1,8.8.8.8
        PrivateKey = mCFRvM8LShpTq6Zhanr8yCu65zYAiGB4jUWCli/EAWo=
        
        [Peer]
        publickey=/34Vt3UbFYMBM7UIVGl/AEoGFXPHrdwylJL7zKamHB0=
        AllowedIPs = 0.0.0.0/0, ::/0
        Endpoint = az1.vpnjantit.com:1024
        """
        
        protocolConfiguration.providerConfiguration = ["wgQuickConfig": wgQuickConfig]
        protocolConfiguration.serverAddress = "az1.vpnjantit.com:1024"
        
        manager.protocolConfiguration = protocolConfiguration
        manager.localizedDescription = "WireGuard VPN"
        manager.isEnabled = true
        
        manager.saveToPreferences { error in
            if let error = error {
                print("Error saving preferences: \(error)")
            } else {
                print("Saved preferences successfully")
                
                NETunnelProviderManager.loadAllFromPreferences { (managers, error) in
                    guard let manager = managers?.first, error == nil else {
                        print("Error loading VPN configurations: \(error!)")
                        return
                    }
                    
                    do {
                        try manager.connection.startVPNTunnel()
                        print("VPN started successfully")
                    } catch {
                        print("Error starting VPN: \(error)")
                    }
                }
            }
        }
    }
}

Upvotes: 0

Views: 54

Answers (0)

Related Questions