
Learn how to issue trial licenses from the platform and SDK, how a trial license works, and how trial licenses can be incorporated into your project.
Some computers will not have an active internet connection or are behind a firewall preventing online activation. For this reason, we developed a mechanism to allow the activation and deactivation of licenses in an offline environment. In this tutorial, we will learn the basics of Offline Licensing using the LicenseSpring C++ SDK.
Follow the linked video for an overview on LicenseSpring’s Offline License Activation.
This guide will walk you through implementing offline licenses within the LicenseSpring C++ SDK. By the end of this tutorial, you should understand how to activate, deactivate, and check licenses without requiring an active internet connection. We will also look into total activations and max activations, the license types supported, and the differences between offline and online licensing. We will create a ChatBot that successfully activates, deactivates, and uses the local license file for local license checks, all without requiring an active internet connection.
For more information, look into our Offline Licensing Documentation.
Note: Since this article is a continuation of the Getting Started Tutorial, it is assumed that readers meet the prerequisites previously stated. Readers should also have a thorough understanding of license activation, deactivation and checking.
The first step to activating a license offline is to create an offline activation request file. This can be done by using the following function:
1
auto filePath = licenseManager->createOfflineActivationFile(licenseId);
This function creates an offline activation request file with the path and name specified in the parameter ‘path’, for the key-based/user-based license defined in LicenseID. If ‘path’ is left empty, the default path that the offline activation request file will be created in is the desktop, and the default name will be ls_activation.req: C:\Users\%USERNAME%\Desktop\ls_activation.req.
Once you have your offline activation request file, you will need to upload it to the LicenseSpring offline portal. Note: this will require a computer with online access.
After uploading, you will be given an offline activation response file, with the name ls_activation.lic.
Finally, to activate the license offline on a device, you can use activateLicenseOffline(path) as shown below:
1
license = licenseManager->activateLicenseOffline(path);
You will have to specify the name and path of the offline activation response file in the parameter ‘path’. If ‘path’ is left empty, the default path and name it will search will be the desktop with the name ls_activation.lic: C:\Users\%USERNAME%\Desktop\ls_activation.lic.
Once a license has been activated, it can also be deactivated using a similar process. Within the Chatbot, the function that creates this offline deactivation request file is:
1
auto filePath = license->deactivateOffline();
You can also provide an optional parameter into the deactivateOffline() to provide an alternative path for the deactivation request file to be created and stored. Leaving the parameter empty uses the default file path, which saves the file to the desktop. After we create the deactivation file, to eliminate any local license that we have, we run:
1
licenseManager->clearLocalStorage();
Now that you have created your deactivation request file, you need to return to the Offline Licensing Portal to upload. After uploading the deactivation request file, this updates the LicenseSpring platform to show that the license is no longer active and unbound from the device.
Offline license refresh assists users in refreshing their activated offline license, typically used when aspects of the license were altered on the backend. For example, if you wish to add a new feature but do not want to reactivate the license. To refresh a license offline, find the license on the LicenseSpring platform and go to the Devices tab.
We incorporated the ability to update licenses using this feature in our Chabot. The line of code that does the updating is:
1
if (license->updateOffline(path));
The path within the parameter is the path to the license_refresh.lic file which we downloaded from the page as shown above.
Since the portal requires a network connection, there are specific ways for offline license activation to work. One way would be to:
A similar process can be done for deactivation, but without having to transfer back the offline activation response file.
If there are cases where you will need both online and offline deactivation, activation, and checks, you can use the code isOnline() to check when you should be doing offline deactivations/activations/checks, and when you should be doing online deactivations/activations/checks.
1
if( licenseManager->isOnline() )
The offline license activation process will fail for any of the following reasons:
Offline activation is supported for Perpetual, Consumption, and Time-Based licenses. Offline activation does not work for Subscription-Based licenses.
Since we perform the operations offline, we do not have direct access to the backend. Due to this roadblock, offline licensing uses a more gradual approach. Rather than activating the license in one line using activateLicense(), we use createOfflineActivationFile() and upload the file to the offline portal to receive the offline response file. This response file is put back into the program to activate the license.
Checking licenses is similar since we do not have access to check() when running our program offline. As a result, we only inspect the local license when checking offline, instead of the backend and locally. Best practices include doing localCheck() consistently to confirm your license is still valid.
Note: to use localCheck(), a valid pointer to the license is required.
Guard files prevent users from using the same license request file and are automatically enabled within extendedOptions. Guard files can be disabled in the extendedOptions constructor or by running enableGuardFile( false ). When this is enabled, a guard file is created in the folder where the license will be created and where we store the SDK logs. These are saved in a hidden file called guard file, and if someone removes this file or tries to edit this file the license activation will fail. This file is created as soon as you create the request file for offline activation, and this guard file is valid and should exist when a user is submitting a response file.
Manually editing a computer’s clock time into the past and running a local license check is prevented in LicenseSpring. If the platform sees that the computer's local time is before the last time the license was checked, it can confirm that the clock has been tampered with. Also, the checker examines only UTC time, so time zones do not impact the anti-clock tampering mechanism.
GetCurrentLicense() not returning null even though the local license file has been deleted from the device:
When the local license file is deleted using something like license->deactivate( true ), the file will still remain in memory, until it is cleaned out, or the program ends. GetCurrentLicense() will always check memory first to find the local license, and if it finds it, it will not go into your storage to look for it, thus it will return the pointer to the location in memory where local license still exists. There are multiple ways to work around this issue:
Note: LicenseFileException listed in docs but doesn’t exist
updateOffline() and activateLicenseOffline() throwing exceptions:
External changes on the LicenseSpring platform that adjust the state of the device, i.e. resetting, disabling, will not be reflected in the program, even with checks.