SDKs
...
Tutorials
Licensing Scenarios
Offline Licensing
30min
in certain scenarios, some computers may lack an active internet connection or be behind a restrictive firewall, hindering online activation to address this, we have developed a mechanism that enables the activation and deactivation of licenses in an offline environment prerequisites completed the getting started docid\ lsfy9tq3vfq4roow9shkd tutorial, specifically initialized licensemanager (or licensehandler ) with your configuration using the appropriate settings created a licenseid using either licenseid fromkey or licenseid fromuser function, depending on the activation method you prefer performing offline license activation using the licensespring sdks is a straightforward process follow the steps below to activate and deactivate licenses license activation process generate a request file by calling the createofflineactivationfile function of licensemanager provide the licenseid you created earlier and specify the path where you want to save the request file the function will return the path to the created file open the offline activation page and upload the request file you generated in the previous step once uploaded, download the offline activation file from this page activate the license by calling the activatelicenseoffline function of licensemanager and passing the path to the offline activation file received from the website the function will return a license object upon successful activation, or null if the activation process fails license deactivation process call the deactivateoffline function of the license object, and optionally provide the path where you want to save the deactivation request file the function will return the path to the created file call the clearlocalstorage function of licensemanager to delete the files created by the sdk to store license data open the offline activation page and upload the deactivation request file you generated in the previous step once uploaded, you will receive a message confirming that the license has been deactivated let's get started! offline activation process request file creation to initiate offline license activation, the first step involves creating an offline activation request file you can accomplish this by utilizing the following function auto filepath = licensemanager >createofflineactivationfile( licenseid );string filepath = licensemanager getofflineactivationfile(licenseid);let filelocation = try manager createofflineactivationfile(licensekey "xxxx xxxx xxxx xxxx")req file path = manager create offline activation file(license id,'offline files/test') print(req file path)// go sdk v2 offlineactivationdata, path, err = license handler createofflineactivationfile("path")licenseidentity identity = licenseidentity fromkey("\<license key>"); string filepath = offlineactivationfile(identity, null); the provided function generates an offline activation request file for the specified key based/user based license, identified by licenseid if you include a 'path' parameter, the file will be created with the specified path and name note if 'path' is not provided, the default location for the offline activation request file will be the desktop, and the default name will be "ls activation req" c \users%username%\desktop\ls activation req uploading the request to the offline activation portal once you have generated your offline activation request file, the next step is to upload it to the licensespring offline portal it's essential to note that this process requires a computer with online access licensespring offline portal upon uploading the request file, you will receive an offline activation response file named "ls activation lic " this response file will enable you to proceed with the offline activation process successfully activation with a response file to complete the offline activation process on a device, utilize the function activatelicenseoffline(path) as demonstrated below license = licensemanager >activatelicenseoffline( path );ilicense license = licensemanager activatelicenseoffline(filepath);let responsefile url = let license = try manager activatelicenseoffline(responsefile)license = manager activate license offline('path to lic file/ls activation lic')// go sdk v2 ld, err = license handler activatelicenseoffline(path) in the 'path' parameter, provide the name and path of the offline activation response file if 'path' is left empty, the function will search for the response file named "ls activation lic" on the desktop by default c \users%username%\desktop\ls activation lic by running this, you will have successfully activated the license offline on the device there is a checker for if the license is offline activated also, as shown below bool offlineactivatedtest = license isofflineactivated();bool offlineactivatedtest = license isofflineactivated();license isofflineactivated this boolean checker returns true if offline activated, and false if not how to secure offline activation with extendedoptions enableguardfile 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 the following method, where options is an extendedoptions object options enableguardfile( false );extendedoptions protectofflineactivation = false;from licensespring licensefile config import configuration conf = configuration(product="your product key",api key="your api key", shared key="your shared key",file key=key,file iv=iv, is guard file enabled=true) once enabled, licensespring generates a guard file in the same folder where the license and sdk logs are stored this guard file remains hidden and plays a crucial role in safeguarding the licensing process should anyone attempt to remove or alter this file, the license activation will fail as a protective measure the guard file is automatically created when you generate the request file for offline activation it must remain valid and present when a user submits the response file to ensure a successful activation process the presence of the guard file is pivotal for maintaining the integrity and security of the offline activation procedure to determine the current status of the guard file, you can utilize the following method (where options is an extendedoptions object) bool guardfiletest = options isguardfileenabled();bool guardfiletest = options protectofflineactivation; if a guard file is actively protecting the offline activation process guardfiletest returns true this method also exists within the configuration object, so using the following (where config is a configuration object) will yield an identical result bool guardfiletest = config isguardfileenabled(); offline license update how to get a refresh file offline license refresh allows users to update their activated offline license, which is typically used when certain aspects of the license have been modified on the backend for instance, you might want to add a new feature without requiring license reactivation to perform an offline license refresh, locate the license on the licensespring platform and access the devices tab downloading license refresh file updateoffline method usage the line of code responsible for the update is as follows license >updateoffline( path );bool isupdated = license updateoffline(filepath);let updatefile url = try license updateoffline(with updatefile)license update offline('offline files/license refresh lic',false) in the path parameter, you should provide the path to the license refresh lic file, which you downloaded from the page, as shown above updateoffline also has a secondary optional parameter, resetconsumpion , which is disabled by default if this parameter is set to true, then this update also resets the consumption this method returns true if the license is successfully updated, and false otherwise offline deactivation how to create deactivation request file once a license has been activated, it can also be deactivated through a similar process the function responsible for creating the offline deactivation request file is as follows auto filepath = license >deactivateoffline();string filepath = license deactivateoffline(deactivationrequestfilepath);let request = try license deactivateoffline()license deactivate offline('path where to create req file')// go sdk v2 ld, deactivationreq, path, err = license handler deactivateoffline("path") additionally, you have the option to provide an alternative path as an optional parameter to the deactivateoffline function, where the deactivation request file will be created and stored note if you leave this parameter empty, the default file path will be used, saving the file to the desktop deleting local license file to eliminate any local license data, after creating the deactivation file, we execute the following licensemanager >clearlocalstorage();licensemanager clearlocalstorage();try manager clearlocalstorage()manager clear local storage() by performing these steps, you can efficiently deactivate the license and clear any associated local data code sample loading local license and creating offline activation request file first we load the local license, using getcurrentlicense whilst checking for any local license errors try { license = licensemanager >getcurrentlicense(); } catch ( locallicenseexception ) { //cannot read the local license or the local license file is corrupt } auto filepath = licensemanager >createofflineactivationfile( licenseid ); //request file created at filepath //upload request file to the licensespring portal to get response file try { license = licensemanager currentlicense(); } catch ( locallicenseexception ex ) { //cannot read the local license or the local license file is corrupt } string filepath = licensemanager getofflineactivationfile(licenseid); //request file created at filepath //upload request file to the licensespring portal to get response file manager = licensemanager(conf) try license = manager load license() except exception as ex print(ex) similarly to creating a deactivation request file, we can select a path for this file to be created or use the default path by leaving the path as null in createofflineactivationfile( licenseid, path ) note if the path parameter is null, then the default path that createofflineactivationfile( licenseid ) creates the file at is 'c \users\\%username%\desktop\ls deactivation req' activating offline license using activation response file now that we have submitted the offline activation file to the portal and downloaded the activation response file, we must activate our device locally after checking that our local license is not active, we run activatelicenseoffline( path ) if ( license == nullptr ) { try { license = licensemanager >activatelicenseoffline( path ); } catch ( signaturemismatchexception ) { //signature inside activation file is not valid " << std endl; }if(licensemanager currentlicense() == null) { try { license license = licensemanager activatelicenseoffline(licensefilepath); } catch (signaturemismatchexception ex) { // handle exceptions } }manager = licensemanager(conf) try license = manager activate license offline('path to lic file/ls activation lic') except exception as ex print(ex) note if the path parameter is null, then the default path that activatelicenseoffline searches for the file is 'c \users\\%username%\desktop\ls deactivation req' local license check to verify the license locally on the device without connecting to the backend, we utilize the localcheck function in the following manner if ( license != nullptr ) { license >localcheck(); }if(license != null) { license localcheck(); }license local check() if license is a nullptr , it indicates that a local license does not exist therefore, it is crucial to first confirm the existence of a local license before proceeding with any operations related to the license the localcheck function also throws exceptions to indicate any encountered issues this feature proves beneficial in assessing the license's validity and detecting potential license tampering if any irregularities are detected, the function will throw an exception to ensure license integrity, it is considered best practice to perform a localcheck (offline check) during each startup this practice helps confirm that the license file has not been copied from another computer and that the license is in a valid state a code sample that handles all potential exceptions is also provided below if ( license != nullptr ) { try { license >localcheck(); } catch ( licensestateexception ) { //license invalid if ( !license >isactive() ) //license inactive if ( license >isexpired() ) //license expired if ( !license >isenabled() ) //license disabled } catch ( productmismatchexception ) { //license does not belong to configured product } catch ( devicenotlicensedexception ) { //license does not belong to current computer } catch ( vmisnotallowedexception ) { //currently running on vm, when vm is not allowed } catch ( clocktamperedexception ) { //detected cheating with system clock } }if (license != null) { try { license localcheck(); } catch (licenseinactiveexception) { // license is inactive } catch (licensedisabledexception) { //license is disabled } catch (licenseexpiredexception) { // license is expired } catch (productmismatchexception) { //license does not belong to configured product } catch (devicenotlicensedexception) { //license does not belong to current computer } catch (vmisnotallowedexception) { //currently running on vm, when vm is not allowed } catch (clocktamperedexception) { //detected cheating with system clock } }try license local check() except exception as ex print(ex) offline update to update licenses offline, we use the updateoffline( path ) method as shown below, where license is a license object if ( license >updateoffline( path ) ) { //license succesfully updated } else //license could not be updated if (license updateoffline(path)) { //license succesfully updated } else //license could not be updated if license update offline('offline files/license refresh lic',false) pass else pass just like the previous code sample, we can also first check whether license is a nullptr to confirm the local license exists before we attempt to update it we can also handle the specific exceptions thrown by updateoffline( path ) as shown below if ( license == nullptr ) //cannot refresh an inactive license else { try { if ( license >updateoffline( path ) ) { //license succesfully updated } else { //license could not be updated } } catch ( signaturemismatchexception ) { //device does not match update file's device signature } catch ( locallicenseexception ) { //local license file cannot be read, may be corrupted } catch ( productmismatchexception ) { //license product code doesn't match configuration product code } catch ( devicenotlicensedexception ) { //license refresh file does not correspond to current device } } if (license != nullptr) { try { if (license updateoffline(path)) { //license succesfully updated } else { //license could not be updated } } catch (filenotfoundexception) { //if file cannot be found } catch (invaliddataexception) { //if file content is empty or invalid } catch (signaturemismatchexception) { //in case signature in the file is not valid or missing } } try if license update offline('offline files/license refresh lic',false) pass \# license updated! else pass except exception as ex print(ex) license deactivation to deactivate a license offline, first ensure that the license is currently active then an offline deactivation request file will be created at the path defined in the parameter of deactivateoffline( path ) note if the path parameter is null, then the default path that deactivateoffline() creates the file at is 'c \users\\%username%\desktop\ls deactivation req' after creating the offline deactivation request file, it is vital that the local license file is deleted, using clearlocalstorage a full code sample is as follows if ( license != nullptr && license >isactive() ) { try { auto filepath = license >deactivateoffline( path ); } catch ( locallicenseexception ) { //local license file cannot be read, may be corrupted } licensemanager >clearlocalstorage(); //to finish deactivation process, upload deactivation request file to the licensespring portal } else //license is already deactivated if (license != null && license status() isactive()) { try { string filepath = license deactivateoffline(path); } catch (locallicenseexception) { //local license file cannot be read, may be corrupted } licensemanager clearlocalstorage(); //to finish deactivation process, upload deactivation request file to the licensespring portal } else //license is already deactivated if license license active() try path = license deactivate offline("path") except exception as ex print(ex) manager clear local storage() automating offline licensing automating the offline activation process becomes achievable by utilizing the following api endpoints offline activation offline deactivation these endpoints provide developers with the necessary tools to seamlessly manage offline license activation, enabling users to access and activate licenses without relying on a constant internet connection note if you want to use these api endpoints directly, instead of using the sdk, please contact us for additional instructions troubleshooting exceptions related to offline activation exceptions that might occur when performing offline license activation signaturemismatchexception signature inside activation file is not valid locallicenseexception invalid activation file provided productmismatchexception license product code does not correspond to configuration product code devicenotlicensedexception license file does not belong to the current device why is the license file not generated after uploading the request file? the offline license activation process may encounter failure due to any of the following reasons total activations on the account have reached the maximum limit the license is expired or disabled incorrect license credentials provided during activation incorrect product configuration, such as using a shared key, api key, or product code the license is associated with an account using the free tier