Private key material on disk
SoftHSM stores all token objects — including private keys — in thedirectories.tokendir location defined in softhsm2.conf. Anyone with read access to that directory can potentially extract key material.
Apply strict permissions to the token directory:
700 (owner read/write/execute only) for maximum restriction, or 750 if the service group requires access.
objectstore.umask
Added in SoftHSM 2.7.0, theobjectstore.umask setting controls the file mode creation mask applied when SoftHSM creates token files and directories. The value is in octal and is applied in addition to the process umask — it cannot grant permissions that the process umask has already removed.
0077, which means group and other bits are cleared for all newly created object store files.
objectstore.umask does not retroactively change permissions on existing files. After changing this setting, verify permissions on existing token directories manually.Non-paged memory
By default, SoftHSM allocates sensitive data (such as private key material held in memory during an operation) in non-paged (locked) memory. This prevents the operating system from writing those pages to a swap file or swap partition, reducing the risk of key material appearing in a memory dump or swap image. This behaviour is controlled at build time:| Method | Description |
|---|---|
./configure --disable-non-paged-memory | Disable non-paged memory (Autotools build) |
-DDISABLE_NON_PAGED_MEMORY=ON | Disable non-paged memory (CMake build) |
SO PIN vs user PIN
SoftHSM enforces the PKCS#11 two-role model:- Security Officer (SO) PIN — Used to initialize or re-initialize a token. A token reset with the SO PIN destroys all existing objects on that token. Restrict the SO PIN to administrators.
- User PIN — Used by applications to perform cryptographic operations. Applications should only be given the user PIN.
Securing the configuration file
The default configuration file location is/etc/softhsm2.conf. You can override it with the SOFTHSM2_CONF environment variable:
- Set ownership to the service user and mode
640or600. - Do not place the config file in a world-readable location such as
/tmp. - If using a per-user config (
~/.config/softhsm2/softhsm2.conf), ensure the home directory has appropriate permissions.
A user-specific config at
~/.config/softhsm2/softhsm2.conf takes precedence over the system-wide config if it exists.p11-kit integration
SoftHSM can be registered as a PKCS#11 module via p11-kit. There are two registration scopes:- System-wide (
/usr/share/p11-kit/modules/or/etc/pkcs11/modules/) — all users on the system can load the module. Only appropriate for shared servers where all users should have access. - Per-user (
~/.config/pkcs11/modules/) — limits module availability to a single user account.
Network considerations
SoftHSM has no network interface. It operates exclusively as a local shared library loaded in-process. There is no daemon, no listening socket, and no remote API. Network-level isolation is therefore not applicable, but you should still:- Restrict which processes can read the token directory via file permissions.
- Audit which applications are granted the user PIN.