Offline license verifications

Welcome to our blog featuring offline license verifications in Cryptolens. We will cover how to set up offline verification in theory and in practice, regarding two major use cases:

  1. When a customer is allowed to temporarily be offline (for example, use the license while they are in airplane mode).
  2. When a customer is allowed to permanently be offline (for example, behind a corporate firewall).

This blog is based on the following page in our documentation.

Here is a YouTube video covering the same topic:

Background

Let us refresh our memory of the standard license key verification code. For the remainder of this blog, we will cover example codes in Python, but the process is similar in other languages.

Below you can find the basic key verification code in Python.

result = Key.activate(token=auth,\
  rsa_pub_key=RSAPubKey,\
  product_id=3349, \
  key="ICVLD-VVSZR-ZTICT-YKGXL",\
  machine_code=Helpers.GetMachineCode(v=2))

if result[0] == None or not Helpers.IsOnRightMachine(result[0], v=2):
  # an error occurred or the key is invalid or it cannot be activated
  # (eg. the limit of activated devices was achieved)
  print("The license does not work: {0}".format(result[1]))
else:
  # everything went fine if we are here!
  print("The license is valid!")

When Key.Activate is called, it calls Cryptolens API, which in turn returns a signed JSON object placed in the result variable. This allows you to proceed as normal and check features, expiry dates, and other parameters. In the code above, we are checking if the license is activated on the correct machine.

Using the following code in Python, we can save the JSON object to disk, allowing us to read it again when the customer lacks internet access.

# res is obtained from the code above
if result[0] != None:
  # saving license file to disk
  with open('licensefile.skm', 'w') as f:
    f.write(result[0].save_as_string())

Case 1 – Temporarily offline

If customers are expected to be offline once in a while, it is considered good practice to always attempt to make the key.activate call, and only load the saved license file from disk if the customer is offline and key.activate fails.

The following Python code example shows you how to load the saved license file from disk:

# read license file from file
with open('licensefile.skm', 'r') as f:
  license_key = LicenseKey.load_from_string(pubKey, f.read(), 30)

if license_key == None or not Helpers.IsOnRightMachine(license_key, v=2):
  print("NOTE: This license file does not belong to this machine.")
else:
  print("Feature 1: " + str(license_key.f1))
  print("License expires: " + str(license_key.expires))

Notice that the parameter load_from_string has “30” set as a parameter. This means that the customer is only allowed to use the software offline for 30 days. You can customize this value so it suits your use case. For example, you may want to change it to 7, if you only want to allow a customer to be offline for a week.

When the date has been reached, the customer will need a new license file (which may be obtained by successfully calling key.activate), which can be done with the LoadFromFile method.

You could also remove the “30” parameter if you do not want to set a limit at all.

If you want to see more code examples in Python, please visit our GitHub page.

Case 2 – Permanently offline

To support customers to be fully offline and still use your software for a long period of time, you would have to send the license file to your customers since they cannot call key.activate.

There are four methods you can use:

  1. Calling key.activate on your end and sending the file to your customer. You can automate this method.
  2. Using Activation forms hosted by Cryptolens for an easier solution.
  3. Obtaining the file manually in the dashboard.
  4. An On-premise License Server by Cryptolens for when you anticipate many end users or want to support floating licenses offline.

1:

The first method is where you call key.activate on your end and send the license file to your customer, for example, over an email. If you would like, you could set up an automized way where your customers can request to download their license file from your dashboard. This could, however, become somewhat complex.

2:

An easier way is to use activation forms by Cryptolens. When inside the Cryptolens dashboard, open the tab called “Forms”, and click on Activation Forms. This form performs a call to key.activate much like you would do on your own in the previous method, but we provide a simpler GUI for your and your customer’s convenience.

Using the form, customers can simply enter their license key and machine code, click on active, and they will obtain their license file that they can insert on their machines.

3:

You can also manually download the license file from the Cryptolens dashboard. Go to the desired product page, find the license key you want to download the license file of, and click on the yellow wrench icon to the right of the key. Click on “Download activation file” and send it in your desired way to your customer.

4:

All of the above-mentioned methods are useful when there are only a few employees on site who would use your software offline. But, if you anticipate that your customers will have many end users, or if you want to support floating licenses offline, you can use an on-premise license server that Cryptolens provides. Please read the documentation relating to the on-premise license server to learn more about this approach.

Thank you for reading this blog about setting up offline license verifications in Cryptolens, please feel free to ask questions to [email protected].


Get Started with Cryptolens Today!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.