7. QKDLite Scripts API Reference¶
This section describes the various key management commands supported by the QKDLite Scripts. QKDLite Scripts uses the QKDLite Utility to perform key management operations at a higher level than QKDLite Utility.
7.1. Types of QKDLite Scripts¶
There are 3 types of scripts:
Local scripts for the user to invoke key management activities locally on one QKDLite node. Local scripts have filenames that do not begin with
replicate_norcron_.Replication scripts for the user to invoke key management activities locally on one QKDLite node (main node) and replicate these key management activities to another QKDLite node (remote node). Replication scripts have filenames that begin with
replicate_.Cron scripts for automation by job schedulers to invoke key management activities on a periodic time interval. Cron scripts can invoke local scripts or replication scripts. Cron scripts have filenames that begin with
cron_.Note
You can use
crontab -eto enter new cron jobs in user context, usecrontab -lto list currently configured cron jobs. An example to have a cron job execute every 10 minutes is as follows:*/10 * * * * cd /home/pqcee/QKDLite && /bin/bash /home/pqcee/QKDLite/cron_maintain_min_num_keys.sh NicholasKey 10 2>&1 | logger -t cron_maintain_key
7.2. Script Error Codes¶
QKDLite Scripts are designed to perform workflow execution across multiple QKDLite nodes. As such, all scripts will return a code to the caller to provide information on execution status. Scripts will return one of the following codes to the caller:
0 : Script completed successfully.
1 : Script failed at initialisation. This is likely due to improper setup of environment variables.
2 : Script failed at performing key management task. Check local syslog for specific error code caused by HSM or QKD appliance for further troubleshooting.
4 : Script failed at performing replication activity. Check both local syslog and remote syslog for specific error codes for further troubleshooting.
255 : Script failed to establish ssh connection to a remote QKDLite node.
7.3. Logging Approach¶
All scripts that perform important actions in key management workflows will log the activity to the local syslog in the same machine that QKDLite is deployed on. The format of the Syslog message will conform to the newer RFC5424 standard.
If you wish to view the messages logged to your local syslog, you can use a
cat or tail command on the syslog log file. The syslog location for
various Linux distros are as follows:
Debian and Ubuntu:
/var/log/syslogRed Hat and CentOS:
/var/log/messages
7.4. Choice of Syslog Facility and Priority Values¶
Every syslog message must define a pair of facility and priority values.
“Local use 0 (local0)” will be used in all syslog messages generated by QKDLite Scripts.
The following priority values will be used according to the type of syslog message generated by the scripts. The priority numerical codes with associated use cases are as follows:
1: “Alert: action must be taken immediately”. The scenarios for this priority level involve events that result from a failure from the HSM or from the QKD appliance. The scenarios that invoke a Priority 1 syslog message include:
HSM or QKD appliance returned an error code during the key management operation.
Connection to next QKDLite site cannot be established.
Next QKDLite site returned an error code.
6: “Informational: informational messages”. The scenarios for this priority level involve key management events that complete successfully without errors. The scenarios that invoke a Priority 6 syslog message include:
Successful completion of key management operation with no errors returned from HSM nor QKD appliance.
Successful completion of key management activity with no errors returned from next QKDLite site.
7.5. Scope of Information Captured in Logs¶
In each log, the following information will be included:
Username logged in
Key management operation attempted
(Optional) Key ID
HSM Slot number
(Optional) KME IP
(Optional) Target SAE
If the operation was unsuccessful, the additional information will be included:
Error code from HSM or QKD appliance via QKDLite Utility.
Error code from QKDLite Script.
7.6. QKDLite Script Commands¶
Note
Scripts are invoked by preceding the script name with ./, followed by
the parameters given in order of listing.
For example:
./create_key.py QKDLITE_B ETSI
Additional information about the nomenclature of parameters, devices and nodes referred to below can be found at API Terms and Definitions.
7.6.1. Local Scripts¶
create_key.py [remote_qnode] [keyID] (keyLabel)- Parameters:
 Name
Input type
Description
remote_qnodestring
Name of the node where the secret key will be shared to.
keyIDstring
The identifier for the secret key.
keyLabel(optional)string
The unique identifier for the secret key, generated by the QKD appliance.
- Description
 Invokes creation of a quantum key (supplied from a QKD appliance) in the main node and replication of the quantum key to a remote node.
Supplying
remote_qnodeandkeyIDarguments will invoke QKD KME (associated with the QKDLite main node) to perform QKD protocol with a remote QKD SAE (associated with theremote_qnodeQKDLite remote node) and create a new quantum key with a newkeyLabel. This new quantum key will only be inserted into the HSM associated with the QKDLite node. It will have identifierskeyIDandkeyLabel.Supplying all
remote_qnode,keyIDandkeyLabelarguments will invoke QKD KME (associated with the QKDLite node) to retrieve a previously-generated quantum key associated withkeyLabel. This quantum key will be inserted into HSM associated with the QKDLite node. It will have identifierskeyIDandkeyLabel.- Output
 If successful, the output returns in the following format:
<keyID>,<generated keyLabel of new key> 0
If unsuccessful due to incorrect input, there will be no output, indicating no key created.
If unsuccessful due to QKD2HSM script failure, the non-zero error code from the QKD2HSM script will be returned.
create_keys_qrng.py [keyID] (key_count)- Parameters:
 Name
Input type
Description
keyIDstring
The identifier for the secret key.
key_count(Optional)integer
The number of keys to be created.
- Description
 Create one or more quantum keys (with entropy from QRNG) locally in main node with an associated
keyIDidentifier.Supplying a
keyIDstring argument andkey_countinteger argument will createkey_countquantum keys, derived from seed pool with QRNG entropy, associated withkeyIDidentifier in main QKDLite node. Each key will be given a new uniquekeyLabelidentifier. Leaving outkey_countargument will default tokey_count=1.- Output
 If successful, the output returns in the following format:
<keyID>,<generated keyLabel of new key> 0
If unsuccessful due to incorrect input, there will be no output, indicating no key created.
If unsuccessful due to QKD2HSM script failure, the non-zero error code from the QKD2HSM script will be returned.
delete_keys.py [keyID] (keyLabel)- Parameters:
 Name
Input type
Description
keyIDstring
The identifier for the secret key.
keyLabel(optional)string
The unique identifier for the secret key, generated by the QKD appliance.
- Description
 Invokes deletion of the quantum key(s) with the associated
keyIDandkeyLabelat the QKDLite node.Supplying a
keyIDargument will delete all keys associated with the providedkeyIDat the QKDLite node.Supplying both
keyIDandkeyLabelarguments will delete one key associated with thekeyIDandkeyLabelat the QKDLite node.- Output
 If one or more keys were deleted successfully, the output returns in the following format:
<keyID_1>,<keyLabel_1> <keyID_2>,<keyLabel_2> ... <keyID_N>,<keyLabel_N> 0
If no keys of supplied
keyIDare found, the output will return:0
If unsuccessful due to incorrect input, there will be no output, indicating no key(s) deleted.
If unsuccessful due to QKD2HSM script failure, the non-zero error code from the QKD2HSM script will be returned.
list_keys.py (keyID)- Parameters:
 Name
Input type
Description
keyID(optional)string
The identifier for the secret key.
- Description
 Generates a list of all keys at the QKDLite node. Note that this script is assumed to be executed locally and remotely via cron jobs, so the output is designed to facilitate processing by scripts rather than by a human operator.
Supplying no arguments will invoke a list of all quantum key identifiers at the QKDLite node.
Supplying a
keyIDargument will invoke a list of quantum key identifiers with a matchingkeyIDvalue at the QKDLite node.- Output
 If successful and more than one key is listed, the output returns in the following format:
<keyID_1>,<keyLabel_1> <keyID_2>,<keyLabel_2> ... <keyID_N>,<keyLabel_N> 0
If there are no keys in the QKDLite node or no keys match the given
keyID, the output will return:0
If unsuccessful due to incorrect input, there will be no output, indicating no keys listed.
If unsuccessful due to QKD2HSM script failure, the non-zero error code from the QKD2HSM script will be returned.
7.6.2. Replication Scripts¶
replicate_create_key.py [remote_qnode] [keyID]- Parameters:
 Name
Input type
Description
remote_qnodestring
Name of the node where the secret key will be replicated to.
keyIDstring
The identifier for the secret key.
- Description
 Invokes creation of one quantum key at the QKDLite node and replicate this key at the indicated QKDLite remote node.
Supplying
remote_qnodeandkeyIDarguments will invoke creation of a quantum key in the QKDLite node. This secret key will be replicated to the indicated remote QKDLite noderemote_qnodeand inserted into its connected HSM with the associatedkeyLabel.Note that if local creation is successful but replication is unsuccessful, the newly created quantum key will be deleted locally.
- Output
 If successful, the output returns in the following format:
Creating key locally on <QKDLite main node>... <keyID>,<keyLabel> Replicating key on QKDLite remote node <QKDLite remote node>... <keyID>,<keyLabel>
If local key creation is successful but replication is unsuccessful, the output will be as follows:
Creating key locally on <QKDLite main node>... <keyID>,<keyLabel> Attempt to undo key creation on localhost QKDLite node by deleting key... Deleting keys locally on <remote QKDLite node>... <keyID>,<keyLabel>
If unsuccessful due to an SSH error, an error message will indicate so.
If unsuccessful due to incorrect input or other reasons, there will be no output, indicating no key replicated.
replicate_create_keys_qrng.py [remote_qnodes] [keyID] (key_count)- Parameters:
 Name
Input type
Description
remote_qnodesstring
Names of the nodes where the secret key will be replicated to.
keyIDstring
The identifier for the secret key.
key_count(Optional)integer
The number of keys to be created.
- Description
 Create one or more quantum keys (with entropy from QRNG) locally in main node with an associated
keyIDidentifier. These created quantum keys are subsequently replicated to the specified list of remote nodes.Supplying a list of names of remote QKDLite nodes
remote_qnodes,keyIDstring argument, andkey_countinteger argument will createkey_countquantum keys (derived from QRNG entropy) associated withkeyIDidentifier in main node and replicate to target remote nodes. Each key will have a new uniquekeyLabelidentifier. The argumentkey_countis optional. If none is provided, a default value of 1 will be used.Note that if local creation is successful but replication is unsuccessful, the newly created quantum key will be deleted locally in main node.
- Output
 If successful, the output returns in the following format:
Creating QRNG key(s) locally on <QKDLite main node>... <keyID>,<keyLabel> Exporting QRNG key(s) locally on <QKDLite main node>... <keyID>,<keyLabel>,<keyData> Importing key(s) on remote QKDLite node <remote QKDLite node>... <keyID>,<keyLabel>
If local key creation is successful but replication is unsuccessful, the output will be as follows:
Creating QRNG key(s) locally on <QKDLite main node>... <keyID>,<keyLabel> Exporting QRNG key(s) locally on <QKDLite main node>... <keyID>,<keyLabel>,<keyData> Attempt to undo key(s) creation on localhost QKDLite node by deleting key(s)... Deleting keys locally on <remote QKDLite node>... <keyID>,<keyLabel>
If unsuccessful due to an SSH error, an error message will indicate so.
If unsuccessful due to incorrect input or other reasons, there will be no output, indicating no key replicated.
replicate_delete_keys.py [remote_qnode] [keyID] (keyLabel) (waitTime)- Parameters:
 Name
Input type
Description
remote_qnodestring
Name of the node where the secret key(s) will be deleted.
keyIDstring
The identifier for the secret key(s).
keyLabel(optional)string
The unique identifier for the secret key, generated by the QKD appliance.
waitTime(optional)int
Time in seconds that this script will delay its execution by.
- Description
 Deletes the specified quantum keys both at the QKDLite main node and at the QKDLite remote node.
Supplying
remote_qnodeandkeyIDarguments will delete all keys associated with the providedkeyIDboth at the QKDLite main node and at the QKDLite remote noderemote_qnode. This command executes immediately.Supplying
remote_qnode,keyIDandkeyLabelarguments will delete one key associated with thiskeyIDandkeyLabelboth at the QKDLite main node and QKDLite remote noderemote_qnode. This command executes immediately.Supplying a
waitTimeargument in addition to the above will delete the specified keys, but will delay execution of the deletion after a time delay ofwaitTimeseconds.- Output
 If successful, the output returns in the following format:
Deleting keys on remote QKDLite node QKDLITE_B... <keyID_1>,<keyLabel_1> <keyID_2>,<keyLabel_2> ... <keyID_N>,<keyLabel_N> Deleting keys locally on QKDLITE_A... <keyID_1>,<keyLabel_1> <keyID_2>,<keyLabel_2> ... <keyID_N>,<keyLabel_N>
If unsuccessful due to incorrect input, there will be no output, indicating no key was deleted.
7.6.3. Cron Scripts¶
cron_maintain_min_num_keys.py [keyID] [number_of_keys] [remote_qnode]- Parameters:
 Name
Input type
Description
keyIDstring
The identifier for the secret key.
number_of_keysint
The quantity of keys that are being checked for in the HSM. If this quantity is not met, keys will be generated until this number is met.
remote_qnodestring
Name of the node where secret key(s) will be added if necessary.
- Description
 Checks locally how many keys of given
keyIDexist. If it is less than the givennumber_of_keys, it adds keys locally and remotely at the given remote QKDLite node until the given minimum quantity of keys exist locally.Supplying
keyID,number_of_keysandremote_qnodearguments invoke checking the number of keys with the identifierkeyIDat the QKDLite node. If it is less than a given minimum number of keysnumber_of_keys, quantum keys shared with the QKDLite remote noderemote_qnodewill be generated until the minimum number of keys is met.- Output
 If successful and there are sufficient keys, the output returns in the following format:
Counting keys locally in HSM Slot <slot number> with keyID =<keyID>... SUCCESS: Found <#keys> key(s). Require minimum <number_of_keys> keys, and found <#keys> keys in localhost QKDLite node... No new keys needed, sufficient keys found in localhost HSM. Return Script Error Code = 0.
If successful and there are insufficient keys, the output returns in the following format:
Counting keys locally in HSM Slot <slot number> with keyID =<keyID>... SUCCESS: Found <#keys> key(s). Require minimum <number_of_keys> keys, and found <#keys> keys in localhost QKDLite node... Insufficient keys found in localhost HSM. Attempting to create <#keys-number_of_keys> keys locally with keyID=<keyID> and replicate remotely to node <remote_qnode> with keyID=<keyID>... SUCCESS: created key #1 (of <#keys-number_of_keys>) locally and replicate remotely. SUCCESS: created key #2 (of <#keys-number_of_keys>) locally and replicate remotely. ... SUCCESS: Successfully created <#keys-number_of_keys> key(s) locally and replicate remotely. Return Script Error Code = 0.
If unsuccessful due failure in count key operation, the output returns in the following format:
Counting keys locally in HSM Slot <slot number> with keyID =<keyID>... FAILED: QKD2HSM Return Code = <qkd2hsm_returncode>. Failed to get key count locally. Return Script Error Code = 2.
If unsuccessful due to a connectivity error, the output returns in the following format:
Counting keys locally in HSM Slot <slot number> with keyID =<keyID>... SUCCESS: Found <#keys> key(s). Require minimum <number_of_keys> keys, and found <#keys> keys in localhost QKDLite node... Insufficient keys found in localhost HSM. Attempting to create <#keys-number_of_keys> keys locally with keyID=<keyID> and replicate remotely to node <remote_qnode> with keyID=<keyID>... FAILED: Script Error Code = <qkd2hsm_returncode>. Failed to create key #1 (of <#keys-number_of_keys>) locally and replicate remotely. FAILED: Script Error Code = <qkd2hsm_returncode>. Failed to create key #2 (of <#keys-number_of_keys>) locally and replicate remotely. ... FAILED: Failed to create <#keys-number_of_keys> key(s) locally and replicate remotely. Return Script Error Code = 4.
If unsuccessful due to incorrect input, there will be no output, indicating no key was replicated.
cron_cleanup_lost_keys.py [remote_qnode] [keyID] [waitTime]- Parameters:
 Name
Input type
Description
remote_qnodestring
Name of the node where secret key(s) will be checked for and deleted if necessary.
keyIDstring
The identifier for the secret key(s).
waitTimeint
Time in seconds that this script will delay its execution by.
- Description
 Checks for keys that either exist only locally or only remotely (but not on both nodes) associated with the given keyID. If found, deletes such keys.
Supplying
remote_qnode,keyIDandwaitTimearguments invoke checking for any keys with the identifierkeyIDat the QKDLite main node and at the QKDLite remote node. If such keys exist on only one of the nodes but not both, the script will spawn “delete key” subprocesses that will sleep for the givenwaitTimein seconds then activate to delete thekeyIDand relatedkeyLabelof the “lost” key. ThewaitTimedelay minimises deleting the key during the transitional period where the first key has been consumed and the second key has yet to be consumed by external SAE.- Output
 If successful and there are no keys needing deletion, the output returns in the following format:
Get list of keys locally in HSM Slot <slot_number> with keyID = <keyID>... SUCCESS: List contains <#> key(s). Get list of keys in remote QKDLite node <remote_qnode> with keyID = <keyID>... SUCCESS: List contains <#> key(s). No "lost" keys found.' Return Script Error Code = 0.
If successful and there are keys that need to be deleted, the output returns in the following format:
Get list of keys locally in HSM Slot <slot_number> with keyID = <keyID>... SUCCESS: List contains <#> key(s). Get list of keys in remote QKDLite node <remote_qnode> with keyID = <keyID>... SUCCESS: List contains <#> key(s). No "lost" keys found.' Return Script Error Code = 0. Found <#> "lost" keys between the QKDLite nodes. Attempting to delete "lost" keys... Created subprocess to delete key with keyID = <keyID> and keyLabel = <keyLabel> after delay of <waitTime> seconds. Created subprocess to delete key with keyID = <keyID> and keyLabel = <keyLabel> after delay of <waitTime> seconds. ...
If unsuccessful due failure in count key operation locally or remotely, the output returns in the following format:
Get list of keys locally in HSM Slot <slot_number> with keyID = <keyID>... FAILED: QKD2HSM Return Code = <error_code>. Failed to get key list locally. Return Script Error Code = 4.
Get list of keys locally in HSM Slot <slot_number> with keyID = <keyID>... SUCCESS: List contains <#> key(s). Get list of keys in remote QKDLite node <remote_qnode> with keyID = <keyID>... FAILED: QKDLite Script Return Code = <error_code>. Failed to get key list from remote QKDLite node. Return Script Error Code = 4.
If unsuccessful due to incorrect input, there will be no output, indicating no key(s) were deleted.