背景
我正在尝试构建一个使用本机 IKEv2 实现连接到 VPN 的应用程序。该应用程序应该为 iOS 构建,但也可以使用 Catalyst 平台在 macOS 上运行。
情况
在 iOS/macOS 中使用本机 IKEv2 实现连接到 VPN 时 - 要使用用户名和密码身份验证,应用程序必须将持久钥匙串引用传递给包含密码的钥匙串项。 (参考 https://developer.apple.com/documentation/networkextension/nevpnprotocol/1406650-passwordreference)
Problem
在 iOS 上它工作得很好,但是当在 Catalyst 平台上启动 VPN 连接时,VPN 服务无法使用给定的持久引用检索密码。控制台打印:
[] (null): Failed to copy content, SecKeychainItemCopyContent returned The contents of this item cannot be retrieved.
钥匙串项存储在钥匙串中,而不是持久引用nil
,但由于某种原因,OS的VPN服务无法检索密码。
如果我尝试使用相同的持久引用检索密码 - 一切都会按预期工作并且密码会被检索。
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrPersistentReference as String: persistentRef,
kSecReturnData as String: true
]
var item: CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &item)
任何信息都将受到高度赞赏。也许在将密码保存到钥匙串时应该添加一些标志?当专门在 Catalyst 平台上从钥匙串检索持久引用时,也许应该添加一些标志?