Connection to IKEv2 VPN Server

I'm Using NEVPNManager to Connect to IKEv2 VPN Server which uses certificate in p12 or .cer file to authenticate for connection.

here my code snippet for connecting to server.


Code Block    
    let vpnManager = NEVPNManager.shared();
        vpnManager.loadFromPreferences { (_: Error?) in
            
        }
        
        let p = NEVPNProtocolIKEv2()
        p.authenticationMethod = NEVPNIKEAuthenticationMethod.none
        p.useExtendedAuthentication = true
        p.serverAddress = "******"
        p.remoteIdentifier = "*****"
        p.disconnectOnSleep = false
        let certificateFile = Bundle.main.path(forResource: "myvpn", ofType: "p12")!
        let certificateData = NSData(contentsOfFile: certificateFile)!
        p.identityData = certificateData as Data
        p.identityDataPassword = "*******"
        vpnManager.protocolConfiguration = p
        vpnManager.localizedDescription = "Apple VPN"
        vpnManager.isEnabled = true
        vpnManager.saveToPreferences(completionHandler: nil)
        vpnManager.loadFromPreferences { (_: Error?) in
            
        }
        
        do{
            try vpnManager.connection.startVPNTunnel()
        }catch{
            print(error)
        }


This Code will create a vpn profile in vpn section of iOS setting part.

The Problem is that I can not understand how should I pass the .p12 file or .cer file to NEVPNProtocolIKEv2 for authentication.

Note : Currently I am able to connect to server by installing .p12 and .cer file manually in setting. so the server is up and working without any problem.

Is this way wrong ?
How can I connect to IKEv2 VPN Server Programmatically?

Thanks



Is this way wrong ?
How can I connect to IKEv2 VPN Server Programmatically?

When using an PKCS12 you can use identityReference which is a reference to an identity saved in the keychain. When using identityData you can load the identity in this way but take a look at your server logs for more information on how to debug this. You may be in a situation where the identity is malformed and not used by NEVPNManager or that the server is rejecting it for some reason.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Connection to IKEv2 VPN Server
 
 
Q