Click here to Skip to main content
15,861,125 members
Articles / Programming Languages / Visual Basic

Creating Secure Trial Versions for .NET Applications - A Tutorial

Rate me:
Please Sign up or sign in to vote.
4.88/5 (65 votes)
16 Oct 2012CPOL7 min read 174.8K   22K   243   33
Implement trial licensing model for your .NET applications with minimal costs

 Image 1

Introduction  

This article actually represents a second part of my previous article Software Copy Protection for .NET Applications - A Tutorial. In that article I have presented several methods for achieving satisfactory software copy protection for .NET applications. In this article I will show you how to create trial versions of your products in a secure manner. Note that completely eliminating software piracy is not generally possible given the today's OS and hardware infrastructure, but this doesn't mean you cannot control it with careful consideration. 

Attached to this articles are C# and VB.NET samples (derived from my first article's samples but significantly different) showing how to implement trial versions of your products. The article does not contain source code (it's in the samples), because I would rather concentrate of explaining how to do it, rather than duplicating source code that can already be found in the samples.  

Background  

One of the most successful models for selling software is the trial software model.  In this model, potential customers are allowed to download and use the software free of charge for a limited period of time, after which the software stops working unless a license is purchased. Unfortunately, this model is also one which can cause loss of revenue because it increases the risk of software piracy. 

The Trial Model Flow 

After the user downloads your trial software, you must do the following:

  • Determine the trial expiration date 
  • Store the trial expiration date in such a way that the user cannot alter it 
  • Prevent additional trial installations after the trial expires  
  • Make sure the user does not manipulate the system clock such that your trial software thinks that the trial period is not yet over

As you can see, this is easier said than actually done. Some pressing questions appear: where do you store the expiration data such that the user cannot find and alter it ? How can you make sure the user didn't alter the system clock ? The answers below... 

The Big Issue #1: Where to Store the Expiration Data ?  

The answer to this question is that if you have to hide data from the user, your licensing model is already compromised. A good licensing model should never be based on hiding or obscuring data from the user.  

The solution that I have found to this matter is to use an online licensing service in conjunction with digital signatures based on public key cryptography.  I chose to use SoftActivate Licensing SDK (from www.softactivate.com) because it is quite cheap, and it includes an ASP.NET licensing service which can issue short, human readable license keys (digitally signed using elliptic curve cryptography) and supports product activation which strongly resembles the trial licensing model. In addition to this, it can generate unique hardware id strings, which are very important (see below).  

Of course, you can build your own service for this purpose, for example using RSA public/private key pairs and digital signatures. The algorithm is as follows:

  • After downloading and installing the product, the customer must press a "Start Trial" button. 
  • Upon clicking this button, the product connects to an online licensing service (preferably via HTTPS in order to ensure that the server is the intended one by checking its SSL certificate) and sends a "hardware id" string unique to the customer's computer 
  • The server checks against a database if the hardware id has already been used for trial purposes. If the hardware id has not been used before, the server sends back a digitally signed message (we name it "trial license" containing the trial expiration date (for security reasons this MUST be absolute, and not relative like a number of days). The trial license is signed using a private key known only by the server. The computer's hardware id should also be included in the license data. 
  • After receiving the signed trial license from the server, the product saves it in a usual settings location and validates the digital signature at every startup and (optionally) at random times during the program execution, using the corresponding public key which is embedded into the product. Please note that the digitally signed message doesn't need to be hidden from the user; the user cannot alter it in any way because it is digitally signed and the signing (private) key is only known by the server. Also, if the trial license is deleted the software would not run, and if a trial version is requested again from the server, the server would not issue another trial license because the hardware id has already been used once for issuing a trial license.

This approach solves the "where to store the expiration data" problem. Basically, you can store this data anywhere you want. You don't need to hide anything, because this data cannot be altered without the product detecting it.   

The Concept of  "Trial License Keys"

 Almost every software product uses license keys to "unlock" the software. A good idea is to embed a certain license key into the product, which is marked as a "trial license key". If the product detects the trial license key at startup, it behaves like a trial version, and if it detects a regular license key, it behaves like a registered product.

The concept of trial license keys is important when using online software activation with your products (see my previous article for details). When the product sends the license key to the activation server, the servers issues a license with a shorter expiration date if it receives a trial license key, and a license with a longer (or unlimited) expiration date if it receives a regular (purchased) product key. The samples in this article use this concept: they have an embedded "trial key" which is sent to the licensing service. The licensing service searches for this license key into its database, and issues a digitally signed expiration date according to what is specified for that particular trial key (30 days from the time of receiving the request). You can modify this value in the licensing service database.

The Big Issue #2: How to detect system  clock manipulation ?  

System clock manipulation detection involves searching a computer for evidence that the system clock was turned back with the purpose of prolonging a software license past its expiration period.

To my knowledge there are no 100% bullet-proof methods of doing this, but usually this involves:

  • Searching certain system files for file times (usually the "last modification time") that are in the future 
  • Searching the event logs for evidence that some events have occurred in the future 
  • Searching popular browser caches / cookies  for evidence of file times occurring in the future 
  • Combining the evidence and drawing a conclusion

The included samples contain some simple clock manipulation detection routines searching the event logs for event dates that occur in the future.   See the ClockManipulationDetector class in the sample projects. 

Using the code   

The samples are created with Visual Studio 2010. Also, SQL Express 2005 or higher should be present on the development machine for the licensing service database. Also make sure that SoftActivate Licensing SDK (2.0 or higher) is installed on the development machine.  Before compiling, copy the LicensingService subfolder under the Bin folder from the SoftActivate Licensing SDK installation folder, inside the Tools folder created by unzipping the sample. 

Running the samples   

First and foremost, you must start the licensing service by running the RunLicensingService.bat file from the Tools folder. Make sure that the paths in the .bat (to Visual Studio and to the sample folder) are set correctly ! Go to the \bin\Release folder and run the SampleAppCS.exe or SampleAppVB file. Click the "Start 30-day Trial" button to start the trial. The application will then connect to the licensing service and request a trial license. Please note that if you try to click it again, it will not work since a trial license has already been issued for your computer. In order to try again, you must connect to the licensing service database (found in the Tools\LicensingService\App_Data folder) and delete the record from the Activations table. 

Points of Interest  

You should be aware that your trial product is not secure if you do not employ the typical software copy protection techniques explained in the first article of this series here . This is because if your application binaries can be altered, the trial checking mechanisms can be bypassed altogether.

History 

October 9, 2012 - Initial publication.

October 16, 2012 - Small bug fixes to the samples.  

 

 

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow to handle deactivation? Pin
Denise Adams2-Sep-16 9:06
Denise Adams2-Sep-16 9:06 
GeneralMy vote of 5 Pin
Santhakumar M27-Nov-15 0:41
professionalSanthakumar M27-Nov-15 0:41 
Questionunsupported key version of Licensing.Net Pin
dinesh9122-Sep-15 22:49
dinesh9122-Sep-15 22:49 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun13-Sep-15 18:30
Humayun Kabir Mamun13-Sep-15 18:30 
GeneralMy vote of 2 Pin
Mikloo28-Nov-14 16:18
Mikloo28-Nov-14 16:18 
GeneralSource Pin
Roberto Pasquali26-Nov-14 0:42
Roberto Pasquali26-Nov-14 0:42 
GeneralMy vote of 2 Pin
seyyed hamed monem4-Jul-14 4:51
professionalseyyed hamed monem4-Jul-14 4:51 
Questionresponce Pin
ketan italiya28-Oct-13 20:06
ketan italiya28-Oct-13 20:06 
QuestionPerfect 5! Pin
10kbps3-Mar-13 16:08
10kbps3-Mar-13 16:08 
AnswerRe: Perfect 5! Pin
Akinmade Bond2-May-13 4:45
professionalAkinmade Bond2-May-13 4:45 
QuestionHow would it influence the users? Pin
Ivan Ičin28-Oct-12 5:02
Ivan Ičin28-Oct-12 5:02 
AnswerRe: How would it influence the users? Pin
Ansel Reynard28-Oct-12 22:45
Ansel Reynard28-Oct-12 22:45 
GeneralMy vote of 5 Pin
DevilVikas25-Oct-12 3:31
DevilVikas25-Oct-12 3:31 
GeneralMy vote of 2 Pin
SalarSoft20-Oct-12 22:56
SalarSoft20-Oct-12 22:56 
GeneralRe: My vote of 2 Pin
Ansel Reynard21-Oct-12 3:36
Ansel Reynard21-Oct-12 3:36 
GeneralRe: My vote of 2 Pin
SalarSoft21-Oct-12 8:10
SalarSoft21-Oct-12 8:10 
GeneralRe: My vote of 2 Pin
Ansel Reynard21-Oct-12 9:29
Ansel Reynard21-Oct-12 9:29 
QuestionBookmarked ! Pin
Gun Gun Febrianza16-Oct-12 16:04
Gun Gun Febrianza16-Oct-12 16:04 
GeneralMy vote of 5 Pin
Gun Gun Febrianza16-Oct-12 16:03
Gun Gun Febrianza16-Oct-12 16:03 
GeneralMy vote of 5 Pin
SachinDakle16-Oct-12 5:01
SachinDakle16-Oct-12 5:01 
GeneralRe: My vote of 5 Pin
Gun Gun Febrianza16-Oct-12 16:03
Gun Gun Febrianza16-Oct-12 16:03 
SuggestionLicense expiration check Pin
Markus6410-Oct-12 2:38
Markus6410-Oct-12 2:38 
GeneralRe: License expiration check Pin
Ansel Reynard10-Oct-12 6:55
Ansel Reynard10-Oct-12 6:55 
GeneralRe: License expiration check Pin
Markus6410-Oct-12 8:02
Markus6410-Oct-12 8:02 
GeneralRe: License expiration check Pin
Daniel Rozsar16-Oct-12 8:54
professionalDaniel Rozsar16-Oct-12 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.