Problem Using Enterprise and Using UUID

As you know, Apple has recently deprecated the use of UDIDs. Therefore my decision was

  • Create CFUUID
  • Store it in the keychain
  • Re-enter the keychain element after this.

This works well. But for some reason, we recently saw that with the installation of the enterprise assembly we get a different UUID (which was supposed to be stored on the key fobs using our unique access key).

Has anyone encountered such a situation? Here is the code to create a UUID and store it on a 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
+5
source share
2 answers

Okie

After battling the problem during the day, I discovered what caused it.

  • Keychain attached to certificate
  • An enterprise assembly is created with a different certificate.
  • , , , , .
  • , . accessGroup init KeyChainWrapper.

!

+3

MAC Addres instread UUID

- (NSString *) macaddress
{
    int                 mib[6];
    size_t              len;
    char                *buf;
    unsigned char       *ptr;
    struct if_msghdr    *ifm;
    struct sockaddr_dl  *sdl;

    mib[0] = CTL_NET;
    mib[1] = AF_ROUTE;
    mib[2] = 0;
    mib[3] = AF_LINK;
    mib[4] = NET_RT_IFLIST;

    if ((mib[5] = if_nametoindex("en0")) == 0) {
        printf("Error: if_nametoindex error\n");
        return NULL;
    }

    if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 1\n");
        return NULL;
    }

    if ((buf = malloc(len)) == NULL) {
        printf("Could not allocate memory. error!\n");
        return NULL;
    }

    if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 2");
        return NULL;
    }

    ifm = (struct if_msghdr *)buf;
    sdl = (struct sockaddr_dl *)(ifm + 1);
    ptr = (unsigned char *)LLADDR(sdl);
    NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", 
                           *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
    free(buf);

    return outstring;
}
-3

All Articles