MatthiasValvekens / pyHanko

pyHanko: sign and stamp PDF files
MIT License
494 stars 71 forks source link

libcrypto.so.3: undefined symbol: C_GetFunctionList' #382

Closed Fernando-Cabral closed 7 months ago

Fernando-Cabral commented 7 months ago

Describe the bug pyhank stopped working and started complaining about /lib/libcrypto.so.3: undefined symbol: C_GetFunctionList'

To Reproduce I have several versions of this library, so I tried one by one. They all failed with the same error message. Here is the code I used to test it:

#!/usr/bin/env python3
from pkcs11 import lib as pkcs11_lib
import OpenSSL
from pkcs11 import Attribute, ObjectClass

# I tried each one of them in turn
# lib_location = '/home/fernando/anaconda3/pkgs/openssl-3.1.3-hd590300_0/lib/libcrypto.so'
# lib_location = '/home/fernando/anaconda3/pkgs/openssl-3.1.3-hd590300_0/lib/libcrypto.so.3'
# lib_location = '/home/fernando/anaconda3/pkgs/openssl-3.2.1-hd590300_0/lib/libcrypto.so.3'
# lib_location = '/home/fernando/anaconda3/lib/libcrypto.so.3'
lib_location = '/home/fernando/anaconda3/envs/myenv/lib/libcrypto.so.3'

lib = pkcs11_lib(lib_location)

slots = lib.get_slots()
for slot in slots:
    try:
        token = slot.get_token()
        print("#", f"->{token.label}<-")
#    except PKCS11Error:
    except Exception as e:
        print ("*", e)
        continue
print ("**Tokens**")
#for token in lib.get_tokens(token_label='smartcard'):
for token in lib.get_tokens():
    print(token)

Environment (please complete the following information):

Additional context

Here is the error message:
~/pyhanko$ ./check_token_label.py
/home/fernando/anaconda3/envs/myenv/lib/libcrypto.so.3
Traceback (most recent call last):
  File "/home/fernando/pyhanko/./check_token_label.py", line 22, in <module>
    lib = pkcs11_lib(lib_location)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fernando/anaconda3/lib/python3.11/site-packages/pkcs11/__init__.py", line 32, in lib
    _lib = _pkcs11.lib(so)
           ^^^^^^^^^^^^^^^
  File "pkcs11/_pkcs11.pyx", line 1429, in pkcs11._pkcs11.lib.__cinit__
  File "pkcs11/_pkcs11.pyx", line 1406, in pkcs11._pkcs11.lib._load_pkcs11_lib
RuntimeError: /home/fernando/anaconda3/envs/myenv/lib/libcrypto.so.3 is not a PKCS#11 library: b'/home/fernando/anaconda3/envs/myenv/lib/libcrypto.so.3: undefined symbol: C_GetFunctionList'

Other than the different path for each library version, the error message is the same, no matter which version I am using.

What should I try next?

MatthiasValvekens commented 7 months ago

Ah, I noticed that pyHanko's CI is currently also failing at the same Cython line in python-pkcs11, but I likely won't have time to debug until Sunday next week at the earliest...

MatthiasValvekens commented 7 months ago

My knee-jerk reaction was wrong. The issue with the CI is now resolved and turned out to be a softhsm2-specific issue (had to do with an interaction between the way I was provisioning the config and a test stack upgrade), so I'm converting this to a discussion.

Looking again at your issue with a fresh pair of eyes, I think it is what it says on the tin: the library you're trying to call is not a PKCS#11 module. libcrypto.so is the OpenSSL binary, which doesn't expose any PKCS#11 functionality. Are you sure you have the right library?