License Key API
licensekey.h File Reference
License key interface.
The license key interface checks that an application has a valid license key installed. This allows you to control who can run the application by making it exit early if the device doesn't have a valid license key.
To receive a license key the user enters the application's license code and the device's serial number on the Axis web service page called Embedded Applications.
The license key is created by Axis in XML-format with a description of the application and a signature that is verified by the License key library using a public RSA-key that resides in the device.
This library is partitioned into a static and a dynamic part. The static part performs checks to make sure that the dynamic part is not circumvented by malicious users. Both parts of the library must be linked to for the check to work.
Example
This is an example of the code to verify the license key.
#define APP_NAME "hello_world"
#define APP_ID 123
#define MAJOR_VERSION 1
#define MINOR_VERSION 2
int main()
{
if (licensekey_verify(APP_NAME, APP_ID, MAJOR_VERSION, MINOR_VERSION) != 1) {
syslog(LOG_ERR, "License key verification failed");
exit(1);
}
...
...
}
Anti debugging (ptrace)
Hackers who are trying to circumvent the copy protection schemes commonly use debuggers. A common tool for Linux is the ptrace(2) system call. When used for debugging it is first called from within an application and then the target application is executed using one of the exec() calls. To make the application more secure call ptrace from within the application. If the application is being debugged using ptrace, the call will fail, since it has already been called once from within.
is_debugged = (ptrace(PTRACE_TRACEME, 0, 0, 0) == -1);
Expiration date explanation
The expiration date is the first day the license is no longer valid. This means the license is only valid before the expiration date, not on or after that date.
Also, the expiration date is based on UTC time. If you are in a different time zone, the license may expire a few hours before or after the date shown.
licensekey_states.h File Reference
License key states file.
API Reference
Header File
Include the header for applications using this library:
#include <licensekey.h>
Documented headers:
licensekey.h: License key interface.licensekey_states.h: License key states file.
Dependencies in the Makefile
When linking the application, provide the following option to the compiler:
-Wl,-Bstatic -llicensekey_stat -Wl,-Bdynamic -llicensekey -ldl
The -Wl option tells the compiler to forward the following comma-separated options to the linker.
Functions
licensekey_verify()
int licensekey_verify ( const char* app_name,
int app_id,
int major_version,
int minor_version
)
Perform a license key check.
Parameters:
app_name: The name of the application. Must matchacapPackageConf.setup.appNameinmanifest.json.app_id: The applicationidof the application, assigned by Axis. Must matchacapPackageConf.setup.appIdinmanifest.json.major_version: The major version of the application. Must match the major version ofacapPackageConf.setup.versioninmanifest.json.minor_version: The minor version of the application. Must match the minor version ofacapPackageConf.setup.versioninmanifest.json.
Returns:
1on success,0on failure.
licensekey_verify_ex()
int licensekey_verify_ex ( const char* app_name,
int app_id,
int major_version,
int minor_version,
const char* licensekey_path
)
Perform a license key check with custom path support and detailed status reporting.
Parameters:
app_name: The name of the application. Must matchacapPackageConf.setup.appNameinmanifest.json.app_id: The applicationidof the application, assigned by Axis. Must matchacapPackageConf.setup.appIdinmanifest.json.major_version: The major version of the application. Must match the major version ofacapPackageConf.setup.versioninmanifest.json.minor_version: The minor version of the application. Must match the minor version ofacapPackageConf.setup.versioninmanifest.json.licensekey_path: Optional license key path. PassNULLto use the default path.
Returns:
- Integer with license key state. The corresponding state message may be retrieved with function
licensekey_get_state_string().
licensekey_get_exp_date()
char *licensekey_get_exp_date ( const char* app_name,
const char* licensekey_path
)
Return the expiration date of the license.
Parameters:
app_name: The name of the application. Must matchacapPackageConf.setup.appNameinmanifest.json.licensekey_path: Optional license key path. PassNULLto use the default path.
Returns:
- String with the expiration date in
YYYY-MM-DDformat. NULLif the expiration date couldn't be read.
licensekey_get_state_string()
char *licensekey_get_state_string(const int state_code)
Return an explicatory message of a license key state returned from licensekey_verify_ex().
Parameters:
state_code: Integer with license key state.
Returns:
- String with license key state message, needs to be freed with
g_free(). NULLif state is not a valid error state.
Enumerations
LicenseKeyStateSTATE_VALIDATION_ERRORSTATE_VALIDSTATE_INVALID_VERSIONSTATE_EXPIRED_DATESTATE_ILLEGAL_APPLICATION_ID_MISMATCHSTATE_ILLEGAL_DEVICE_ID_MISMATCHSTATE_ILLEGAL_MISSING_FIELDSSTATE_ILLEGAL_INVALID_ENTRY_APPLICATION_IDSTATE_ILLEGAL_INVALID_ENTRY_MIN_MAJORSTATE_ILLEGAL_INVALID_ENTRY_MIN_MINORSTATE_ILLEGAL_INVALID_ENTRY_MAX_MAJORSTATE_ILLEGAL_INVALID_ENTRY_MAX_MINORSTATE_ILLEGAL_KEY_DECODING_FAILSSTATE_ILLEGAL_INVALID_SIGNATURENUM_LICENSEKEY_STATES