Retrieving saved passwords from a keychain does not go beyond Xcode

I store shared passwords in the key chain after the Apple example code in the Key Key Programming Guide.

Everything works fine while I run the application in debug mode from Xcode. However, when I archive and export the application, it will still save passwords (visible in Keychain Access), but will not be able to recover them.

The key fob always returns errSecAuthFailed (-25293). This happens on Mountain Lion, but not on Snow Leopard. My application has code signed and isolated. It seems to me that when receiving a password, keychain does not recognize the application as the one that stores the password, because when I set a password to access any application, it also works well.

I am using the following code:

+ (NSString*) retrievePasswordFromKeychainWithKey: (NSString*) theKey { SecKeychainUnlock(NULL, 0, NULL, FALSE); const char* userNameUTF8 = [NSUserName() UTF8String]; uint32_t userNameLength = (uint32_t)strlen(userNameUTF8); uint32_t serviceNameLength = (uint32_t)strlen([theKey UTF8String]); uint32_t pwLength = 0; void* pwBuffer = nil; SecKeychainItemRef itemRef = nil; OSStatus status1 = SecKeychainFindGenericPassword (NULL, serviceNameLength, serviceNameUTF8, userNameLength, userNameUTF8, &pwLength, &pwBuffer, &itemRef); if (status1 == noErr) { NSData* pwData = [NSData dataWithBytes:pwBuffer length:pwLength]; SecKeychainItemFreeContent (NULL, //No attribute data to release pwBuffer //Release data buffer allocated by SecKeychainFindGenericPassword ); return [NSString stringWithCString:[pwData bytes] encoding:NSUTF8StringEncoding]; } //status1 is always -25293 return nil; } 
+4
source share
1 answer

OK, I just found out that this is a bug in Mac OS 10.8.0. Applications signed with the developer identifier cannot access the data from the remote control. I hope this will be fixed in 10.8.1 ...

The workaround is not to sign the application with your developer id. (I also read that applications created under Lion are not affected by this error, but I have not been able to verify this yet)

+4
source

All Articles