我正在使用Swift 4.x访问运行macOS 10.12.6的Mac上的钥匙串。
我想导出钥匙串中当前存在的所有身份。可以与以下代码完美配合:
var item: CFTypeRef?
let getquery: [String: Any] = [
kSecClass as String: kSecClassIdentity,
kSecMatchLimit as String: kSecMatchLimitAll,
kSecReturnRef as String: kCFBooleanTrue
]
let status = SecItemCopyMatching(getquery as CFDictionary, &item)
guard status == errSecSuccess else {
print(SecCopyErrorMessageString(status, nil) as Any)
return
}
let items = item as! CFArray?
for i in items as! [SecIdentity] {
print(i)
}
var params = SecItemImportExportKeyParameters()
params.passphrase = Unmanaged.passRetained("1234" as AnyObject)
var exported: CFData?
let exportstatus = SecItemExport(items!, .formatPKCS12, SecItemImportExportFlags(), ¶ms, &exported)
guard exportstatus == errSecSuccess else {
print("Error: ", SecCopyErrorMessageString(exportstatus, nil) as Any)
return
}
问题是,每个身份两次要求用户输入密码。这是一个问题,因为某些用户可以拥有20个或更多的证书。
是否有可能只询问用户一次并获得对钥匙串的完全访问权限?
谢谢:)