Skip to content

Instantly share code, notes, and snippets.

@tylerhall
Created February 2, 2011 15:27
Show Gist options
  • Save tylerhall/807838 to your computer and use it in GitHub Desktop.
Save tylerhall/807838 to your computer and use it in GitHub Desktop.
Here's the problem I was having...
I have a singleton object which is first instantiated inside my NSDocument's windowControllerDidLoadNib:. It attempts to fetch a password from the user's default keychain using EMKeychain[1]. For over a week, this was working fine.
At some point I noticed that the password fetch would fail with an errSecAuthFailed error. However, it would only fail on every other app launch. Literally. Launch the app, it works. Quit, relaunch (with or without rebuilding) and it fails. Quit, launch again, it works. I reproduced this behavior 20 launches in a row, consistently. Cleaning all and rebuilding didn't change anything. Neither did locking/unlocking the keychain, restarting the Mac, etc.
After going back through numerous revisions, I tracked the problem down to the build where I first added Sparkle. Because this app is currently in beta testing, I have Sparkle configured to check for updates on every launch inside my app delegate like so:
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self.sparkle setDelegate:self];
[self.sparkle setSendsSystemProfile:YES];
[self.sparkle checkForUpdatesInBackground];
}
Going through that build, I found I could turn the error behavior on/off simply by removing Sparkle's SUFeedURL entry from my Info.plist. Sparkle would then, of course, complain and fail at checking for updates, but the keychain error immediately went away.
Looking through the Sparkle docs I found that it will also look in NSUserDefaults for SUFeedURL if it's not found in Info.plist. Moving the key into NSUserDefaults solved the problem. Sparkle and the keychain code are both working properly now.
So what was actually causing the problem? No idea. It's a rabbit hole I haven't had time to look into yet.
My gut tells me it's a code signing problem that's preventing the system from granting my app access to the keychain. However, that doesn't explain the "works one time, doesn't work the next" behavior. Or why moving the Sparkle key makes a difference. So, who knows?
[1] http://extendmac.com/EMKeychain/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment