I'm using the ARCified KeychainItemWrapper
and having trouble migrating the data in one keychain item to another item. Basically I'm trying to copy the contents from an app specific item to a shared item. For brevity I've only put in the user name since it fails there.
KeychainItemWrapper *legacyKeychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"mainLogin" accessGroup:@"C35BXHSRSA.com.foo.bar"];
NSString *legacyUser = [legacyKeychainItem objectForKey:(__bridge id)kSecAttrAccount];
self.migratedKeychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"security" accessGroup:@"C35BXHSRSA.com.foo.security"];
// dies here
[self.migratedKeychainItem setObject:legacyUser forKey:(__bridge id)kSecAttrAccount];
It dies in the KeychainItemWrapper
method writeToKeychain
throwing NSAssert( result == noErr, @"Couldn't update the Keychain Item." );
Looking up the error in the Keychain Services Reference tells me
errSecDuplicateItem –25299 The item already exists.
I can confirm this issue by hard coding/altering the string and the code works perfectly, but I'm trying to migrate data... so identical is important. The question is, why is this throwing an error when it's 2 different keychain items and how the heck do I get it to work as desired?