Expand description
§NetHSM
A high-level library to interact with the API of a Nitrokey NetHSM.
The NetHSM is a hardware appliance, that serves as secure store for cryptographic keys. With the help of a REST API it is possible to communicate with the device (as well as the official nethsm container) for setup and various cryptographic actions.
The nethsm-sdk-rs library is auto-generated using openapi-generator. This leads to a broad API surface with sparse documentation, that this crate attempts to rectify with the help of a central struct used for authentication setup and communication.
As this crate is a wrapper around [nethsm_sdk_rs] it covers all available actions from provisioning, over key and user management to backup and restore.
The NetHSM provides dedicated user management based on a role system (see UserRole) which can be used to separate concerns.
Each user has exactly one role.
With the help of a namespace concept, it is possible to segregate users and their keys into secluded groups.
Notably, this introduces R-Administrators (system-wide users in the Administrator role), which have access to all system-wide actions, but can not modify users and keys in a namespace and N-Administrators (namespace users in the Administrator role), which have access only to actions towards users and keys in their own namespace.
Namespace users in the Operator role only have access to keys in their own namespace, while system-wide users only have access to system-wide keys.
The cryptographic key material on the NetHSM can be assigned to one or several tags.
Users in the Operator role can be assigned to the same tags to gain access to the respective keys.
Using the central NetHsm struct it is possible to establish a TLS connection for multiple users and all available operations.
TLS validation can be configured based on a variant of the ConnectionSecurity enum:
ConnectionSecurity::Unsafe: The host certificate is not validated.ConnectionSecurity::Fingerprints: The host certificate is validated based on configurable fingerprints.ConnectionSecurity::Native: The host certificate is validated using the native Operating System trust store.
§Documentation
- https://signstar.archlinux.page/rustdoc/nethsm/ for development version of the crate
- https://docs.rs/nethsm/latest/nethsm/ for released versions of the crate
Apart from the crate specific documentation it is very recommended to read the canonical upstream documentation as well: https://docs.nitrokey.com/nethsm/
§Testing
This library is integration tested against Nitrokey’s official nethsm container. To run these long running tests a podman installation is required. The tests handle the creation and teardown of containers as needed.
cargo test --all -- --ignored§Re-exports
This crate relies on a set of external crates in its own public API.
Re-exports ensure that the respective dependencies do not have to be relied upon directly by consumers:
chrono::DateTimechrono::Utcnethsm_sdk_rs::models::DistinguishedNamenethsm_sdk_rs::models::InfoDatanethsm_sdk_rs::models::LoggingConfignethsm_sdk_rs::models::NetworkConfignethsm_sdk_rs::models::PublicKeynethsm_sdk_rs::models::SystemInfonethsm_sdk_rs::models::SystemStatenethsm_sdk_rs::models::SystemUpdateDatanethsm_sdk_rs::models::UserData
§Examples
Establish a connection with a Nitrokey NetHSM and manage credentials:
use nethsm::{Connection, ConnectionSecurity, Credentials, NetHsm, Passphrase};
// Create a new connection to a NetHSM at "https://example.org" using admin credentials
let nethsm = NetHsm::new(
Connection::new(
"https://example.org/api/v1".try_into()?,
ConnectionSecurity::Unsafe,
),
Some(Credentials::new("admin".parse()?, Some(Passphrase::new("passphrase".to_string())))),
None,
None,
)?;
// Connections can be initialized without any credentials and more than one can be provided later on
let nethsm = NetHsm::new(
Connection::new(
"https://example.org/api/v1".try_into()?,
ConnectionSecurity::Unsafe,
),
None,
None,
None,
)?;
nethsm.add_credentials(Credentials::new("admin".parse()?, Some(Passphrase::new("passphrase".to_string()))));
nethsm.add_credentials(Credentials::new("user1".parse()?, Some(Passphrase::new("other_passphrase".to_string()))));
// A set of credentials must be used before establishing a connection with the configured NetHSM
nethsm.use_credentials(&"user1".parse()?)?;§Features
test-helpersenables thesignstar_config::testmodule which provides utilities for test setups that are also useful for other crates._nethsm-integration-testenables tests that requirepodmanfor starting test dependencies in containers.
§Contributing
Please refer to the contributing guidelines to learn how to contribute to this project.
§License
This project may be used under the terms of the Apache-2.0 or MIT license.
Changes to this project - unless stated otherwise - automatically fall under the terms of both of the aforementioned licenses.
Modules§
Structs§
- Container
- A running container
- NetHsm
Image - An image of NetHSM used to create a running container.
Statics§
- ADMIN_
USER_ ID - Identifier for an admin user.
- ADMIN_
USER_ PASSPHRASE - Sample admin passphrase.
- BACKUP_
USER_ ID - User ID for backup purposes.
- BACKUP_
USER_ PASSPHRASE - Sample passphrase for the backup user.
- BACKUP_
USER_ REAL_ NAME - Real name for the backup user.
- DEFAULT_
AES_ BITS - Default size for the AES key in bits.
- DEFAULT_
KEY_ ID - Default ID for a key.
- DEFAULT_
OPERATOR_ USER_ ID - Default user ID for an operator.
- DEFAULT_
OPERATOR_ USER_ PASSPHRASE - Sample operator passphrase.
- DEFAULT_
OPERATOR_ USER_ REAL_ NAME - Default real name for an operator.
- DEFAULT_
RSA_ BITS - Default size of the RSA key in bits.
- DEFAULT_
TAG - Default tag.
- ENC_
KEY_ ID - Default ID for the encryption key.
- ENC_
OPERATOR_ USER_ ID - User ID for the operator user who can access the encryption key.
- ENC_
OPERATOR_ USER_ PASSPHRASE - Sample passphrase for the operator user who can access the encryption key.
- ENC_
OPERATOR_ USER_ REAL_ NAME - Real name for the operator user who can access the encryption key.
- ENC_TAG
- Default tag for the encryption key.
- METRICS_
USER_ ID - User ID for the metrics user.
- METRICS_
USER_ PASSPHRASE - Sample passphrase for the metrics user.
- METRICS_
USER_ REAL_ NAME - Real name for the metrics user.
- NAMESPAC
E1 - Sample namespace.
- NAMESPAC
E2 - Second namespace.
- NAMESPAC
E1_ ADMIN_ REAL_ NAME - Real name for
namespace1’s administrator. - NAMESPAC
E1_ ADMIN_ USER_ ID - Administrator’s user ID for
namespace1. - NAMESPAC
E1_ ADMIN_ USER_ PASSPHRASE - Sample passphrase for
namespace1’s administrator. - NAMESPAC
E1_ OPERATOR_ REAL_ NAME - Real name of an operator in
namespace1. - NAMESPAC
E1_ OPERATOR_ USER_ ID - User ID of an operator in
namespace1. - NAMESPAC
E1_ OPERATOR_ USER_ PASSPHRASE - Sample passphrase of an operator in
namespace1. - NAMESPAC
E2_ ADMIN_ REAL_ NAME - Real name for
namespace2’s administrator. - NAMESPAC
E2_ ADMIN_ USER_ ID - Administrator’s user ID for
namespace2. - NAMESPAC
E2_ ADMIN_ USER_ PASSPHRASE - Sample passphrase for
namespace2’s administrator. - NAMESPAC
E2_ OPERATOR_ REAL_ NAME - Real name of an operator in
namespace2. - NAMESPAC
E2_ OPERATOR_ USER_ ID - User ID of an operator in
namespace2. - NAMESPAC
E2_ OPERATOR_ USER_ PASSPHRASE - Sample passphrase of an operator in
namespace2. - OTHER_
KEY_ ID - Default ID for a different key.
- OTHER_
OPERATOR_ USER_ ID - User ID for a different user.
- OTHER_
OPERATOR_ USER_ PASSPHRASE - Sample passphrase for a different user.
- OTHER_
OPERATOR_ USER_ REAL_ NAME - Real name for a different user.
- OTHER_
TAG - Different tag.
- UNLOCK_
PASSPHRASE - Sample unlock passphrase.
Functions§
- add_
keys_ 🔒to_ nethsm - add_
users_ 🔒to_ nethsm - create_
container - Creates and starts a new NetHSM container.
- create_
nethsm - Creates a new NetHsm object configured with administrator credentials.
- nethsm_
with_ keys - Adds users and keys to an already provisioned NetHSM container.
- nethsm_
with_ users - Creates a new NetHsm object pointing at a NetHSM container with users.
- provision_
nethsm 🔒 - provisioned_
nethsm - Creates a new NetHsm object pointing at a provisioned NetHSM container.
- unprovisioned_
nethsm - Returns a new NetHsm object pointing to an unprovisioned NetHSM.
- update_
file - Downloads an update file if it’s not already present.