.. include:: definitions.rstinc

================
License system
================

An application built with AGX requires a valid license to run. AGX can either be licensed with a *runtime*-license, or a *developer license*.
A runtime-license usually does not have a time limit, but needs to be tied to a network adapter in your computer.


License information for a node-locked license is generated through a four step process:

1. Download the license executable available for all platforms `here <https://www.algoryx.se/download/installers/RuntimeKeyGenerator.zip>`_.

2. Next, execute the **RuntimeKeyGenerator** that correspond to your platform. This will generate a number of Hardware ID:s based on the available network adaptors (NIC).

3. Copy the list of the Hardware ID:s and send the following information to support@algoryx.se:

  -	User/company name
  -	Contact/email
  -	HardwareID (select one whole line from the output of RuntimeKeyGenerator)
  -	Url (Personal or your company’s)

4. You will receive a file in email which should be named agx.lic that you should place in the installation directory of AGX Dynamics, or one of the directories specified by the environment variable AGX_FILE_PATH, or with the AGX API call :cpp:`agxIO::Environment::getFilePath(agx::Environment::RESOURCES)` (see :numref:`locating-files`).

-------------------------
Sample Windows session
-------------------------
Below is output from the RuntimeKeyGenerator.exe:

.. image:: images/license_system_1.png


--------------------
Sample Linux session
--------------------
Output from a typical Linux session:

.. code-block:: console

  johnd@ubuntu:~$  ~/Downloads/RuntimeKeyGenerator-amd64-ubuntu-20.04 

  Available unique ids:

  TYPE  Hardware ID                      Comment                                 
  ------------------------------------------------------------------------------
  NIC   36A55A36955110F55967514527F8FFD3 wlo1                                    

  One of these Hardware Id value(s) should be used when acquiring 
  a license from Algoryx


  johnd@ubuntu:~$ 


--------------------
License deployment
--------------------
This section describes the workflow for shipping the license with your end-user application.

When deploying an application based on AGX Dynamics, the application must be accompanied by a valid license issued from Algoryx.
This license must be a commercial valid runtime license intended for the application as written in the AGX Dynamics license agreement. 
A Subscription or Developer license must NOT be used for deploying applications to third-party customers.

License file
^^^^^^^^^^^^^^
To be able to run an application with AGX Dynamics a valid license is required. This license file is distributed as a text file agx.lic as part of the licensing procedure.
During internal development, an OEM/Developer license can/should be used. 
Usually the license file (agx.lic) is placed into a directory where AGX can locate it (see :numref:`executing_an_agx_application`).
A license file contains a number of fields:

- User: Name of the user/company/scope
- Contact: email address to the licensee
- EndDate: Last date when this license is valid
- HwKey: List of hardware keys for which this license is valid
- Modules: List of AGX modules
- Version: For which version of AGX this license is valid
- EndOfUpdate: Compared to the build date of AGX Dynamics and specifies the last date for which this license is valid.


Runtime license deployment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When an application is being deployed, we recommend *that you do not ship the agx.lic on disk*. The main reason for this is to avoid leaking the license file in clear text on the internet.
A runtime license usually has the following properties:

- EndDate: None - meaning it will be valid forever
- EndOfUpdate - If set, it indicates that this is a runtime license with maintenance/update period.
- A specified AGX version: indicates which version of AGX is being utilized in the application. For example: “2.25.0.3”

.. note::

  To reduce the risk of having a license file distributed over the internet, we strongly recommends that an obfuscated license file is used.

.. _obfuscate_license_file:


Validate using obfuscated license file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The process of obfscating a license is where you take the original content of a license file and run it through a tool which generates a long string which represents the license information.

To convert a license file into an obfuscated license string you use the `RuntimeKeyGenerator` executable which is available for all platforms at the following  `link <https://www.algoryx.se/download/installers/RuntimeKeyGenerator.zip>`_. 
For version 2.26.0.0 and later it is also available in your AGX installation. 
To obfuscate a license file you use the command:

.. code-block:: console

  > RuntimeKeyGenerator --obfuscate agx.lic obfuscated.txt

The content of obfuscated.txt can now be copy-pasted into your source code and used as an argument to the verifyAndUnlock method of the Runtime class:

.. code-block::

  const char* licenseStr =  “rF3pUP9LX+m0lP6IFoYOMBaLIq8RvYmPFro0vjjdCjP6WK+rFoXVB6k0cMb0kw2iZa9NoA2irw7PgcwAN1YF46P/Wh3623cjEuXZ8/coslPalc5e/p+Z8G/DAPzI+IvwwxXBg4yzPTsE9CVKm9x5wYLoDQysHdALjiz4fdYsYhYGpOpFb3V2h0c4K/7V0PiLXzICK4jskYUGwP6tNfXzbl4L7aYW0PdiBzeo4JhOpTMuXLtI1Lagk+ZbZhmFbvY5ZejLqlQiohJf4zfl6cWAOgkMkKrnh2PZIMR7pnCPbWktGVTdhNPD1wmJEW/+kMs9999Z6EmaKAlHqvienW22um1LNCMZdgykbtZCWvsgH/qUrfUZrl/QXtbyY83xNrlFUj7zKZjTUbE1TxMdVwNBNxVapjJSxgBqbHakl229wvhi3ZPd3zph6DWNucKdM1a0gqHb4XsVxx6buBnJgm+3jV7AW2A59Go5BCdhLQLrmGjWGz7QrUmptMu//yQKsxsE0HT0ZABr/Hu7CCQIxnVE8mEsQ3ZtcwShrpa9mzq/trS5Zl/LYwIN5G1ayKxTy+UXzriMCC4NPRcpN6YuOzcicqf/Ont5ZCcDCGUcGef2HzBH8GDkHH3umUMeVSfpF8Tvk-/qmArdimyxPzy9SGsz2Zd/PZiu2KgMA5Nca38p0j8ulV4tASpXqCpKY8nWH5xCWe4kfO7pWZaJH+s0FghHx9H+fwc71kC2AAeyr8N+PPUnfnNprV3FIuaTdnaj1mCjVqXcVusWmYqF7JhcPffVPE9rkVdNO2qTNkpywwSGwfhyZmmJASByEqq4qp35AavGi3/twWTnWep1kt9ADcZlCG6fewsg5VrHBb7DDgNmcCWVLE1ew5D8bIpq1aukd8tl3hBqaDcgkdATEA369WJlg==”;
  // Unlock AGX dynamics with the obfuscated license
  bool isValid = agx::Runtime::instance()->verifyAndUnlock(licenseStr);


----------------------------------------
Validating using license in clear text
----------------------------------------
The second way of validating a license file is to use the text in the license file without obfuscating.
**However we do not recommend using this as the license text will be embedded in the binary as text strings.**


.. code-block:: c

  // Read the content of the license file into a string variable
  std::string licenseFileContent = read_license_file_content();

  // Unlock using the text string containing the license file
  bool valid = agx::Runtime::instance()->unlock( licenseFileContent.c_str() );
  if (valid)
    // We got a valid license file
