objective-ckeychainidentifierkeychainitemwrapper

What is the proper identifier to use when adding a keychain item using KeyChainItemWrapper?


I don't really understand what the identifier is or how it is used.

Is it arbitrary? Is it my app name in reverse? Below I use "test" but should it be: "com.mydomain.myApp.test"? Or my app bundle identifier: "com.Soundpaper.soundpaper.fakeID123"? Or what?

Thank you.

@property (nonatomic, strong) KeychainItemWrapper *myChain;
    
     . . .

if (myChain == nil)
{
    // first question: what identifier should I use?        
    myChain = [[KeychainItemWrapper alloc] initWithIdentifier:@"test" accessGroup:nil];
}

Solution

  • The KeychainItemWrapper is a wrapper class to hide all the CFRef conversion stuff from the "typical" developer. Being so, all the "rules" of the Keychain services in the Security framework hold.

    Therefore, whenever you access a keychain item, the framework will automatically "add" the bundle id of your app to that item, to ensure that you can read only your own items, see e.g. SecItemAdd discussion.

    Hence, the identifier is completely arbitrary and may only raise conflicts within your own app, not with others.

    Remark: if you specify an accessGroup, you can share keys between apps, see Sharing Access to Keychain Items Among a Collection of Apps