LicenseKey
licensekey.h File Reference

License key interface. More...

Go to the source code of this file.

Functions

int licensekey_verify (const char *app_name, int app_id, int major_version, int minor_version)
 Perform a license key check. More...
 
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 for ACAP3 applications. More...
 
char * licensekey_get_exp_date (const char *app_name, const char *licensekey_path)
 Return the expiration date of the license. More...
 
char * licensekey_get_state_string (const int state_code)
 Return an explicatory message of a license key state for ACAP3 applications. More...
 

Detailed Description

License key interface.

The license key interface checks that an application has a valid license key installed. 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.


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.

Example

This is an example of the code to verify the license key.

#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 excuted 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);

Function Documentation

◆ 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_nameThe name of the application. Must match APPNAME in package.conf.
app_idThe application id of the application, assigned by Axis. Must match APPID in package.conf.
major_versionThe major version of the application. Must match APPMAJORVERSION in package.conf.
minor_versionThe minor version of the application. Must match APPMINORVERSION in package.conf.
Returns
1 on success, 0 on 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 for ACAP3 applications.

Parameters
app_nameThe name of the application. Must match APPNAME in package.conf.
app_idThe application id of the application, assigned by Axis. Must match APPID in package.conf.
major_versionThe major version of the application. Must match APPMAJORVERSION in package.conf.
minor_versionThe minor version of the application. Must match APPMINORVERSION in package.conf.
licensekey_pathOptional license key path meant to be used mainly for acap3 but is also available for acap2. Defaults to the acap2 license key folder.
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_nameThe name of the application. Must match APPNAME in package.conf.
licensekey_pathOptional license key path meant to be used mainly for acap3 but is also available for acap2. Defaults to the acap2 license key folder.
Returns
string with the expiration date in YYYY-MM-DD format.
NULL if 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 for ACAP3 applications.

Parameters
state_codeInteger with license key state.
Returns
string with license key state message, needs to be freed with g_free()
NULL if state is not a valid error state