我想从沙盒化的macOS应用程序中访问其他应用程序(不同供应商,不能在一个组中共享)的钥匙串应用程序密码(kSecClassGenericPassword
)。
我设想的方式是为用户提供一个按钮“从VendorApp重用密码”。然后为服务/帐户运行SecItemCopyMatching()
。然后,我希望钥匙串系统本身会弹出一个对话框,提示用户允许或拒绝该操作。
现在这几乎可以工作了,SecItemCopyMatching
确实返回了带有一些元数据的结果。但是它不会返回实际数据,也不会提示用户。
所以问题是:如何获得钥匙串服务以提示用户允许向我的应用程序提供数据? kSecUseAuthenticationUI
有点建议这样做。
这是我正在尝试的:
let query : [ String : Any ] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: account,
kSecAttrService as String: service,
kSecReturnAttributes as String: true,
kSecMatchLimit as String: kSecMatchLimitOne,
kSecUseAuthenticationUI as String: kSecUseAuthenticationUIAllow,
kSecUseOperationPrompt as String: "Login Using VendorApp"
]
var item : CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &item)
// status gives errSecSuccess and we do get some proper item fields
// always empty, obviously, it would need to prompt the user for permission
let data = item?[kSecValueData as String] as? Data