我正在使用 TunnelKit 库创建一个 VPN macOS 应用程序。
我有配置/创建连接的代码:
func connectToVPN() async {
guard let cfg = WireGuard.Configuration.make(
"Meter VPN",
appGroup: appGroup,
clientPrivateKey: clientPrivateKey,
clientAddress: clientAddress,
serverPublicKey: serverPublicKey,
serverAddress: serverAddress,
serverPort: serverPort
) else {
print("Configuration incomplete")
return
}
Task {
do {
try await vpn.reconnect(
tunnelIdentifier,
configuration: cfg,
extra: nil,
after: .seconds(2)
)
print("VPN connection started successfully")
} catch {
print("Failed to connect to VPN: \(error.localizedDescription)")
}
}
print("ERROR: \(cfg.lastError)")
}
我已验证所有配置值都是正确的。
这里是我目前设置我的
appGroup
和tunnelIdentifier
值的地方:
private let appGroup = "MY_ID.group.com.meter.test.WireGuard"
private let tunnelIdentifier = "com.meter.MeterTunnel.Tunnel"
在我的项目设置中,我启用了应用程序目标和扩展的数据包隧道功能:
我对 App Groups 和 Keychain Sharing 有以下值:
最后,这是我为应用程序的包 ID 设置的内容:
扩展名:
我再次与同事核实所有网络特定值似乎都是正确的;我的直觉是目前我设置应用程序组/钥匙串共享等的方式有问题
在我的系统偏好设置中,我可以看到我的 VPN 配置已添加;但我什至无法打开和关闭按钮。连接永远不会发生。
非常感谢任何帮助。