# TSIG Keys Management

CWMTsigKeys is a widget for CWM that can be used for management of TSIG keys (that are used for DDNS authentication between DNS and DHCP servers). It handles all needed functionality.

Additionally, the module provides functions that can be very useful for modules that manipulate TSIG keys.

To create the service start widget, use the `CWMTsigKeys::CreateWidget` function. As parameter, it takes a map with settings needed to create the widget and handle settings on it, returns a map with the widget for CWM. This map can be used the same way as maps for other widgets.

Usage of the Tsig Keys Management widget

            global define void SetKeysInfo (map<string,any>) {...}
            global define map<string,any> GetKeysInfo () {...}

            map<string,any> widget = CWMTsigKeys::CreateWidget ($[
                "get_keys_info" : DhcpServer::GetKeysInfo,
                "set_keys_info" : DhcpServer::SetKeysInfo,
            ]);

## Reading and storing TSIG Keys

The parameters for service starting are following:

- `"get_keys_info"` is reference to a function with no parameter returning a map with following keys:

  - `"removed_files"` lists of strings, file names of files with TSIG keys that were removed during previous runs of the dialog (just copy of the same value that passed to "set_keys_info". May be missing.

  - `"new_files"` lists of strings, file names of files with TSIG keys that were added during previous runs of the dialog (just copy of the same value that passed to "set_keys_info". May be missing.

  - `"tsig_keys"` is a list of maps of TSIG keys. Each map is of type string->string, with keys "key" and "filename" and values key ID resp. file name of the file with the key.

  - `"key_files"` is an alternative to "tsig_keys". Is used only if "tsig_keys" is missing. Contains a list of strings, file names of files with TSIG keys.

  It is mandatory. "key_files" is used only if "tsig_keys" is missing.

- `"set_keys_info"` is reference to a function with one map parameter containing information about TSIG keys and return type viod. The map is of type string->any. should be started at boot and return type void. It is mandatory.

  The map contains all keys mentioned in "get_keys_info" odcumentation.

## Other stuff

Other supported parameters are following:

- `"list_used_keys"` is a reference to a function of type `list<string>()` returning a list of at the moment used TSIG keys. The list is used to prevent used TSIG keys from being deleted. If not present, all keys may get deleted.

- `"help"` the complete help for the widget. If it is not present, generic help is used (button labels are patched into the help texts.

## Notes on the widget

If "removed_files" or "new_files" is not present in output of "get_keys_info", then in "set_keys_info" the value contains keys that were added/removed during the one run of the dialog. Otherwise, added/removed keys are added to the appropriate variables. The widget takes care that no key is in both of the variables.

If keys are specified via "key_files" and some of the files don't contain any key, these files aren't specified in the variable in the "set__keys_info". Such files aren't mentioned in "removed_files".

## Misc. functions

The CWMTsigKeys module also offers several functions tightly boud to the TSIG keys. Following functions are available:

- `list<string> AnalyzeTSIGKeyFile (string filename)` Analyzes the file and return list of all TSIG Key IDs found in the file.

- `list<string> Files2Keys (list<string> filenames)` Analyzes all of the files and returns a list of all TSIG key IDs fount in the files.

- `list<map<string,string>> Files2KeyMaps (list<string> filenames)` Analyzes the files and returns a list of the maps of all TSIG keys found in the files. A TSIG Key map (string->string) contains keys "key" and "filename" with values Key ID resp. file name of the file.