我从 Android 获取 .ovpn 文件,我有用户名和密码,我应该连接到 vpn 服务器,但我不知道该怎么做。我试过这样的事情:
let manager = NEVPNManager.sharedManager()
manager.loadFromPreferencesWithCompletionHandler { (error) -> Void in
if manager.`protocol` == nil {
let newIPSec = NEVPNProtocolIKEv2()
newIPSec.serverAddress = "xxx.xxx.xxx.xxx"
newIPSec.username = "username"
let keychain = Keychain(service: "com.app.ios")
let data = keychain[data: "vpnpassword"]
newIPSec.passwordReference = data
newIPSec.authenticationMethod = NEVPNIKEAuthenticationMethod.None
newIPSec.disconnectOnSleep = false
manager.`protocol` = newIPSec
manager.enabled = true
manager.saveToPreferencesWithCompletionHandler({ (error) -> Void in
print(error)
})
}
}
我不知道如何添加证书(<ca>
在.ovpn 之间)信息以及如何设置它。文件 .ovpn 看起来像这样(我只是删除<ca>
标签中的数据并更改服务器地址:
client
dev tun
proto udp
remote xx.xx.xx.xx 443
resolv-retry infinite
nobind
persist-key
persist-tun
verb 3
<auth-user-pass>
#username#
#userpass#
</auth-user-pass>
cipher AES-256-CBC
<ca>
-----BEGIN CERTIFICATE-----
xxx
-----END CERTIFICATE-----
</ca>
谢谢你的帮助