beautypg.com

Verifying the license key – Echelon i.LON SmartServer 2.0 User Manual

Page 172

background image

158

Creating FPM Application Licenses

Verifying the License Key

To write your license validation algorithm so that it verifies the license key in the FPM application
license file, you do the following:

1. Check the results of the Node Lock Check. For example:

if (taskCallBlock.sts == LicMgrStsOK)
{

//store the license data

pLic

=

taskCallBlock.pLicense;

2. If the SmartServer passes the check, get the secret key defined for your FPM in a block of

memory. If you split it into pieces, you must assemble them here. For example:

memcpy(secretKey, FPM_KEY_PART_0, sizeof(FPM_KEY_PART_0));
memcpy(&secretKey[sizeof(FPM_KEY_PART_0)], FPM_KEY_PART_1,
sizeof(FPM_KEY_PART_1));

In this example the secret key is the 16-byte hexadecimal string appropriate for the HMAC-MD5
algorithm that you defined in step 2. See Creating a License Generator Configuration File for
more information on the SecretKey property.

3. Call your security algorithm to calculate a license key. This must be the same security algorithm

used in the License Generator DLL. The security algorithm returns a license key (digest) that is
calculated from the license manager control structure data returned by the license manager, the
length of the license manager control structure data, the secret key defined for your FPM, and the
length of the secret key. For example:

LICMGR_hmac_md5((unsigned char*)pLic->szHashText,
strlen(pLic->szHashText), secretKey, 16, digest);

4. Compare the length and content of the license key stored in the license file to that of the license

key returned by the security algorithm. For example:

if ((pLic->licenseKeyLen == MD5_DIGEST_LEN) &&

(memcmp(pLic->licenseKey, digest, MD5_DIGEST_LEN) == 0)){

5. Optionally, you can evaluate any other data in the license manager control structure data besides

the licenseKey and licenseKeyLen fields. The license manager control structure contains all the
data included in the license file, split into the following fields:

• szHashText. A pointer to the text over which the security algorithm runs. It combines a

number of other fields.

• szLicenseType. A pointer to the text for the lock type (e.g., “MACID”).
• lockType. An enum value indicating the lock type.
• szLockId. A pointer to the text of the lock ID.
• lockId. A pointer to the converted binary bytes of the lock ID if the lock type is “MACID” or

“LUID”. If the lock type is not “MACID” or “LUID” or if this field is not used, this field is
NULL.

• szOptions. A pointer to the text of the options field, if any.
• licenseKey. A pointer to the binary bytes of the license key. Used in step 4.
• licenseKeyLen. he length in bytes of the licenseKey field. Used in step 4.
• szFullLicenseText. A pointer to the complete XML text of the license.
• szUserLicenseText. A pointer to the beginning of the (optional) user section of the XML

license text.