My name is Kenneth and I write cool Mac and iPhone software. This is my personal weblog where I post about stuff I find interesting. I usually write about Mac development, the business of shareware and the Mac community in general.read more →
One challenge that most developers face when nearing release of their first application is how to implement registration and piracy protection. This three-part article will describe three common types of registration schemes: Serial Numbers, Asymmetrical Cryptographic Keys and Product Activation.
Part One: Serial Numbers
Serial numbers are the simplest, most practical option. However, they are also the least secure. It consists of taking at least one of the customers’ details, and creating a serial number from it. The serial number is usually tied to either the customer’s name, or his email address, preferably both.
For example, let’s say the customer’s name “First Last” and his email address is “email@example.com”. The first step would be to strip his name and email address of any non-alphabetical characters, concatenate it and convert it to uppercase. (I put the email address first, because it’s less recognizable) Here’s what we get:
Now map this string onto a XXXX-XXXX-XXXX-XXXX-XXXX key. If there are any character leftovers, just discard them. If there aren’t enough characters to fill all the Xs in, leave them as something constant. (they don’t have to be all the same, but they have to be the same for each position all the time. You could for example say you’re mapping it onto an QRST-ABCD-IJLK-EFGH-MNOP key, and leave unfilled spaces as is)
Then, we’d apply ROT13 on it.
Lastly, we could replace any swearwords in the key by some random other constant text, just in case.
Another example, using a similar method: Using the same customer, here’s what we’d do. Take his details, concatenate and salt them:
First Last+random firstname.lastname@example.org
Then, MD5 the result and add another salt:
Next, SHA1 the result:
And finally, uppercase it and map it onto a XXXX-XXXX-XXXX-XXXX-XXXX serial:
When you have decided on a serial scheme, implementing it is easy. Upon registration, you take the buyer’s name and email address, and generate a serial from it. He then has to input this serial into you app, along with his name and email address. All you have to do in you app is take the name and email address he gave you, generate a serial from it, and check it against the serial he gave you.
Making it more secure
For security reasons, one important step to take is obfuscating how you create those serials, in case anyone tries to create a keygen for you app. The easiest way is adding dummy maths code in the middle of the code where you work out your serial. It will not affect your serial, but it will show up in the assembly code in case anyone tries to gdb your app (more on that in another blog post I have planned).
Another quick thing you could do is shuffle the characters a bit on a set pattern to make them less obvious.
For example you could use this pattern:
Sometimes, your serials cannot be tied to any of the customer’s data, for example for retail sales. In that case, you’d need a different serial scheme. You need to choose certain characteristics / rules that make a serial valid. It could be as simple as checking that the 19th character is a W.
Here’s a set of example rules you could use:
- The ASCII value of the first character of all five blocks of four characters have to add up to 100.
- The last character of all five blocks of four characters have to be vowels.
- The first character of either block 3 or 4 has to be E.
- The ASCII value to the third character of every block have to be even numbers.
In your apps, just check the serial against the rules, and if it’s correct, you can assume it is a correct serial.
For your generator, you can have a pre-made list of valid serials, and assign them to a customer or print them on a retail copy when needed. The problem with this method is that you can eventually run out of valid serials. In which case you would have to generate a new batch of serials, or reassign already used serials to a second customer.
Another (better) way of doing stand-alone serial numbers is splitting the serial number in two, and basing the second part on the first part. [thanks to tomasf from the #macsb IRC channel for this method]
For example, in a serial number ABCD-EFGH-D07A-A959-F269, separate the first eight characters from the rest of the serial:
Map it onto XXXX-XXXX-XXXX:
And check it against the second part of the serial. In this example, the serial is correct.
Part Two: Asymmetrical Cryptographic Keys
The last parts will be coming soon.
This entry was posted on Thursday, April 3rd, 2008 at 11:26 pm and is filed under Articles, Business, English, Hacking, Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Add your thoughts!