Migrating from SoftHSM v1 to v2
SoftHSM v2 uses a completely different token storage format from v1. Thesofthsm2-migrate tool reads a v1 SQLite3 token database and imports the objects into a v2 token via the PKCS#11 interface.
Prerequisites
- SoftHSM v2 must be built with migration support:
--with-migrate(Autotools) or-DWITH_MIGRATE=ON(CMake). - SQLite3 ≥ 3.4.2 is required for the migration tool.
- A SoftHSM v2 token must be initialized and ready to receive the imported objects.
The migration tool can also target any other PKCS#11 library, not just SoftHSM v2, by using the
--module option.Building with migration support
- Autotools
- CMake
Migration steps
Locate the v1 token database
Find the SQLite3 database file used by SoftHSM v1. Its path is set in the SoftHSM v1 configuration file, typically under a
token.db path.Run softhsm2-migrate
Migrate the v1 database into the v2 token. Identify the destination token by label:Or by slot number:
softhsm2-migrate options
| Option | Description |
|---|---|
--db <path> | Path to the SoftHSM v1 SQLite3 database to migrate |
--token <label> | Use the v2 token with this label as the destination |
--serial <number> | Use the v2 token with this serial number as the destination |
--slot <number> | Use the v2 slot number as the destination |
--pin <PIN> | User PIN for the destination token |
--no-public-key | Do not migrate public key objects (migrate private keys only) |
--module <path> | Use a different PKCS#11 library instead of SoftHSM v2 |
--help, -h | Show help |
--version, -v | Show version |
Moving between object store backends
SoftHSM v2 supports two object store backends:file— Each token object is stored as a separate file on disk (default).db— All token objects are stored in a SQLite3 database file per token.
softhsm2-util and a PKCS#11 key export/import tool, or re-generate keys in the new backend if your use case allows it.
The
db backend requires SQLite3 and must be enabled at build time with --with-objectstore-backend-db (Autotools) or -DWITH_OBJECTSTORE_BACKEND_DB=ON (CMake).Steps to switch backends
Export key material
Export the keys you need to transfer. For asymmetric keys, use
softhsm2-util --export-pubkey for public keys and a PKCS#11 wrapping scheme for private keys if your application supports it. For certificates and other objects, use the relevant PKCS#11 export functions.Update softhsm2.conf
Change the Then create a fresh token directory (or clear the existing one):
objectstore.backend setting:Moving tokens between systems
SoftHSM tokens are self-contained directory trees underdirectories.tokendir. Moving a token to another system is a file copy operation.
Steps
Stop any applications using the token
Ensure no process has the SoftHSM library loaded and the token in use before copying.
Update the configuration on the target system
Ensure the
directories.tokendir in softhsm2.conf on the target system points to the same path, or update it to match the new location: