Skip to main content
Use a Yubico YubiHSM 2 on the Lager Box to generate keys, import keys and sign data. The private keys stay in the HSM.

Import

Methods

Every method marked Yes takes two keyword-only arguments: auth_key_id=1 and password. The password is required. The driver does not store it, and it is never put in an exception message.

Method Reference

Net.get(name, type=NetType.Hsm)

Get an HSM net by name.
Returns: YubiHsm2 Each call opens the device, runs one operation and closes the device again. The driver does not hold the USB device between calls.

info()

Returns: dict with firmware, serial, log_used, log_size, part_number and algorithms

generate_key(object_id, algorithm, label='', domains=(1,), capabilities=None, *, auth_key_id=1, password)

Generate an asymmetric key in the HSM.
Returns: dict with id and public_key_pem RSA key generation can take several minutes. The call waits up to 300 seconds for an RSA key.

sign(object_id, data, mechanism, *, auth_key_id=1, password)

Sign data with the stored key.
mechanism is one of ecdsa-sha256, ecdsa-sha384, ecdsa-sha512, eddsa, rsa-pkcs1-sha256, rsa-pkcs1-sha384, rsa-pkcs1-sha512, rsa-pss-sha256, rsa-pss-sha384 or rsa-pss-sha512. Returns: bytes - The signature

import_key(object_id, private_key_pem, label='', domains=(1,), capabilities=None, *, auth_key_id=1, password)

Import an unencrypted PEM private key. Returns: int - The object ID

list_objects(type=None, label=None, *, auth_key_id=1, password)

Returns: list[dict], each with id, type, label, algorithm, domains, capabilities, size and sequence. get_object_info() returns one such dict. type and object_type take asymmetric-key, authentication-key, opaque, wrap-key, hmac-key, template or otp-aead-key.

reset(*, auth_key_id=1, password)

Factory-reset the HSM and wait up to 10 seconds for it to come back. This deletes every key on the HSM.

session(*, auth_key_id=1, password)

A context manager that yields a logged-in session of the yubihsm package, for an operation that this driver does not wrap.

Errors

Notes

  • Read the password from the environment or a file, not from the script source
  • The CLI equivalent is lager hsm
  • The Rust equivalent is in the Rust HSM reference