Patrick
Patrick

Reputation: 3111

Secure way to unlock full version via In-App Purchase

I'm planning to use In-App Purchases to unlock some features in my app. What is the most secure way to do this?

Originally I planned to set a Bool in the NSUserDefaults:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isPro"];

But I'm not really sure whether there is a possibility to set this value via a "hack" (as NSUserDefaults are managed by iOS and not directly by the app) so that the user doesn't have to perform the In-App Purchase in order to get the full version.

What's the best practice to handle this?

Upvotes: 6

Views: 2404

Answers (4)

Anton  Malmygin
Anton Malmygin

Reputation: 3496

I came across some problem and found two common ways for secure storing of In-App Purchases:

1) Using secure version of NSUserDefaults:

a) "Secure NSUserDefaults". This version of NSUserDefaults generate hash for any saved secret item and provide to you validation of this hash for item after. So, you can easily deal this situation of "hack" defaults .plist by user.

Check here: https://github.com/matthiasplappert/Secure-NSUserDefaults

b) "SecureNSUserDefaults". NSUserDefaults with AES encryption. My advise here not just storing secure bool values for purchases, but rather some obfuscated string for indication of payment done or not.

Check here: https://github.com/nielsmouthaan/SecureNSUserDefaults

2) Using KeyChain

a) "RSSecrets" Simple class to store key-value items in KeyChain. See also discussion here: Storing In App Purchase receipts in the application Keychain

And check project: https://github.com/jeffargast/RSSecrets

b) "STKeychain" Mostly this class used for storing login/pass in KeyChain, but in project of MKStroreKit (popular In-App Purchases StoreKit for iOS devices) they actually use this class for storing In-App Purchases.

Check here: https://github.com/ldandersen/STUtils/blob/master/Security/STKeychain.h

P.S. I am not yet used any of this classes in my project, but think to use "RSSecrets"

Upvotes: 0

spring
spring

Reputation: 18507

Security through Obfuscation is the simplest way to go here (e.g. don't name your var "isPro" and perhaps don't have it's value be a simple BOOL but instead have it be some "magic" integer. Not foolproof but another speed bump to cracking.

As an alternative to using NSUserDefaults you could save a file to the app filesystem and then check it's contents at app launch.

Not sure it is worth the time and trouble though.

Upvotes: 3

Jim
Jim

Reputation: 73966

Yes, it's relatively easy to modify application preferences. But does it really matter? I would wager that anybody who is willing to crack open their iPhone filesystem and modify config files to save a quid or two is not the type of person who would be inclined to spend the money if they were unable to do so.

Upvotes: 9

Edwin Vermeer
Edwin Vermeer

Reputation: 13127

You could save it in the keychain, but then on a jailbroken device it's also easy to read and change that. So you should encrypt the data. Make sure that the encryption password can not be found easily in your app by scanning the binary.

Upvotes: 1

Related Questions