Shelf Life Check
A Shelf Life Check is a type of Check that detects if an application is being run after a certain date. This gives the application a shelf life - a limited period of time for which it can be run.
Shelf Life Checks are particularly useful for beta or evaluation software. If the user attempts to run the application beyond the expiration date, a Shelf Life Check can detect this and react by notifying the application and causing the application to exit. In other words, a Shelf Life Check detects and reacts to unauthorized use of your application based on the current date.
Configuring Shelf Life Checks
To have Dotfuscator inject Shelf Life Checks into your application, you must first obtain a Shelf Life Activation Key from PreEmptive Solutions.
Once you have an Activation Key, enable Checks.
Then, configure the Checks via the user interface or by annotating your source code with ShelfLifeCheckAttribute
.
Both of these methods allow you to specify various properties that determine how the Check operates; for a full listing, see the ShelfLifeCheckAttribute
section of the Check Attributes page.
Activation Key
A Shelf Life Activation Key is a data file that is required to inject Shelf Life Checks. To obtain an Activation Key, contact PreEmptive Solutions.
Once issued, you must specify the path to the Activation Key in each Shelf Life Check's ActivationKeyFile property. We recommend keeping a copy of the Activation Key on each build machine.
The Activation Key is only needed when Dotfuscator processes the application. The application does not need to access the Activation Key at runtime, so it should not be distributed outside of the development organization.
Tokens
A Shelf Life Token is a file containing information about an application's shelf life, such as the expiration date. Rather than embedding the expiration information directly into the application, Dotfuscator generates a Token containing this information. At runtime, the Shelf Life Check uses the Token to determine if the application has expired.
When Dotfuscator Community injects a Shelf Life Check, it automatically generates a Token based on the Check's ExpirationDate property, then embeds the Token in the application for the Check to use at runtime.
Dotfuscator Professional also allows you to sign Tokens with public / private key pairs, to ensure Tokens used at runtime are authentic.
Expiration Date
Each Shelf Life Token has an associated expiration date. When a Shelf Life Check using the Token runs, it compares the expiration date to the current time (using an algorithm more complex than just checking the system time). If the expiration date is in the past, the Check determines the application to be expired. What happens as a result of the application being expired depends on the application notification properties.
The expiration date for a Shelf Life Check is specified by the Check's ExpirationDate property.
Dates for a Shelf Life Tokens are configured as strings, in one of two formats:
An absolute date, specified in the form
YYYY-MM-DD
.A date relative to the date Dotfuscator generated the Token, specified as an integer indicating the number of days.
For instance, if Dotfuscator generates the Token on August 1, 2017, and the application should expire on August 31, 2017, the expiration date can be written as either 2017-08-31
or 30
.
Application Notification
Having a Shelf Life Check notify the application code is a feature exclusive to Dotfuscator Professional.
Exit Behavior
Shelf Life Checks do not support Check Actions. A configuration equivalent to the use of the Exit Action can be done by setting the ExpirationNotificationSinkElement property of the Check to DefaultAction.
When a Shelf Life Check with this configuration detects expired application usage, it will cause the application to exit immediately with exit code 0.
Unsupported Application Types
Dotfuscator can inject Shelf Life Checks into all .NET assemblies except for the following:
- Managed C++ assemblies containing native and managed code
- Multi-module assemblies
- .NET Core assemblies
- .NET 5+ assemblies
- UWP assemblies
- Xamarin assemblies
Testing
To test how the Shelf Life Checks injected into your application react to expired application usage, the simplest method is to temporarily configure the Checks with the expiration dates in the past. Be sure to exercise all locations of your Shelf Life Checks. Once you have tested that the application acts as it should when it is expired, you will need to change the dates back to their intended values before building for distribution.