ios - 连接 VPN IKEv2 它可以在 iOS 平台上工作,但 macOS 无法工作,面临同样的问题
问题描述
我在 macOS Development 上连接 IKEv2 协议时遇到问题,程序在断开连接时工作正常但是当我进行连接时需要继续设置连接
我正在使用 IKEv2 协议进行 VPN 连接,使用 NetworkExtention 文件,
public func connectIKEv2(config: Configuration, onError: @escaping (String)->Void) {
let p = NEVPNProtocolIKEv2()
if config.pskEnabled {
p.authenticationMethod = NEVPNIKEAuthenticationMethod.sharedSecret
} else {
p.authenticationMethod = NEVPNIKEAuthenticationMethod.none
}
p.serverAddress = config.server
p.disconnectOnSleep = false
p.deadPeerDetectionRate = NEVPNIKEv2DeadPeerDetectionRate.medium
p.username = config.account
p.passwordReference = config.getPasswordRef()
p.sharedSecretReference = config.getPSKRef()
p.disableMOBIKE = false
p.disableRedirect = false
p.enableRevocationCheck = false
p.enablePFS = false
p.useExtendedAuthentication = true
p.useConfigurationAttributeInternalIPSubnet = false
// two lines bellow may depend of your server configuration
p.remoteIdentifier = config.server
p.remoteIdentifier = config.remote
p.localIdentifier = config.account
loadProfile { _ in
self.manager.protocolConfiguration = p
if config.onDemand {
self.manager.onDemandRules = [NEOnDemandRuleConnect()]
self.manager.isOnDemandEnabled = true
}
self.manager.isEnabled = true
self.saveProfile { success in
if !success {
onError("Unable to save vpn profile")
return
}
self.loadProfile() { success in
if !success {
onError("Unable to load profile,")
return
}
let result = self.startVPNTunnel()
print("Show Result, \(result)")
if !result {
onError("Can't connect")
}
}
}
}
}
private func startVPNTunnel() -> Bool {
do {
try self.manager.connection.startVPNTunnel()
return true
} catch NEVPNError.configurationInvalid {
NSLog("Failed to start tunnel (configuration invalid)")
} catch NEVPNError.configurationDisabled {
NSLog("Failed to start tunnel (configuration disabled)")
} catch {
NSLog("Failed to start tunnel (other error)")
}
return true
}
我正面临 macOS 开发的错误,
open(/var/db/DetachedSignatures) - 未定义错误:0 连接错误:无法加载配置文件,
但是一些关于iOS开发的代码工作文件,
解决方案
推荐阅读
- python - 通过 LAN 连接 RFC 2217 激光器 - Python
- python - 从 2D Numpy 数组中获取前 N 个值及其坐标
- git - 如何配置 Git 或 Gitlab,以便只允许分支的所有者推入它?
- splunk - 需要在 Splunk 中创建一个嵌套表或多列的表
- r - 在 R 的子函数中使用两列
- vb6 - 没有特定 DLL 引用的 VB6 项目编译
- twitter-bootstrap - 如何使我的 Bootstrap 日期选择器工作,是否有“官方”Bootstrap 3 日期选择器?
- spring - Spring Security:反向代理后面的 X509(预)身份验证
- python - 如何在不调用 Python 中的方法的情况下更改类中的属性值?
- hibernate - Hibernate Unknown 列字段列表“clazz_”