I`m trying to make my own OpenVPN client using NetworkExtension. I'm following these instructions:
https://github.com/ss-abramchuk/OpenVPNAdapter
But I cant get it to work. I create my manager succesfully, without any errors. But then when I call startTunnel() nothing happens. No error (I have my try/catch in place) and nothing in the log. I have the NetworkExtension entitlements in both my targets. This is the code in question:
NETunnelProviderManager.loadAllFromPreferences { (managers, error) in
guard error == nil else {
NSLog("Unexpected error: \(error).");
return
}
/
if (managers?.count != 0)
{
do
{
NSLog("Found VPN with target \(managers?[0].localizedDescription)")
managers?[0].isEnabled = true;
try managers?[0].connection.startVPNTunnel();
}
catch
{
NSLog("Unexpected error: \(error).");
}
}
/
else
{
NSLog("Not found, creating new");
let manager = NETunnelProviderManager();
/
guard
let configurationFileURL = Bundle.main.url(forResource: "config", withExtension: "ovpn"),
let configurationFileContent = try? Data(contentsOf: configurationFileURL)
else {
fatalError()
}
let tunnelProtocol = NETunnelProviderProtocol()
tunnelProtocol.serverAddress = ""
tunnelProtocol.providerBundleIdentifier = "com.vpn.xxx.TunnelManager";
tunnelProtocol.providerConfiguration = ["ovpn": configurationFileContent]
manager.protocolConfiguration = tunnelProtocol
manager.localizedDescription = "My VPN"
manager.isEnabled = true
/
manager.saveToPreferences(completionHandler: { (error) in
if let error = error {
print(error);
}
manager.loadFromPreferences(completionHandler: {(error) in
do
{
try manager.connection.startVPNTunnel();
}
catch
{
NSLog("Unexpected error: \(error).");
}
})
});
}
I changed the blunde identifier for privacy reasons.
I hope somebody can help me with my problem, if you need the contents of another file, or any other information, please ask.
Thanks in advance.