I try to open new session to softhsm2.
let pkcs11 = Pkcs11::new(
env::var("PKCS11_SOFTHSM2_MODULE")
.unwrap_or_else(|_| "/usr/lib/softhsm/libsofthsm2.so".to_string()),
)
.unwrap();
// initialize the library
pkcs11.initialize(CInitializeArgs::OsThreads).unwrap();
It got panic when meet the line pkcs11.initialize...
. What is wrong here?
I tried with sudo pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --list-slot
, it is fine.
Besides, there was one time Rust code works with that line but cannot return existing slots.
1
The problem is the service cannot open the tokens
folder, because it cannot check the configuration file of softhsm2 to know token.dir
I check the configuration file of softhsm2 using cat
and detect the permission error
. So it needs to be granted permission, everyone should be able to access /etc/softhsm2.conf
.
and also allow the access to /var/lib/softhsm/tokens
too.