dlopenpkcs#11opensc

dlopen() fails loading opensc-pkcs11.so


While trying to dlopen the /usr/lib/x86_64-gnu-linux/opensc-pkcs11.so from within an application, I get a "Cannot open shared object file: no such file or directory" for the library.

dlopen("/usr/lib/x86_64-linux-gnu/opensc-pkcs11.so", RTLD_NOW | RTLD_LOCAL);

I followed the instructions on the Wiki https://github.com/OpenSC/OpenSC/wiki/Compiling-and-Installing-on-Unix-flavors

and also did a sudo apt-get install opensc-pkcs11.so. The file exists in /usr/lib/x86_64-gnu-linux and that is the library search path.

Is there anything else that needs to be done ? Do any env variables need to be set ? The same works for dlopen of the SoftHSM library.

Wanted to point out that when running the pkcs11-tool command line, it works

$ pkcs11-tool --module /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so -I
Cryptoki version 2.20
Manufacturer     OpenSC (www.opensc-project.org)
Library          Smart card PKCS#11 API (ver 0.0)
No slot with a token was found.

So it appears to be when I try the same dlopen within my application, that it fails. Any ideas ?


Solution

  • when I try the same dlopen within my application, that it fails

    The most likely reason for no such file is that the opensc-pkcs11.so itself has a dependency on some other library, and that library isn't found.

    You can confirm or disprove this with ldd /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so.