Skip to content
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

Skip login if token does not require login #258

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ static CK_RV slot_login(P11PROV_SLOT *slot, P11PROV_URI *uri,
return ret;
}

static bool check_skip_login(P11PROV_CTX *ctx, P11PROV_SLOT *slot)
{
return p11prov_ctx_login_behavior(ctx) != PUBKEY_LOGIN_ALWAYS
&& !p11prov_slot_check_req_login(slot);
}

/* There are three possible ways to call this function.
* 1. One shot call on a specific slot
* slotid must point to a specific slot number
Expand Down Expand Up @@ -734,7 +740,7 @@ CK_RV p11prov_get_session(P11PROV_CTX *provctx, CK_SLOT_ID *slotid,
if (ret != CKR_OK) {
goto done;
}
if (reqlogin) {
if (reqlogin && !check_skip_login(provctx, slot)) {
ret = slot_login(slot, uri, pw_cb, pw_cbarg, NULL);
if (ret != CKR_OK) {
goto done;
Expand Down Expand Up @@ -768,7 +774,7 @@ CK_RV p11prov_get_session(P11PROV_CTX *provctx, CK_SLOT_ID *slotid,
/* keep going */
continue;
}
if (reqlogin) {
if (reqlogin && !check_skip_login(provctx, slot)) {
ret = slot_login(slot, uri, pw_cb, pw_cbarg, NULL);
if (ret != CKR_OK) {
/* keep going */
Expand Down
5 changes: 5 additions & 0 deletions src/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,8 @@ P11PROV_SESSION_POOL *p11prov_slot_get_session_pool(P11PROV_SLOT *slot)
{
return slot->pool;
}

bool p11prov_slot_check_req_login(P11PROV_SLOT *slot)
{
return slot->token.flags & CKF_LOGIN_REQUIRED;
}
1 change: 1 addition & 0 deletions src/slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ CK_RV p11prov_slot_set_bad_pin(P11PROV_SLOT *slot, const char *bad_pin);
const char *p11prov_slot_get_cached_pin(P11PROV_SLOT *slot);
CK_RV p11prov_slot_set_cached_pin(P11PROV_SLOT *slot, const char *cached_pin);
P11PROV_SESSION_POOL *p11prov_slot_get_session_pool(P11PROV_SLOT *slot);
bool p11prov_slot_check_req_login(P11PROV_SLOT *slot);

#endif /* _SLOT_H */
Loading