Hi everyone
My app is facing strange keychain behaviour: sometimes it returns -25300 status instead of credentials that definitely exists, so logged in users randomly becomes "logged out".
App restart doesn't help, only new user authorization.
Seems like items just disappearing from keychain for some reason.
After looking closer at code that saves and reads data from keychain and comparing it with Apple's sampes, i noticed that we don't use kSecAttrService attribute when saving item of kSecClassGenericPassword class.
Here is some code snippets:
So, may the absence of kSecAttrService when saving kSecClassGenericPassword items be the reason why keychain items become unreachable for some reason, or is there any other reason?
Thanks
My app is facing strange keychain behaviour: sometimes it returns -25300 status instead of credentials that definitely exists, so logged in users randomly becomes "logged out".
App restart doesn't help, only new user authorization.
Seems like items just disappearing from keychain for some reason.
After looking closer at code that saves and reads data from keychain and comparing it with Apple's sampes, i noticed that we don't use kSecAttrService attribute when saving item of kSecClassGenericPassword class.
Here is some code snippets:
Code Block func saveData(_ data: Data, for key: String) -> OSStatus { let query: [CFString : Any] = [ kSecClass: kSecClassGenericPassword, kSecAttrAccount: key, kSecValueData: data, kSecAttrAccessible: kSecAttrAccessibleWhenUnlockedThisDeviceOnly ] return SecItemAdd(query as CFDictionary, nil) }
Code Block func readData(for key: String) -> String? { let query: [CFString: Any] = [ kSecClass: kSecClassGenericPassword, kSecAttrAccount: key, kSecReturnData: kCFBooleanTrue as Any, kSecMatchLimit: kSecMatchLimitOne ] var result: AnyObject? _ = withUnsafeMutablePointer(to: &result) { SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0)) } return (result as? Data).flatMap { String(data: $0, encoding: .utf8) } }
So, may the absence of kSecAttrService when saving kSecClassGenericPassword items be the reason why keychain items become unreachable for some reason, or is there any other reason?
Thanks