ThalesGroup / pycryptoki

Python interface to SafeNet's PKCS11 library implementation
Apache License 2.0
60 stars 23 forks source link

Support for multithreaded applications #50

Open hassan-kamaledine opened 4 months ago

hassan-kamaledine commented 4 months ago

Hello team, I wanted to inquire about the possibility of adding support for handling sessions in a multi threaded application. An example of this can be found in the python-pcks11 library.

Since we use this library for its better compatibility with the Thales network HSM, but we faced an issue when using multiple threads with gunicorn we would get the error code CKR_OPERATION_ACTIVE since the thread tried to use a session that was already in use.

astraw38 commented 4 months ago

Hi @hassan-kamaledine , It's been a while since I've done pycryptoki with threading. There's nothing built into pycryptoki that is plug-and-play, but there's also nothing that makes it impossible to implement yourself, via a session pool that threads would grab from & use.

hassan-kamaledine commented 4 months ago

Thanks for the prompt support!

but there's also nothing that makes it impossible to implement yourself, via a session pool that threads would grab from & use.

Yep that is the plan, just wanted to check if it was ever considered to add support for this out of the box.

Have a nice day!