This tutorial demonstrates the basic steps involved to integrate FortLM C/C++ into a sample application. For more information please refer to the document  'FortLM_reference_guide.pdf'  in your FortLM C/C++ installation.

The source code 'champlm_demo.c' and makefile for the sample application can also be found in your FortLM C/C++ installation.

Required code changes

Compile demo application on Windows

Compile demo application on Linux

Run the demo application

Generate a public and private key pair

 

Required Code Changes:

 1) Include FortLM header file

The first thing to do is to include FortLM header 'champlicense.h' in your application:

#include "champlicense.h"

 2) Generate vendor's public and private key (1024 bit)

In this demo 'sample_vendor_pub_key.pem' and 'sample_vendor_priv_key.pem' are used as vendor's key pair. In a real application, you need to generate your own public and private key pair.

The vendor's public key will need to be included in the applications' initialization code as shown below. Note it is important to use line continuation to construct a correct public key string.

char *vendor_pubkey=
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQChVpK/Icnkm9FYCDkPedA/fWr3\
6izKVfDcV420AqW21ubDiqwtlK9GloJF4Uhb3zwVumwqptcJs73N3+5GiZY3H+6n\
xogxUgQ99gDfYWXFH2JzdoH8EhW5D8R9fkLfafd3ygNKogfFz2HSZvjT1jpnp48E\
FHPVsWZ1KC7zbEcFQwIDAQAB";

3) Name an environment variable for the application to locate its license

Your application will be using an environment variable to locate its license file. For this demo application we use CHAMP_DEMO_APP_LICENSE.

char *license_envvar = "CHAMPLMS_DEMO_APP_LICENSE";

4) Features restriction

A feature can be an arbitrary string which is found in the "FEATURE=" line in your license file. Use NULL if you do not want to restrict your software based on features.

char *feature="demo";

5) Version restriction

A version string appears in the "VERSION=" line in your license file. Use NULL if you do not want to restrict using your software based on versions.

char *version=NULL;

6) HostID restriction

Set the hostID parameter to NULL if we want to check if the hostID specified in a license file matches the target computer. Set it to "000000000000" (twelve 0s) will disable hostID checking.

char *hostID=NULL;

7) Call fortlm_verify_license to validate the license file

int result;
result=fortlm_verify_license( license_envvar, vendor_pubkey, hostID, feature, version);
if (result == 0) {
           printf (" Feature %s verified Ok.\n", feature);
} else {
           printf("Invalid License! %s\n", license_err2str(result));
           exit (1);
}


Compile demo application on Windows:

On Windows, we use the freely available c/c++ compiler included in Microsoft Windows 7. Visual C++ 2008 also contains this compiler.

First open a Microsoft Windows SDK 7 “CMD shell”, then:

cd c:\fortlm

Set environment to x86 release mode:

setenv /release /x86

Compile and link our demo application:

cl /MT champlm_demo.c /link /LIBPATH:x86\win champlicense.lib /LIBPATH:x86\win\openssl1.0.0c\lib libeay32.lib ssleay32.lib

Note if your project creates a DLL and uses /MD linker option to link with MSVCRT32.lib, you need to use /NODEFAULTLIB:LIBCMT.lib when linking with champlicense.lib. For example:

cl /MD champlm_demo.c /link /LIBPATH:x86\win champlicense.lib /LIBPATH:x86\win\openssl1.0.0c\lib libeay32.lib ssleay32.lib /NODEFAULTLIB:LIBCMT.lib

 When compiling for a 64-bit (X86-64) target system, you simply need to set mode to x64 using command setenv /release /x64 and also replace "x86" with "x64" in the 'cl' command above .

 A simple demo nmake file is also shipped with FortLM. You can compile the demo by running

nmake -f Makefile_demo.mak, or
nmake -f Makefile_demo_x64.mak

 

Compile demo application on Linux

On Linux, we use g++ compiler:

cd /path-to/fortlm

On a x86 32 bit system:

g++ champlm_demo.c -w -L./x86/linux -L./x86/linux/openssl100c/lib -Wl,-Bstatic\
          -lchamplicense -lcurl -lssl -lcrypto -Wl,-Bdynamic -lrt -ldl -o demo

On a x86-64 64-bit system:

g++ champlm_demo.c -w -L./x64/linux -L./x64/linux/openssl100c/lib -Wl,-Bstatic\
       -lchamplicense -lcurl -lssl -lcrypto -lz -Wl,-Bdynamic -lrt -ldl -o demo

A simple demo make file is shipped with FortLM. You can compile the demo by running:

make -f makefile_demo clean
make -f makefile_demo,

or for x64

make -f makefile_demo_x64 clean
make -f makefile_demo_x64

 

 

Run the demo application

You will get the following error message when you try to run this demo application

>>You must set the environment variable CHAMPLMS_DEMO_APP_LICENSE to point to your license file! If you don't have a license file, contact your application supplier.

Process license file: C:\Users\bob\license.key
File not found! C:\Users\bob\license.key
Missing one or more of HOSTID, VERSION, FEATURE, START, EXPIRE lines in the license file. demo license verification failed. Error code 7. Read license data failed.
License file environment variable not defined or the file it points to does not exist

License checking failed. Exiting.

 To get rid of the error message and unlock your application, you will then need to create a license file. See tutorials on creating and signing license files for more information.

 

 

Generate a public and private key pair

You can use the Openssl to generate a 1024 bit key pair (OpenSSL Toolkit is shipped with FortLM).

openssl genrsa 1024 > vendor_priv_key.pem
openssl rsa -in vendor_priv_key.pem -pubout > vendor_pub_key.pem

You might get a warning message: “can’t open config file: /path/openssl.cnf”. This warning message is just a warning and it does not affect the keys to be generated successfully. To get rid of the warning message you need to set the path to the .cnf file supplied with installation. Simply create an environment variable (for example): OPENSSL_CONF=C:\champlicense\x86\win\openssl1.0.0c\ssl\openssl.cnf.

If you get message like "unable to write random state", try running the commands above as 'root' or 'administrator'.

The generated private key will be used to sign your license files. Keep it in a safe place!