We are trying to connecting vpn (TCP & UDP) through “.ovpn” configuration using TunnelKit, But after calling startTunnel NEPacketTunnelProvider is not initiating.
Here's code:
private func makeProtocol() -> NETunnelProviderProtocol {
let credentials = OpenVPN.Credentials(textUsername.text!, textPassword.text!)
let configurationFileURL = Bundle.main.url(forResource: “xyz”, withExtension: "ovpn")
do {
let file = try OpenVPN.ConfigurationParser.parsed(fromURL: configurationFileURL!).configuration
var builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: file)
builder.mtu = 1450
builder.shouldDebug = true
builder.masksPrivateData = false
let configuration = builder.build()
return try! configuration.generatedTunnelProtocol(
withBundleIdentifier: ViewController2.tunnelIdentifier,
appGroup: ViewController2.appGroup,
credentials: credentials
)
} catch {
print("Failed to send a message to the provider")
return NETunnelProviderProtocol()
}
}
func connect() {
configureVPN({ (manager) in
return self.makeProtocol()
}, completionHandler: { (error) in
if let error = error {
print("configure error: \(error)")
return
}
self.currentManager?.isEnabled = true
let session = self.currentManager?.connection as! NETunnelProviderSession
do {
try session.startTunnel()
print("start Tunnel called")
} catch let e {
print("error starting tunnel: \(e)")
}
})
}