5

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?

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Harsha
  • 131
  • 1
  • 6

1 Answers1

8

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.
Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Harsha
  • 131
  • 1
  • 6
  • It's a good idea to add `export SOFTHSM2_CONF=$HOME/lib/softhsm/softhsm2.conf` to your .bashrc file too (or for whatever shell you use) so that subsequent shells can still run the command without root. – Josh Correia Oct 13 '20 at 18:23