Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with Enterprise build and UUID usage

As you know Apple recently deprecated the usage of UDID. So my solution to this was

  1. Generate CFUUID
  2. Save it to keychain
  3. Re-access the keychain item there after.

This has been working good. But, for some reason we recently saw that with the installation of an enterprise build we are getting a different UUID(Which was supposed to be stored on keychain with our unique access key).

Did any one come across such situation? Here is the code to create the UUID and store it onto keychain..

+ (NSString *)registerUUIDWithKeyChain
{
CFUUIDRef udid = CFUUIDCreate(NULL);
NSString *uuidString = (NSString *) CFUUIDCreateString(NULL, udid);

KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"UniqueApp" accessGroup:nil];

NSString *userName = @"UniqueAppName";
NSString *password = uuidString;

[keychainItem setObject:userName forKey:(id)kSecAttrAccount];
[keychainItem setObject:password forKey:(id)kSecValueData];

[keychainItem release]; 

return uuidString;

}

+ (NSString *)userUUID
{
    KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"UniqueApp" accessGroup:nil];

//Accesing the v_data was the only way. For some reason there is a runtime issue if we try to access it though "kSecValueData"
NSString *uuid = [keychainItem.keychainItemData objectForKey:@"v_Data"];

//Check if the app is installed for the first time on the device. If YES register the UUID in to the keychain.
//Also check if it is a reinstall by accessing the previous keyChainItem with our Identifier.
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"firstRun"] intValue] == 0 && !(uuid.length > 0)) 
{
    uuid = [UIDevice_Additions registerUUIDWithKeyChain];

    NSLog(@"\n First Time Registered UUID is %@", uuid);

    //after stuff done
    [[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInt:1] forKey:@"firstRun"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    [keychainItem release]; 
    return uuid;
}

[keychainItem release]; 
return uuid;
}

@end
like image 754
Mobilewits Avatar asked Nov 25 '22 00:11

Mobilewits


1 Answers

Okie,

After battling with the issue for a day, I found what was triggering this.

  • Keychain's are certificate dependent
  • An enterprise build is created with a different certificate
  • Hence, when the code tries to access your key from an enterprise build you will not find it and hence the code generates will generate a new one.
  • Solution would be to create your Keychain so that it is globally accessible. You can change the accessGroup variable in the KeyChainWrapper init method.

Good Luck!

like image 78
Mobilewits Avatar answered Dec 24 '22 12:12

Mobilewits