To start using Self Defense feature in KAV SDK follow the procedure. The procedure contains of preparing environment and deploying Self Defense library.
Preparing environment
To prepare the environment for deploying Self Defense library:
Send your public key to TAM. This key will be signed by Kaspersky Lab and sent back to you in the build of KAV SDK.
Deploying Self Defense library
The step-by-step procedure outlines the deployment steps later in this section.
Step-by-step: Deploying Self Defense library
Self Defense library is incorporated in the kavsdk8_sd.dll file and exposes Self Defense API. This library must never share the same process with KAV SDK library which is incorporated in kave8.dll. Below you can find the step you must follow when deploying the self-protection library.
Step 1. Loading Self Defense library
The kavsdk8_sd.dll library must be included into your application project before its Self Defense API can be called by your installer application. Included into the project this library must be loaded into memory by using its API.
To protect critical resources in application, Self Defense automatically starts in a custom action of your installer. When enabled at installing time, the Self Defense feature remains active after installation finishes, protecting resources specified in the access rules.
Resources defined by access rules are controlled by Kaspersky driver and protected even when your application is unloaded.
To load Self Defense library into system memory,
Invoke kaveSelfDefenseLoad and specify location of the library in its parameters.
Pass NULL if the library is located in the working folder of your application.
Step 1.1. [optional] Configuring diagnostic logging
For diagnostic purposes you may turn on logging of Self Defense events.
To turn on logging for Self Defense,
Invoke kaveSelfDefenseEnableLog.
Step 2. Generating and registering key pair on Windows
Self Defense uses public key encryption as part of its protection of specified resources. You must register the key in the Windows before you install Kaspersky drivers. If you miss this and specify the public key after drivers are installed, you will need to restart the operating system before you could go with deployment of Self Defense library. Drivers load information about the public keys at starting.
To specify the public key:
Use kavsigner tool to create the keys. To locate the tool, open the Tools folder in the SDK program folder.
Send your public key to your TAM.
kaveSelfDefenseSetPublickey.Step 3. Preparing driver environment
The drivers that support Self Defense technology are available from the KAV SDK setup distribution under install_sd folder.
Use udinstaller tool to install the the drivers by following this sequence:
udinstaller --install KLHKudinstaller --install KLIF.The udinstaller tool automatically attempts to start the driver after it registers it in the system registry.
Step 4. Specifying protected installer
Specify processes of installer application that must be protected by Self Defense.
To specify protected processes,
Invoke kaveSelfDefenseSetInstallers passing the list of process PIDs.
Installer processes with the specified PIDs are automatically protected by Self Defense. Note, child processes are not automatically protected and have to be specified separately, if need be.
Step 5. Configuring Self Defense access rules
Configure your installer application and specify resources that must be protected by Self Defense technology.
To configure target resources to be protected by Self Defense,
kaveSelfDefenseSetConfig passing a reference to the filled configuration in its argument.After access rules are configured, the Self Defense is automatically enabled for the resources specified in the rules. As kaveSelfDefenseSetConfig returns with success code, configured resources are protected by Self Defense.
Self Defense protects only the processes started after the initialization of Self Defense. To protect already running processes (ones that were running at the time Self Defense initialized), restart those processes.
Step 6. Unloading Self Defense library
When your installer application finishes installation procedure, the kavsdk8_sd.dll library can be unloaded from memory to free resources. All protection configured through the Self Defense is now maintained by Kaspersky drivers, and Self Defense library is no longer necessary. Your application will remain enabled with Self Defense unless you do one of the following:
To unload Self Defense library from memory,
Invoke kaveSelfDefenseUnload.
Special scenarios
All configurations for Self Defense protection must be performed from within the installer application at the installation stage. These configurations are made by using the Self Defense API exported by kavsdk8_sd.dll library.
When all configurations are done and installation is finished, you can manage the state of Self Defense by using the API provided by kave8.dll. The management can be done from your application that was installed by your installer application.
Scenarios for your application
Following scenarios describe state management functionality provided in KAV SDK library.
Turning off Self Defense protection
If you do not want the Self Defense feature to be active at some time, you may turn it off. Turning Self Defense off does not reset configured access rules. Instead, it temporary disables Self Defense protection. This protection may be then enabled back from within your application through the kaveEnableSelfDefense API.
To turn off Self Defense:
kaveEnableSelfDefense with bEnable set to FALSE.This API is exposed in kave8.dll.
Enabling back Self Defense protection after it was turned off
If Self Defense is turned off, you can reenable it from your application. The following options are available:
This requires removing your product enabled with KAV SDK from the system and installing a new copy of KAV SDK with enabled Self Defense feature.
This allows you to bring back the Self Defense feature on the system already running KAV SDK without having to reinstall your product.
To enable Self Defense from your application,
kaveEnableSelfDefense with bEnable set to TRUE.This API is exposed in kave8.dll.
Scenarios for installer application
Following scenarios describe other management functionality provided out-of-the box in Self Defense library.
Updating public encryption key
When the public key that you have used to install your application equipped with the Self Defense technology expires, you can register a new public key by using kaveSelfDefenseUpdatePublicKey.
To register a new public key:
This API is exposed in kavsdk8_sd.dll.
Reconfiguring access rules
Access rules must be configured at the time of installation. When installer finishes the rules cannot be reconfigured unless you reinstall the application.
To redefine the list of resources protected by Self Defense:
Scenario for uninstaller application
Following scenario describes the procedure that you must follow when removing the application enabled with Self Defense from Windows. The actions described refer to your uninstaller application.
Preparing uninstaller environment
To prepare the environment for removal of the application enabled with Self Defense,
Digitally sign your application uninstaller.
You must use the key pair that was generated by using kavsigner tool for which the public key was placed to system registry by your installer during the installation of your application.
Removing your application
To remove the application enabled with Self Defense:
Clearing Self Defense traces off the system
To clear Self Defense traces off the system,
Invoke kaveSelfDefenseClear.
This API is exposed in kavsdk8_sd.dll.
Removing Kaspersky drivers
Use udinstaller tool to uninstall the the drivers by following this sequence:
udinstaller --uninstall KLHKudinstaller --uninstall KLIF.