directories.tokendir in softhsm2.conf. Backups are ordinary file-system operations.
Where tokens are stored
Each token occupies its own subdirectory insidetokendir. The subdirectory name is a UUID generated at initialization time, not the token label:
Token directories are identified by UUID, not by label. Two tokens can share the same label, but their UUIDs will differ. When restoring, always transfer the full UUID directory.
--with-objectstore-backend-db), each token’s data is stored in a single SQLite3 database file inside the UUID directory instead of individual .object files.
Backing up tokens
File-based backend (default)
Copy the entiretokendir or the specific UUID subdirectories you want to preserve:
SQLite3 backend
For the SQLite3 backend, back up the database file inside the token’s UUID directory. Use the SQLite3 online backup API or simply copy the file while SoftHSM is not actively writing to it:Restoring tokens
Stop any process using SoftHSM
Ensure no application has the SoftHSM PKCS#11 library loaded before you modify the token directory.
Set correct permissions
Token files must be readable and writable by the user running SoftHSM. Fix ownership and permissions if needed:The
objectstore.umask setting in softhsm2.conf controls the permission mask applied to newly created token files. Ensure the restored files are consistent with this setting.File permissions and objectstore.umask
Theobjectstore.umask setting in softhsm2.conf determines the permission mask applied when SoftHSM creates token and object files. The default is 0077, which makes files accessible only to the owning user.
Moving tokens to another machine
Because tokens are identified by UUID directory name and the serial number embedded intoken.object, you can move a token to another machine by:
- Copying the UUID directory to the same
tokendirpath on the target machine. - Ensuring the
softhsm2.confon the target machine points to the sametokendir. - Verifying the
objectstore.backendsetting matches the backend used when the token was created.
The slot ID assigned to the token on the target machine may differ from the source machine, since slot IDs are derived from the serial number but also depend on what other tokens are present. Always look up tokens by label or serial number rather than slot ID.