-
Notifications
You must be signed in to change notification settings - Fork 37
logout user in the case that the underlying connection gets disconnected #383
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,26 @@ int wh_Server_Init(whServerContext* server, whServerConfig* config) | |
| server->nvm = config->nvm; | ||
| #ifdef WOLFHSM_CFG_ENABLE_AUTHENTICATION | ||
| server->auth = config->auth; | ||
| /* auth context is externally owned; clear any stale session left over from | ||
| * a prior connection (Logout first so backend callback runs). */ | ||
| if (server->auth != NULL) { | ||
| if (server->auth->user.user_id != WH_USER_ID_INVALID) { | ||
| whUserId stale_id = server->auth->user.user_id; | ||
|
|
||
| rc = wh_Auth_Logout(server->auth, stale_id); | ||
| if (rc != WH_ERROR_OK) { | ||
| WH_LOG(&server->log, WH_LOG_LEVEL_SECEVENT, | ||
| "Stale auth session force-cleared during server init after " | ||
| "logout failure"); | ||
| } | ||
| } | ||
| rc = wh_Auth_Reset(server->auth); | ||
| if (rc != WH_ERROR_OK) { | ||
| WH_LOG(&server->log, WH_LOG_LEVEL_SECEVENT, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 [Low] Init-time auth SECEVENT logs fire before wh_Log_Init and are discarded · Dead error handling The new Fix: Move the auth stale-session clearing block to after the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JacobBarthelmeh this look like the log will indeed be dropped since it is after the reset. Could you address this pls? Then we can get it in |
||
| "Failed to clear auth session during server init"); | ||
| return rc; | ||
| } | ||
| } | ||
| #endif /* WOLFHSM_CFG_ENABLE_AUTHENTICATION */ | ||
|
|
||
| #ifndef WOLFHSM_CFG_NO_CRYPTO | ||
|
|
@@ -177,6 +197,31 @@ int wh_Server_SetConnected(whServerContext *server, whCommConnected connected) | |
| return WH_ERROR_BADARGS; | ||
| } | ||
|
|
||
| #ifdef WOLFHSM_CFG_ENABLE_AUTHENTICATION | ||
| /* Log out any active user on disconnect, including abrupt drops where | ||
| * COMM_CLOSE never arrives. */ | ||
| if (connected == WH_COMM_DISCONNECTED && | ||
| server->connected != WH_COMM_DISCONNECTED && | ||
| server->auth != NULL && | ||
| server->auth->user.user_id != WH_USER_ID_INVALID) { | ||
| whUserId user_id = server->auth->user.user_id; | ||
| int rc = wh_Auth_Logout(server->auth, user_id); | ||
|
|
||
| if (rc != WH_ERROR_OK) { | ||
| WH_LOG(&server->log, WH_LOG_LEVEL_SECEVENT, | ||
| "Auth session force-cleared on disconnect after logout " | ||
| "failure"); | ||
| } | ||
| rc = wh_Auth_Reset(server->auth); | ||
| if (rc != WH_ERROR_OK) { | ||
| WH_LOG(&server->log, WH_LOG_LEVEL_SECEVENT, | ||
| "Failed to clear auth session on disconnect"); | ||
| server->connected = connected; | ||
| return rc; | ||
| } | ||
| } | ||
| #endif /* WOLFHSM_CFG_ENABLE_AUTHENTICATION */ | ||
|
|
||
| server->connected = connected; | ||
| return WH_ERROR_OK; | ||
| } | ||
|
|
@@ -285,15 +330,9 @@ static int _wh_Server_HandleCommRequest(whServerContext* server, | |
| /* No message */ | ||
| /* Process the close action */ | ||
|
|
||
| #ifdef WOLFHSM_CFG_ENABLE_AUTHENTICATION | ||
| /* Log out the current user when communication channel closes */ | ||
| if (server->auth != NULL && | ||
| server->auth->user.user_id != WH_USER_ID_INVALID) { | ||
| whUserId user_id = server->auth->user.user_id; | ||
| (void)wh_Auth_Logout(server->auth, user_id); | ||
| } | ||
| #endif /* WOLFHSM_CFG_ENABLE_AUTHENTICATION */ | ||
|
|
||
| /* wh_Server_SetConnected logs out any active user on the transition to | ||
| * the disconnected state, so the graceful-close and abrupt-disconnect | ||
| * paths share a single authoritative logout. */ | ||
| wh_Server_SetConnected(server, WH_COMM_DISCONNECTED); | ||
| *out_resp_size = 0; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JacobBarthelmeh Seems odd to still clear the session if you can't acquire the lock - this means someone else could be in process of reading. Perhaps the backend would get put into a weird state if synchronous access isn't respected? I'd rather just hard fail if you can't acquire the lock, and let the caller deal with it since it probably means their entire system is broken? I guess you could make the argument that the locking function really shouldn't ever fail, but kind of a bucket of worms. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with changing it to be a hard fail when the lock fails. I think that is better behavior than what I'd added for continuing to memset anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JacobBarthelmeh sounds good, pls assign me when ready for re-review