-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Regression in session handling for PIN protected enclaves #9
Comments
I think I can write a regression test for it and maybe even offer a patch. |
details and tests are in #10 |
This regression was my fault in #3, and I was just coming here now to fix, and saw this. My apologies for the trouble. Closing idle sessions seems like a good idea, but is hard to get right with how the package is implemented currently (as can be seen with the scope of changes in #10). I was just going to change the idle timeout value to 0, which disables the closing of idle resources. But I'll give the changes in #10 a shot first and report back. |
I tested out #10, and it's a partial solution for us. Our code calls However, the change to proactively attempt a login when new sessions are created allows us to implement retries in our application logic, and this works for us: https://gist.github.com/cbroglie/e7e9fce242ad23c552df4c6e72755f5f. It would be great if this library could eventually encapsulate all the retry behavior itself. Thanks again for cleaning up my mess. |
I do think it is hard to provide a decent connection pool handling for everyone because usually when someone uses a pool, every aspect of the behavior is specific to the use case. From the other side, it's hard to manage context state and sessions state with pkcs#11 API as it does not expose a lot of necessary information (i.e. is the user logged in for the token) and this info must be always be marshaled first. Another point: the Login operations i.e. may be very expensive. It's more of the library API design that it uses singleton instance, and so limited to the behavior configuration. Even the pool could be given to the user to be used by himself if required alone. Timeouts may be exposed to the user configuration though.
We do the same. With the pool design which can eat idle connection getting CKR_OBJECT_HANDLE_INVALID is inevitable. Unfortunately, the key identity can't be retrieved after the handle got rot and thus can't be automatically retrieved without knowing associated identity information before. There is also no way to check for the handle health but calling for an Identity location via CGO proactively which is the same bad, as trying to Login for every new session. But IFIIN there is no other way to get a context state to determine if the token has been logged into, as the login state is shared among the sessions, but when the res pool closes all of them, the login state shuts down automatically. That's why it is barely possible to handle Login state for new sessions in the pool, but not for the object handles. In the end, it's up for the client to decide on the trade offs. It can have connection pool without idle timeouts, or he can have no cached handles. If to cache handles, the cache could proactively check handles health and restore them, or the client code could support resorting handles state handling known error. Proactive checks reduce performance, yet it depends on the use cases. |
I think this is a good idea; should add it to |
See ThalesGroup/crypto11#9. Permanent fix will be handled in #246.
See ThalesGroup/crypto11#9. Permanent fix will be handled in #246.
Agree. I will add MaxSessions and IdleTimeout to the #10 then. |
Personally, if I would making crypto11 the next version, I did vote for removing the singleton default session and resource pool necessity and give the user right to choose how to configure and handle session/s. That will make API clearer and easier and will shift the complexity of bringing universal solutions on the sessions handling to the domain where it can just pick and tune. |
I agree completely. |
#10 merged |
_, err := crypto11.Configure(&crypto11.PKCS11Config{Path: config.HSMTokenPath, TokenLabel: config.TokenLabel, Pin: config.HSMPin})
is doing finesets an idle timeout of 30 seconds for the sessions to be wiped out off the pool.
3. Then Configure uses withSession to login for currently created session.
4. After 30 seconds pool closes a session OR after a 30 seconds of used sessions pool closes them.
5. After that user is unable to work with the library because for all further operations it returns either
pkcs11: 0x82: CKR_OBJECT_HANDLE_INVALID
orpkcs11: 0x101: CKR_USER_NOT_LOGGED_IN
.The text was updated successfully, but these errors were encountered: