I'm trying to get a persistent reference for a SecIdentityRef so I can reliably retrieve it later. I've tried a variety of things in the query parameter of SecItemCopyMatching, but I can't get it to work. I know the item exists in the keychain; I just barely called SecItemAdd not long ago. Here's what I've got right now:
let identityArray: CFArray = [identity] as CFArray
let query: [CFString: AnyObject] = [kSecClass: kSecClassIdentity,
kSecMatchItemList: identityArray,
kSecReturnPersistentRef: true]
var _persistentItems: AnyObject?
let copyResult = SecItemCopyMatching(query, &_persistentItems)
// copyResult is -50 (errSecParam)
I've tried the following other queries as well:
let query = [kSecMatchItemList: selfArray,
kSecReturnPersistentRef: true] // Produces -50 (errSecParam)
let query = [kSecClass: kSecClassIdentity,
kSecValueRef: identity,
kSecReturnPersistentRef: true] // Produces -25291 (errSecNotAvailable)
let query = [kSecValueRef: self,
kSecReturnPersistentRef: true] // Produces -25300 (errSecItemNotFound)
Is it possible to get a persistent keychain ref to a SecIdentityRef on iOS? (For that matter, I need to do the same on OS X, but I've generally found that the OS X APIs are more likely to do what I expect.)