views:

305

answers:

1

Hi

I am looking for a stable (and Apple compliant) registration and authentication design pattern between an iphone device and a server. Ideally the registration and authentication would not involve the user and be a background process.

So far I've found 3 primitives for doing components of this:

  1. UDID
  2. UUID
  3. SBFormattedPhoneNumber

UDID method

 [[UIDevice currentDevice] uniqueIdentifier]

    where @property (nonatomic, readonly, retain) NSString *uniqueIdentifier

uniqueIdentifier is a string unique to each device based on various hardware details. (read-only)

A unique device identifier is a hash value composed from various hardware identifiers such as the device’s serial number. It is guaranteed to be unique for every device but cannot publically be tied to a user account. You can use it, for example, to store high scores for a game in a central server or to control access to registered products. The unique device identifier is sometimes referred to by its abbreviation UDID. We can get UDID from iTunes manually for checking

Not sure what "cannot publically be tied to a user account" means.

UUID method

NSString *uuid = nil;
CFUUID theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID) {
  uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID);
  CFRelease(theUUID);
}

CFUUIDCreate creates a Universally Unique Identifier (UUID) object. UUID object is different every time CFUUIDCreate is invoked. Therefore we need to generate it on first launch and then save it to your preferences using NSUserDefaults. The downside to this is that if the app is deleted and reinstalled or if the device is restored from backup, you'll lose the saved UUID and things won't be recognized as from the same device.

SBFormattedPhoneNumber

NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@”SBFormattedPhoneNumber”];
NSLog(@”Phone Number: %@”, num);

The number returned by this code snippit is the number that is set up in iTunes for the device. If you didn’t enter the iPhone’s in iTunes at device activation, or perhaps [as in my case] if the default value wasn’t the iPhone’s number and you clicked OK anyway, such that iTunes doesn’t list the phone number when your iPhone is plugged in, this code will return a null string.

"For security reasons, iPhone OS restricts an application (including its preferences and data) to a unique location in the file system. This restriction is part of the security feature known as the application's "sandbox." The sandbox is a set of fine-grained controls limiting an application's access to files, preferences, network resources, hardware, and so on."

The device's phone number is not available within your application's container. You will need to revise your application to read only within your directory container and resubmit your binary to iTunes Connect in order for your application to be reconsidered for the App Store.

thank you in advance for your help.

peyman

+2  A: 

Apple recommends using the UDID method as you found yourself. It is unique and stable for each device. Besides it's very easy to handle. Cannot be publically be tied to a user account means that you are not able to get the users iTunes account based on it which adds to the security of using this method.

The UUID will change every time you generate it. You will therefore have to store it yourself between runs of the application.

Phone number is not very stable as it can be changed by the user. Additionally it will be considered breach of the users private data to retrieve, store and transfer it.

So I would strongly recommend going for the UDID method.

Claus Broch
I agree with Claus, the [UIDevice uniqueIdentifier] is the best way to identify an iPhone. But the identifier is not secret soalso consider compiling a "secret" (some x random characters) into the app, then build a checksum with all the values and the secret when authenticating and send it as a parameter. This approach will make it harder for someone to do a "man-in-the-middle" attack and pose as an authenticated iPhone.
RickiG
thank you Claus and RickiG. Much appreciated for your time and help. this site is amazing.
Peyman
"Cannot be publicly be tied to a user account..." I can read this as a technical limitation ("application has no access to this information"--I think this is how Claus explains it) or a legal restriction ("we at Apple don't want you to associate them"). I wonder if Claus or Ricki can comment on this.
iter
@iter: Well, I'm not a legal expert by trade, but my guess is that the statement actually contains bits of both. It wouldn't surprise me if there were a way to tie this information together on a jail broken device, so Apple says something around the lines of "We (Apple) have not provided a public API for this, so don't try to do it by other means." It could also mean that you are not allowed to publicly display the UDID along with some sort of account information. Anyway, I'm sure that any breach of this could possible lead to some sort of legal action by Apple, eg. App Store rejection.
Claus Broch
Thank you Claus. In my application, I want to store some user information on my server (mostly to backup user files from the device), but I don't want to require users to register on my site (if they do, that's extra cool, but they don't have to). I don't care about users' iTunes accounts. Like the OP, I find the UDID a useful way to identify a device to my server. I want to make sure my design complies with relevant policy.
iter