Error creating token via softhsm2 as non-root user "Could not initialize the library"

3.8k views Asked by At

Whilst initializing a token via softhsm2-util as a non-root user I receive the following error:

$ softhsm2-util --init-token --slot 0  --label "test" --so-pin 5462 --pin 8764329

ERROR: Could not initialize the library.

How can I fix this?

1

There are 1 answers

1
Harsha On

Whilst initializing token as a non-root user, we invariably try to access the default /etc/softhsm/softhsm2.conf which points tokens to be staged under /var/lib/softhsm/tokens whose ownership/permission is limited to be used by root and its associated groups.

Changing ownership/permission of /var/lib/softhsm/tokens doesn't solve the problem as we cannot access /etc/softhsm/softhsm2.conf in the first place given the access limitation, so we should be doing this instead:

cd $HOME
mkdir -p $HOME/lib/softhsm/tokens
cd $HOME/lib/softhsm/
echo "directories.tokendir = $PWD/tokens" > softhsm2.conf
export SOFTHSM2_CONF=$HOME/lib/softhsm/softhsm2.conf

$ softhsm2-util --init-token --slot 0 --label "test" --so-pin 5462 --pin 8764329
The token has been initialized.