views:

111

answers:

1

Hi.

i'm writing an app that stores passwords on the keychain, and later obtains them with SecKeychainFindGenericPassword(). this works file 90% of the time, but every once in a while, the call to SecKeychainFindGenericPassword() will fail with errSecAuthFailed (-25293). when it does, just trying again, or restarting the app fixes it.

does anyone have an idea what could be causing this? general Google search on this error points to keychain corruption or the keychain being locked - neither of which is the case here, since subsequent calls succeed again...

+1  A: 

This link suggests the passphrase you entered is not correct. See Here Is it possible that sometimes you are sending a null object as a passphrase just by chance?

Alternatively, you could try out EMKeychain. I have a more up-to-date version on GitHub here: http://github.com/ctshryock/EMKeychain

ctshryock
i'm not passing any passphrase. here is what i'm calling:SecKeychainItemRef keychainItem = 0;UInt32 length;void *data;NSString *account = [MY_HOST_NAME stringByAppendingFormat:@":%@", login];OSStatus s = SecKeychainFindGenericPassword (nil, strlen(MY_APPNAME), MY_APPNAME, [account length], [account cStringUsingEncoding:NSUTF8StringEncoding], if (s != 0) NSLog(@"Error %d obtaining password from keychain.", s);my keychain is never locked while i'm testing this, fwiw. when it fails, after just restarting the apps, it works again.
marc hoffman
opps. that doesn't render well, looks like SO removes all the linebreaks :(
marc hoffman
ps: when i actually do log the keychain, i get the proper prompt to unlock it, and all works fine after that, as well.
marc hoffman