.. hsm2-sdk-tools-libraries.rst .. _hsm2-sdk-tools-libraries-label: =================================== YubiHSM 2 SDK Tools And Libraries =================================== .. _hsm2-setup-tool-label: YubiHSM 2 Setup Tool ===================== The SDK ships with a tool called `yubihsm-setup `_ that helps with setting up a device for specific use cases. The tool assumes familiarity with the key concepts of YubiHSM such as :ref:`hsm2-concepts-domain-label`, :ref:`hsm2-concepts-capability-label` and :ref:`hsm2-concepts-objectid-label`. It currently supports the following: * setup for KSP/ADCS and EJBCA; * restoring a previous configuration * resetting the device to factory defaults * exporting all existing objects The tool is based around the concept of secret-sharing. When setting up Objects, those are exported with a freshly created Wrap Key. The key is never stored on disk, but rather it is printed on the screen as shares. The key concepts here are: * The number of shares, which is the number of parts the key should be divided into. * The security threshold, which is the minimum number of shares required to reconstruct the Wrap Key. Besides splitting the Wrap Key into shares, the tool (by default) also exports under wrap all the newly created objects and saves them in the current directory. This can be used at a later time to “clone” or recover a device. This operation can be performed either with ``yubihsm-setup`` or manually if the Wrap Key is known. By default, the Authentication Key used to establish a Session with the device is also normally deleted at the end of the process. Default behavior can be altered with command line options. For more information, consult the tool’s help. Setup for EJBCA ---------------- When setting up the device for use by EJBCA, the setup tool will also generate an asymmetric keypair and an X509 certificate suitable for use as a CA key. The setup tool can be re-run as many times as the number of asymmetric keys to be generated since each run will produce only one keypair and one corresponding X509 certificate. .. Note:: Using the ``--no-new-authkey`` flag will prevent generation of a new Wrap Key and a new Authentication Key. How It Works ------------- For the JAVA implementation, a keypair can be used to perform PKCS#11 operations only if the key and its corresponding X509 certificate are stored under the same ID on the device (the value of their CKA_ID attributes is the same). To store them under the same ID, run the YubiHSM 2 Setup tool with the ``ejbca`` subcommand: 1. Generate an Asymmetric Key on the YubiHSM 2. 2. Generate an attestation certificate for the asymmetric key and import it into the YubiHSM 2 under the same ID as the Asymmetric Key. The attestation certificate stored on the YubiHSM 2 is, in fact, only a placeholder certificate for the public key. It is never used by EJBCA because EJBCA stores the CAs’ certificates in a dedicated database. .. _hsm2-shell-label: YubiHSM Shell ================ The `yubihsm-shell `_ is the administrative and testing tool you can use to interact with and configure the YubiHSM 2 device. All the commands supported by YubiHSM 2 :ref:`hsm2-cmd-reference-label` can be issued to YubiHSM 2 using YubiHSM 2 Shell. The Shell can be invoked in two different ways: interactively, or as a command line tool useful for scripting. Additional information on the various commands can be obtained with the ``help`` command in interactive mode or by referring to the ``--help`` argument for the command line mode. Examples of commands can also be found in the :ref:`hsm2-cmd-reference-label` reference. YubiHSM Shell Command Syntax ------------------------------- Commands and subcommands require specific arguments to work. The Shell will return an error message if the command syntax is incorrect, pointing at the first invalid argument. Arguments have different types. In interactive mode pre-defined values for command types can be tab-completed (Tab Completion does not work on Windows). Command arguments are explained in the table below. .. table:: +-----+-----------------+----------------------------------------------------+ | Arg | Type | Description | +=====+=================+====================================================+ | A | Algorithm | An algorithm in string form (ex: ecp256) | +-----+-----------------+----------------------------------------------------+ | B | Byte | A generic (hex or dec) 8-bit unsigned number | +-----+-----------------+----------------------------------------------------+ | C | capabilities || A list of Capabilities in either form: | | | || hex (ex: 0xffffffffffffffff) or | | | || string (ex: sign-pkcs,sign-pss, get-log-entries) | +-----+-----------------+----------------------------------------------------+ | D | Domains || A list of Domains, either in hex (ex: 0xffff) or | | | || string form (ex: 3,5,14) | +-----+-----------------+----------------------------------------------------+ | I | Format | A format specifier in string form (ex: base64) | +-----+-----------------+----------------------------------------------------+ | I | input data | Input data, generally defaults to standard input | +-----+-----------------+----------------------------------------------------+ | U | Number | A generic (hex or dec) unsigned number | +-----+-----------------+----------------------------------------------------+ | O | Option || A device-global option in string form | | | || (ex: force-audit) | +-----+-----------------+----------------------------------------------------+ | F | output filename || Output file name, generally defaults to standard | | | || output | +-----+-----------------+----------------------------------------------------+ | E | Session | The ID of an already-established Session | +-----+-----------------+----------------------------------------------------+ | S | String || A generic string (use quotes for strings | | | || including white spaces) | +-----+-----------------+----------------------------------------------------+ | T | Type | An Object Type in string form (ex: Asymmetric) | +-----+-----------------+----------------------------------------------------+ | W | Word | A generic (hex or dec) 16-bit unsigned number | +-----+-----------------+----------------------------------------------------+ Different commands have different default formats. These can be listed by invoking ``help`` on a specific command. For example, the ``help sign`` will display the following message: .. code-block:: bash pss Sign data using RSASSA-PSS (default input format: binary) e:session,w:key_id,a:algorithm,i:data=-,F:out=- As can be seen, the input format is binary. Additionally, arguments to a command that have ``=-`` after their type and name (like ``i:data`` and ``F:out`` in the example above), use the standard input or standard output by default for reading data. Different levels of debug output can be enabled by using the ``-v`` flag in command line mode, or by issuing the ``debug LEVEL`` command in interactive mode, where LEVEL is one of ``all``, ``crypto``, ``error``, ``info``, ``intermediate``, ``none``, or ``raw``. The following is a list of supported yubihsm-shell commands and their formats. **Blink Device --** Blinks the LED of the device to identify it. *Interactive mode* .. code-block:: bash $ blink *Command line mode* .. code-block:: bash $ yubihsm-shell -a blink-device [--duration ] **Change Authentication Key --** Replaces the Authentication Key used to establish the current Session. *Interactive mode* .. code-block:: bash $ change authkey **Close Session --** Closes the current session and releases it for re-use. *Interactive mode* .. code-block:: bash $ session close **Create Otp Aead --** Creates a Yubico OTP AEAD using the provided data. *Interactive mode* .. code-block:: bash $ otp aead_create **Decrypt AES CBC --** Decrypt data in AES CBC mode. *Interactive mode* .. code-block:: bash $ decrypt aescbc *Command line mode* .. code-block:: bash $ yubihsm-shell -a decrypt-aescbc -i --iv --in **Decrypt AES ECB --** Decrypt data in AES ECB mode. *Interactive mode* .. code-block:: bash $ decrypt aesecb *Command line mode* .. code-block:: bash $ yubihsm-shell -a decrypt-aesecb -i --in **Decrypt Oaep --** Decrypts data encrypted with RSA-OAEP. *Interactive mode* .. code-block:: bash $ decrypt oaep *Command line mode* .. code-block:: bash $ yubihsm-shell –a decrypt-oaep -i -A [--in -l ] **Decrypt Otp --** Decrypts a Yubico OTP with an AEAD and returns counters and timer information (default input format in binary). *Interactive mode* .. code-block:: bash $ otp decrypt **Decrypt Pkcs1 --** Decrypts data encrypted with RSA-PKCS#1v1.5. *Interactive mode* .. code-block:: bash decrypt pkcs1v1_5 data=->`` *Command line mode* .. code-block:: bash $ yubihsm-shell -a decrypt-pkcs1v15 -i [--in ] **Delete Object --** Deletes an object in the device. *Interactive mode* .. code-block:: bash $ delete *Command line mode* .. code-block:: bash $ yubihsm-shell -a delete-object -i -t `` **Derive Ecdh --** Performs an ECDH key exchange with the private key in the device. *Interactive mode* .. code-block:: bash $ derive ecdh *Command line mode* .. code-block:: bash $ yubihsm-shell -a derive-ecdh -i [--in ] **Encrypt AES CBC --** Encrypt data in AES CBC mode. *Interactive mode* .. code-block:: bash $ encrypt aescbc *Command line mode* .. code-block:: bash $ yubihsm-shell -a encrypt-aescbc -i --iv --in **Encrypt AES ECB --** Encrypt data in AES ECB mode. *Interactive mode* .. code-block:: bash $ encrypt aesecb *Command line mode* .. code-block:: bash $ yubihsm-shell -a encrypt-aesecb -i --in **Export Wrapped --** Retrieves an object under wrap from the device. The Object is encrypted using AES-CCM with a 16 bytes MAC and a 13 bytes nonce. *Interactive mode* .. code-block:: bash $ get wrapped *Command line mode* .. code-block:: bash $ yubihsm-shell -a get-wrapped --wrap-id -t -i [--out ] **Generate Asymmetric Key --** Generates an Asymmetric Key in the device. *Interactive mode* .. code-block:: bash $ generate asymmetric session>