Skip to content

About

License server that can be installed by your clients on-premise, especially if they have machines that need to be offline.

Topics

Resources

Stars

36 stars

Watchers

3 watching

Forks

Repository files navigation

License Server

Note: a seprate subscription is required to use the license server: https://cryptolens.io/products/license-server/

Idea

Problem: Large companies tend to have strict policies that restrict certain machines to have direct internet access. This is a problem if we want license files on them to be up-to-date.

Solution: We allow one computer, the license server, to have internet access. All the machines in the network will contact the license server and it will in turn contact Cryptolens. Alternatively, the license server can store a copy of the license files and work offline.

Getting started

You can run the license server with Docker, use the pre-built binaries, or build it with the .NET SDK.

Docker

From a source checkout, set cryptolens_configurationstring to the signed Configuration Data from the License Server page. Run docker compose up -d in container/ to build the image and start the server.

To distribute the server to an air-gapped site, build and sign the offline bundle on a connected machine using the packaging script. The Docker guide covers local setup, packaging, and testing the bundle before delivery.

Using the pre-built license server

You can use our pre-built binaries for all use cases (including the local floating license server feature).

When you use the binaries, you can either store the configuration in the config file (as we describe later), configure the server using environment variables (read more here) or pass on the configuration as a command line variable (read more here).

Please keep in mind that the license server will only read the environment variables or the -config command line parameter if you run it as a service (read more here), unless you set cryptolens_configurationstring environment variable with the configuration string from this page.

To sum up, you can start the server in two ways:

  1. If you choose to use environment variable, you would need to set cryptolens_configurationstring to the configuration string.
  2. If you instead want to supply the configuration string as a command line argument, you can start the server using as follows:
LicenseSerer.exe -config <the configuration string>
  1. By using a config.json file (not recommended).

Packaging self-contained builds

On every push to master, GitHub Actions reads the first entry in release-versions.json, runs the tests, and uploads the Linux, Windows, and macOS archives to the workflow run. To set a new release version, insert a new entry at the top with a three-part version and a short description. If the version stays the same, CI builds another set for that commit and stores it with that workflow run.

The packages bundle .NET 10 or .NET 6 for x64 and ARM64. The platform appears in the filename as linux, win, or osx. Windows packages use .zip. Linux and macOS packages use .tar.gz to preserve the executable permissions. Prefer .NET 10 for new deployments. Microsoft no longer services .NET 6.

On a build machine with the .NET 10 SDK, Bash, tar, and zip, run the command for the platform you want to package.

On Windows, build the release archives in WSL using the .NET 10 SDK installed inside WSL. Keep both the checkout and the build output on the WSL Linux filesystem, for example ~/src/license-server and its artifacts/ directory. Paths under /mnt/c use the Windows filesystem. Packaging from the Linux filesystem preserves the executable permissions needed by the Linux and macOS launchers, including the Linux launchers in binaries.zip.

bash scripts/package-release.sh linux 2.14.0
bash scripts/package-release.sh win 2.14.0
bash scripts/package-release.sh osx 2.14.0

Use the actual server release version as the argument. Publish folders and archives go under artifacts/. The scripts/package-linux.sh command is also available for building Linux packages.

Copy the appropriate archive to the offline host and extract it. Keep the entire folder together. Each package includes its .NET runtime and requires a compatible host operating system. Linux builds require a glibc-based distribution with the .NET native system dependencies.

On Linux or macOS, run ./LicenseServer -config-file /path/to/signed-configuration from the extracted folder. On Windows, run .\LicenseServer.exe -config-file C:\path\to\signed-configuration from an elevated PowerShell.

Use the existing offline license setup with these packages. The Docker packaging and startup instructions apply when deploying the container image.

Building the combined binaries.zip

CI also creates binaries.zip. It includes the legacy net461/, net5.0/, and net6.0/ folders, plus the four self-contained Linux publish folders for the selected version. Linux users can run dotnet LicenseServer.dll from either legacy .NET folder if the matching runtime is installed. To use a bundled runtime, run ./LicenseServer from the appropriate self-contained folder.

To build the ZIP locally, generate the Linux packages first and then run:

bash scripts/package-linux.sh 2.14.0
bash scripts/package-binaries.sh 2.14.0

Building the server yourself

If you need the local floating license server and cannot use environment variables or pass the configuration string as a command line argument as described here, the license server needs to be compiled on your end to create the binaries. All configuration is stored inside the ConfigurationFromCryptolens variable in Program.cs, which can be created on this page. In other words, there is no need to provide any arguments when calling the license server or use an external configuration file.

The license server can be compiled on most operating systems and the process is as follows:

Install .NET

Install the .NET 10 SDK for your operating system and CPU architecture to build and run the current checkout.

Configuring the server

There are three steps involved:

  1. Visit the configuration page to create a configuration that will make the server work in standard mode.
  2. Copy the configuration string and paste it in the ConfigurationFromCryptolens variable in Program.cs.
  3. Environment variables can also be used to change configuration data for a specific user. Please read more here.

Later in this tutorial, there are examples of calling the license server using command line arguments. We recommend to use the configuration string as described in (1) if possible. If you have any questions, please reach out to us at support@cryptolens.io.

Building and running the server

From the repository root, build the .NET 10 target, then launch the DLL from the output directory:

dotnet build LicenseServer/LicenseServerCore.csproj --configuration Release -p:TargetFrameworks=net10.0 -p:GeneratePackageOnBuild=false
cd LicenseServer/bin/Release/net10.0
dotnet LicenseServer.dll

If you saved the signed configuration to a file, specify its path when you launch the server:

dotnet LicenseServer.dll -config-file /path/to/signed-configuration

Starting the server

In order to launch the server, you need to run LicenseServer.exe as an administrator (you can download it here). The default port is 8080 but this can be changed. One way of doing it is to run CMD as an administrator and then type the command below:

C:\> LicenseServer.exe 5000

For newer versions of the license server, you can this configuration to set the port to 5000.

Please make sure to check that this port is open so that other computers in the network can access it (shown below).

Running as a Windows service

If you would like to run the license server as a service on Windows, you can accomplish that as described here.

Running on Linux and Mac

On Linux or macOS, use the self-contained package to run directly without a system .NET install. For a framework-dependent build on Linux or macOS, install the runtime that matches the build target and launch it as follows:

dotnet LicenseServer.dll

Running the license server on Linux does not require sudo with the default port.

Allowing ports (Windows only)

In order to allow other computers in the network to access the license server, you need to open up the desired port in the firewall. If you use the default firewall, it can be opened as follows:

  1. Run wf.msc
  2. Right click on Inbound Rules and then click on Add Rule
  3. Ryle type should be Port
  4. Specific local ports should be checked, and the textbox at the right of it should be set to 5000 (or any other port of your choosing).
  5. Click next through the entire wizzard and that should be it.

Connect to the server

Depending on which of our client SDKs you use, there will be a different way to provide the URL of the license server. For example, if you use the .NET SDK, every API method (such as Key.Activate) will have an extra parameter LicenseServerUrl, which can be used to provide the URL of the license server.

Additional features

There are two versions of the license server, v1.* and v2.*. If you only need the request forwarding feature, v.1.* version will suffice. If you want to use the extra features listed below, you can use v2.* version instead.

Enable caching of licenses

Since v2.0 there is a way to cache responses to Key.Activate, which helps to reduce the number of requests sent to Cryptolens. This is useful especially if your clients would have temporary internet connectivity issues. To enable license caching, you need to specify how long the license server should store each license. Note: if your application uses the signatureExpirationInterval parameter in HasValidSignature, the lifetime of the cache on the license server needs to be either equal to signatureExpirationInterval or less. Otherwise, your client application will throw an error.

As an example, to launch the server that caches licenses for 10 days, it can be started as follows:

C:\> LicenseServer.exe 8080 10

For newer versions of the license server, you can use this configuration instead.

Customers who are permanently offline

The default behaviour of the server is to always attempt to get the latest copy of the license. However, if you know that the license server will not have access to the internet, it is better to enable the offline mode so that the license server always reads from cache.

To enable offline mode, you can launch the server as follows (or use this configuration string):

C:\> LicenseServer.exe 8080 10 work-offline

In this case, it is a good idea to provide the license files (aka. activation files) that you want to load into the server. You only need to do it once or when the cache needs to be updated. If the license file (with a .skm extension) is in the Downloads folder, it can be loaded as follows (or use this configuration string):

C:\> LicenseServer.exe 8080 10 work-offline "C:\Users\User Name\Downloads"

If you want to load a specific list of files and folders, they can be separated by a semi-colon ';'.

C:\> LicenseServer.exe 8080 10 work-offline "C:\Users\User Name\Downloads";"C:\temp\file.skm"
Floating licenses offline

On the local Licenses page, expand a license to see its active floating leases, with the user or device ID, optional friendly name and expiry. The server stores identified leases in license-service.sqlite, including leases on unlimited licenses. To display a person's name, the application can send it as FriendlyName when activating. Released and expired leases leave the active list.

If you want to use floating licensing in offline mode (for example, to restrict the maximum number of containers a user can start), it can be done as follows:

  1. Visit https://app.cryptolens.io/extensions/licenseserver and copy the "License server configuration" and "RSA Public Key".
  2. When verifying the signature inside your application, please use the RSA Public Key on this page instead of the one you would normally use when your application can access our API. This key will only work with the license server that uses the configuration above.
  3. In the license server project, paste the value of "license server configuration" to ConfigurationFromCryptolens variable in Program.cs. In newer versions, you can choose to place the configuration string in an environment variable (cryptolens_configurationstring) or by supplying it as a command line argument (-config).
  4. Compile the license server in release mode.
  5. In the release folder, create a new folder called "licensefiles".
  6. Visit the product page and click on the yellow button next to the license key that belongs to your client (to manage all activations). Now, click on "Download activation file" and put this file into the "licensefiles" folder created earlier.
  7. You can now send the license server (in the release folder, including all the files and folders) to your client.

Note (for .NET users) For the time being, Key.Activate needs to be called the same way as the in the Unity example: https://help.cryptolens.io/getting-started/unity

// call to activate
var result = Key.Activate(token: auth, productId: 3349, key: "GEBNC-WZZJD-VJIHG-GCMVD", machineCode: "foo", floatingTimeInterval: 150, LicenseServerUrl: "http://192.168.0.2:8080");

// obtaining the license key (and verifying the signature automatically).
var license = LicenseKey.FromResponse("RSAPubKey", result);

Note If the local license server is enabled, floating license status will not be synchronized with Cryptolens, even if online mode is enabled. Moreover, GetKey request will return the information stored on the local license server and sign it using the local license server's private key. This means that if you have enabled floating licensing offline, you need to use public key that was shown on the configuration page for both Activate and GetKey requests.

If you need to deactivate machine earlier, you can use the Deactivate method with Floating=true, similar to the way it would have been done when calling Cryptolens' Web API:

var result = Key.Deactivate("", new DeactivateModel { ProductId = 3349, Key = "key", MachineCode = "machine", LicenseServerUrl = "http://192.168.0.2:8080", Floating = true });

The server stores limited floating seats in the floating_leases table of license-service.sqlite under the configured cache folder, or its working directory by default. Restarts preserve the existing expiry. The server needs write access to that folder. When upgrading from an in-memory version, allow its outstanding leases to expire before issuing new seats.

To obtain the list of all activated floating machines, you can use the GetKey call:

var result = Key.GetKey(token: "", productId: 3349, key: "", LicenseServerUrl: "http://192.168.0.2:8080");

// obtaining the license key (and verifying the signature automatically).
var license = LicenseKey.FromResponse("RSAPubKey", result);
Import and Remove License Files

With a current signed configuration, a publisher public key and a positive cache length, set LICENSE_SERVER_ADMIN_PASSWORD and restart the server to enable file management. With Docker Compose, apply the environment change with docker compose up -d. Use HTTPS for remote administration.

On Licenses, open Import License File, select a signed .skm file and enter the administrator password. The server verifies the signature, saves the original file in license-service.sqlite, and loads it immediately. Import a more recently signed file for the same product and key to replace it. To delete the upload, expand the license and select Remove Uploaded License. Replacement and removal preserve local seat history and assignments. Previously issued client responses follow the application's signature freshness policy.

Files placed in the activation folder are read into memory at startup. SQLite records their product and key so an old response cache cannot restore a removed file. Replace or remove those files in their folder, then restart the server. If the same license exists in both locations, the folder takes priority and the dashboard identifies the unused upload. The signed server configuration still comes from your deployment settings.

Named Users and Node-Locked Devices Offline

The Licenses page shows each license's named-user assignments separately from its floating leases. An administrator can enter a friendly name when assigning a user or device. The ID and friendly name are stored together in SQLite. On Overview, Active Floating Leases shows the next five leases to expire, and Recent Named-User Activations shows the five most recently active assignments. Select a license key to open its full list.

Enable Allow Local Node-Locked Activations when generating the signed server configuration. Set a positive cache length. Leave the reassignment cooldown blank or enter 0 to reuse a seat immediately after removal. Enter a positive number to hold the seat for that many days.

  1. Put the publisher-signed license file in the activation folder. The first import copies its device assignments into license-service.sqlite. Replacing the file updates license terms and keeps local assignments. Keep the database when replacing the container.
  2. To manage seats, set LICENSE_SERVER_ADMIN_PASSWORD in the server environment and restart the process. With Docker Compose, run docker compose up -d from the Compose directory to apply the new environment. Open Licenses, expand the license, and enter the user or device ID your application sends as MachineCode. Use HTTPS when entering the password over the network.
  3. Point the application at the local server, use SignMethod=1, and verify the response with the local server public key shown on the configuration page.

To remove a user or device, open its license, select Remove Assignment beside the ID, and enter the administrator password. With a positive cooldown, the assignment ends immediately and the seat still counts toward the limit until the time shown under Seats in Cooldown. Other available seats can be assigned during that time.

With Allow Local Node-Locked Activations enabled, the server handles Activate, GetKey and Deactivate locally, regardless of the general offline-mode setting. A regular Activate requires an assigned device or user ID. An unknown license or unassigned ID returns a local error. GetKey lists the current assignments and, when local floating licensing is enabled, active floating leases. Only the site administrator can release a named assignment. To release a local floating lease, call Deactivate with Floating=true.

With both modes enabled, a five-seat license allows five node-locked assignments and five concurrent floating leases. Releasing a node-locked seat stops new signed responses for that ID. Applications that cache responses can continue accepting an earlier signature until their configured freshness interval runs out. Choose a cooldown that covers that interval when overlap matters.

For extra floating seats, send MaxOverdraft with each floating Activate, including renewals. The default is zero. For example, MaxOverdraft=2 on a five-seat license allows seven concurrent floating leases. The Licenses page shows the seat type. The signed machine ID starts with floating: for a regular seat or floating-overdraft: for an overdraft seat.

Usage-based licensing offline

Enable offline mode, configure the publisher public key and a positive cache length, and load a current signed license. Applications can use the following Data API methods on the local server.

Operation Shared license counter Counter on an assigned machine
Create AddDataObjectToKey AddDataObjectToMachineCode
Read current values ListDataObjectsToKey ListDataObjectsToMachineCode
Increase IncrementIntValueToKey IncrementIntValueToMachineCode
Decrease DecrementIntValueToKey DecrementIntValueToMachineCode

Pass ProductId and Key for both scopes, and MachineCode for machine counters. Add returns the object ID. Increment and Decrement accept the ID or name and an IntValue amount. With EnableBound=true, the resulting value must be at or below Bound for an increment, or at or above it for a decrement. If the request is denied, the balance stays at its previous value.

The server initializes each license counter from its signed value and each new local counter from the application's opening value. SQLite preserves balances across restarts and license reimports. Installations upgrading from the encrypted usage folder start with these opening balances.

Resetting a license counter

For five CI runs per day, create a license-key data object named runs with an initial integer value of 5. Set the string value of a second data object named cryptolens_dobjreset to [{"Name":"runs","Freq":1,"Default":5}]. Download the signed activation file and import it on the Licenses page. A product-level rule supplies the default for issued files. A rule on the license key replaces the whole list for that license, and an empty list ([]) disables resets.

For each run, call DecrementIntValueToKey with Name=runs, IntValue=1, EnableBound=true and Bound=0. The first counter read or change after midnight UTC restores the allowance once, including after downtime. For a frequency greater than one, resets fall on UTC days of the year divisible by Freq (1 through 366). The schedule applies to matching license-key counters. Machine counters keep their own balances.

Importing a newer signed file updates the allowance for the current period by the quota difference. If three of five runs have been used, raising the quota to ten leaves seven. Reimporting the same file preserves those seven. A frequency change takes effect after the current period ends. Export Activity includes CounterReset and CounterQuotaChanged events for the affected data objects.

Recording feature events offline

On the License Server configuration page, enable Offline Mode and Allow Offline Feature Events, generate the signed Configuration Data, and restart the server with it. Applications can then post to /api/ai/RegisterEvent or /api/ai/RegisterEvents without a loaded license. Supply ProductId if you include a license key. Online servers forward these requests to Devolens.

For example, curl -d "FeatureName=Build&EventName=Finished" http://localhost:8080/api/ai/RegisterEvent records one build. To download the application events stored in SQLite, open Licenses, select Export Feature Events, and enter the administrator password. Previously collected events remain available after collection is disabled until the retention limit removes them.

Exporting activity

Set LICENSE_SERVER_ADMIN_PASSWORD, open Licenses, and select Export Activity. Enter the administrator password and select Download. BSON is the default format for importing into Devolens. Select CSV for a text export. Both formats contain the same events in recorded order.

Each row has a stable Id, UTC Time, Event and numeric State. The server uses Devolens key-log codes where available. For example, 2014 is a regular floating activation, 2015 is an overdraft activation and 2024 is a floating capacity denial. A renewal keeps the same state as a grant and appears as Renew.

For results without a hosted code, including GetKey and license imports, the server uses four local states. -1 means success, -2 means denied, -3 means a server error and -4 means the result is unknown.

Product, LicenseKey and MachineCode identify the license and device where known. Seat snapshots show the signed limit (MaxNoOfMachines), assigned node-locked seats (NodeMachines) and active floating leases including overdraft (FloatingMachines) at the time of the request. FloatingExpires gives the recorded lease expiry in UTC. A blank cell means no value was recorded. A zero count means the server observed zero seats. Data-object operations can include DOId and DOIntValue for the object and integer amount involved.

The CSV prefixes formula-like identifiers and identifiers starting with an apostrophe with one extra apostrophe so spreadsheets display them as text. SQLite and the BSON export keep the original identifiers. BSON is a binary format without built-in encryption.

Each BSON export is a stream of BSON documents. The first document contains the report type in format and the schema version in version. Each following event uses the same field names as the CSV. Timestamps use BSON UTC datetimes and event identifiers retain the same text or integer representation as the CSV. The last document contains recordCount so Devolens can detect an incomplete transfer.

Retaining local logs

Set Log Retention in the signed Configuration Data and restart the License Server. A positive number of days applies to both license activity and feature events. The server deletes rows older than that many 24-hour days using each event's UTC occurrence time. Cleanup runs at startup and once an hour. An unset or zero value keeps logs indefinitely.

Loading settings from a config file

Note In newer versions of the license server, we recommend to create a configuration string as described in the beginning of this page.

To make it easier to deploy the license server on customer site, you can add all settings into config.json in the same folder as the server. The structure of the configuration file is shown below:

{
    "Port" : 8080,
    "CacheLength": 365,
    "OfflineMode" : True,
    "ActivationFiles" : ["C:\Users\User Name\Downloads"]
}

The ActivationFiles can either reference a specific file or a folder. If it references a folder, all files with the .skm extension will be loaded.

Running the license server as a service

The license server can run as a Windows service in the background. This can be accomplished as follows (using sc). Note, these commands need to be ran as an Administrator:

sc create license-server binpath="D:\path\to\licenseserver\LicenseServer.exe" start=auto
net start license-server

Note: the path to the license server needs to be absolute. It's important that you provide a configuration string that can be obtained at can be obtained on https://app.cryptolens.io/extensions/licenseserver. When creating a new configuration, please set Activation file folder to an absolute path. For example, C:\license-files.

Once you have the configuration string, you have three ways that you can start the server:

If you have compiled the server yourself

  1. Copy the configuration string that you obtained above into ConfigurationFromCryptolens variable and build the License Server yourself.

If you are using the pre-built binaries

  1. Create an environment variable cryptolens_configurationstring with the configuration string from above.
  2. Supply the configuration string (from above) as a command line argument when registering LicenseServer.exe as a service, as follows:
sc create license-server binpath="D:\path\to\licenseserver\LicenseServer.exe -config <the configuration string>" start=auto

We have tested the license server version that targets .NET Framework 4.6.1.

Below are other useful commands:

sc stop license-server
sc queryex license-server
sc delete  license-server

To obtain information about server status, e.g. the IP it is listening or if any errors have occurred, you can use the Windows Event log.

If you need any help, please let us know at support@cryptolens.io.

Alternative ways to configure the server

Using environment variables

It is also possible to configure the license server using environment variables. For now, the license server will only read the environment variables in two cases:

  1. If the ConfigurationFromCryptolens in Program.cs is not null or empty.
  2. If license server runs as a service (Windows).

For example, if you prefer to use the environment variables, you can set ConfigurationFromCryptolens to any string value and then rely on the environment variables. Alternatively, you can create a configuration string at https://app.cryptolens.io/extensions/licenseserver and then set "path to config file" to USE_ENVIRONMENT_VARIABLES.

Cryptolens uses the following environment variables:

Name Description
cryptolens_offlinemode Specifies if the license server should contact the central server (if set to false) or rely on the cached version if such exists (if set to true). When set to true, the license server will at first try the cache before attempting to contact the license server.
cryptolens_port The port to use.
cryptolens_activationfilefolder The path to the folder with activation files. Please set it to an absolute path when running the license server as a service.
cryptolens_cachelength The amount of days until a new license file should be obtained.
cryptolens_pathtoconfigfile The path to the configuration file. This can be useful if you anticipate that your clients might need to change certain properties more often, and then it may be easier to change the file rather than restarting the machine (which is often required for the environment variables to take effect). For now, you can set the port and the folder to the activation files. If you plan to run the server as a service, please set this to absolute path.
cryptolens_cachefolder Path to the cache folder. If you plan to run the server as a service, please set this to absolute path.
cryptolens_configurationstring An optional parameter that you can use to provide the configuration string that would normally need to be added in the code. The license server will always check for this environment variable at start and it will have priority over command line arguments.

Note: when running the license server as a service, all paths to files and folders need to be absolute.

Providing the configuration string as command line argument

Since version v2.13, you can pass on the configuration string as a command line argument, meaning that you can start the server as follows:

dotnet LicenseServer.exe -config <paste configuration string here>

The configuration string can be obtained at https://app.cryptolens.io/extensions/licenseserver.

About

License server that can be installed by your clients on-premise, especially if they have machines that need to be offline.

Topics

Resources

Stars

36 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages