Getting started with Self Defense in KAV SDK

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:

  1. Digitally sign your application installer and processes to be protected by Self Defense.
    1. Obtain a signed public encryption key from your Technical Account Manager (TAM).

      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.

    2. Use custom private encryption key to sign processes that you want to protect using Self Defense technology.

Deploying Self Defense library

  1. Load the Self Defense protection library (hereinafter also self-protection library).
  2. Register your public encryption key in system.
  3. Install Kaspersky drivers.
  4. Set your installer applications.
  5. Prepare access rules for self-protection library in your installer, see section Specifying access rules.

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:

  1. Generate the key pair.

    Use kavsigner tool to create the keys. To locate the tool, open the Tools folder in the SDK program folder.

  2. Digitally sign your public key with the private key of Kaspersky Lab

    Send your public key to your TAM.

  3. Digitally sign all the executable files of your applications using your custom private key.
  4. Register your public key in Windows by calling 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:

  1. udinstaller --install KLHK
  2. udinstaller --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,

  1. Prepare access rules using provided Configuration structure of access rules.
  2. Call 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:

  1. Call 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:

To enable Self Defense from your application,

  1. Call 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:

  1. Sign your installer application by using the private keys for the following public keys:
    • The expired key used during installation of your application
    • The new key that you want to register in system.
  2. After the function returns, restart the operating system to finish the update operation.

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:

  1. Remove your application.
  2. Install the application again and set the new access rules as described in "Step 5. Configuring Self Defense access rules".

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:

  1. Load the Self Defense protection library as described in Step 1 of deployment procedure.
  2. Clear Self Defense traces off the system.
  3. Remove Kaspersky drivers following the standard procedure, see "Drivers" section.
  4. Unload the Self Defense library as described in Step 6 of deployment procedure.

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:

  1. udinstaller --uninstall KLHK
  2. udinstaller --uninstall KLIF.

Page top