-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yubihsm ran out of session after a while when using with pkcs11 module #379
Comments
Would you kindly provide the versions of the yubihsm_pkcs11 module, the libpkcs11 engine and openssl ? The OS version would also be helpful. Thank you. As a side I can comment that the password needs to start with 4 hex digits, but maybe this was just an example. |
Thanks for the quick replies! Here are the version info:
We are currently running NixOS 23.05 Yeah for the password, it's definitely 4 numbers, I just didn't type it in correctly |
Also,could you set the YUBIHSM_PKCS11_DINOUT and YUBIHSM_PKCS11_DBG env variables and re-run the command, and then show the end parts of the log, so we can see if C_CloseSession (or possibly C_CloseAllSessions) is called. If it isn't then there is something wrong outside yubihsm_pkcs11. |
This is the log, I don't see the C_CloseSession which makes sense why things are not closing.
|
So it would seem yubihsm_pkcs11 is not getting deinitialized in any way, and hence cannot know that it should close the session(s). This will leave a session open in the yubihsm, which will then after 15 seconds time out. |
Gotcha, any special config needed to deinitialize it? I have been following the tutorial from the yubihsm site here: https://developers.yubico.com/YubiHSM2/Usage_Guides/OpenSSL_with_pkcs11_engine.html and I didn't see mention of special cleanup |
Okay I think I understand why things are not playing well with each other. So libp11 will wait for a new session forever as specified here by checking for if the I think a possible fix would be for yubihsm to actually reserve the session with the physical yubikey itself in C_OpenSession so that if we don't have enought session, libp11 knows to wait |
C_OpenSession doesn't open a physical session because with the yubihsm a session is always encrypted, so we can't open one until we have a password. Secondly, since login state is global (per process) in pkcs#11 there is no need for a separate physical session per logical (pkcs#11) session. In fact it would make things complicated, as per the pkcs#11 standard all (pkcs#11) sessions transition between logged in and not logged in (and a third SO state) simultaneously. We have no set upper limit on pkcs#11 sessions that can be opened as they only represent some memory which is dynamically allocated. (A pkcs#11 session does however represent a RO or RW state, which we keep track of in the library) Having said all that I don't think this has any bearing on the fundamental problem, which is that as the openssl command / process dies it does not tell yubihsm_pkcs11 to clean up (either openssl doesn't tell the libp11 engine or the libp11 engine doesn't tell yubihsm_pkcs11), and thus we leave a session open on the yubihsm device. As that process dies it forgets the session keys and hence the session is now useless, but the yubihsm device can't know that. And we can't clean the session up in a new instance of yubihsm_pkcs11 since we can't know if there is a client still using it. I would say the next step might be to try to debug the libp11 engine and see if it gets a cleanup, and what it does with it. |
okay I went down the blackhole and it looks like there is a reference counting bug in openssl that's why clean up wasn't called. Fixing that bug results in another deadlocking bug though so I think for now I will just use our delay workaround |
Maybe this could be useful https://github.com/latchset/pkcs11-provider |
Hi,
Currently, I'm using yubihsm with the openssl commandline through the pkcs11 module and the signing works for a bit but then gradually we run into the error: "Failed to create session: All sessions are allocated".
I think this is because the sessions are not closed by pkcs11 but I'm not sure how to force it to close or whether I'm using it incorrectly. For example this is the command that we would run:
And it works for a bit but if we do it too frequently then it ran out of session. If I add some delays then it doesn't break.
This is our openssl config file:
The text was updated successfully, but these errors were encountered: