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

MD: Propagate the number of attempts remaining #2758

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/libopensc/card-piv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3203,7 +3203,6 @@ static int piv_match_card_continued(sc_card_t *card)
priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
/* TODO Dual CAC/PIV are bases on 800-73-1 where priv->pin_preference = 0. need to check later */
priv->logged_in = SC_PIN_STATE_UNKNOWN;
priv->tries_left = 10; /* will assume OK at start */
priv->pstate = PIV_STATE_MATCH;

/* Some objects will only be present if History object says so */
Expand Down
1 change: 1 addition & 0 deletions src/libopensc/pkcs15-pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ int sc_pkcs15_verify_pin_with_session_pin(struct sc_pkcs15_card *p15card,
*sessionpinlen = 0;
}
}
auth_info->tries_left = data.pin1.tries_left;

if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN
&& auth_info->auth_method != SC_AC_SESSION) {
Expand Down
3 changes: 1 addition & 2 deletions src/libopensc/pkcs15-piv.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,8 @@ static int sc_pkcs15emu_piv_init(sc_pkcs15_card_t *p15card)
pin_info.attrs.pin.stored_length = pins[i].storedlen;
pin_info.attrs.pin.max_length = pins[i].maxlen;
pin_info.attrs.pin.pad_char = pins[i].pad_char;
pin_info.tries_left = pins[i].tries_left;
sc_format_path(pins[i].path, &pin_info.path);
pin_info.tries_left = -1;

label = pins[i].label;
if (i == 0 &&
Expand All @@ -970,7 +970,6 @@ static int sc_pkcs15emu_piv_init(sc_pkcs15_card_t *p15card)
pin_info.attrs.pin.flags &= ~SC_PKCS15_PIN_FLAG_LOCAL;
label = "Global PIN";
}
sc_log(card->ctx, "DEE Adding pin %d label=%s",i, label);
strncpy(pin_obj.label, label, SC_PKCS15_MAX_LABEL_SIZE - 1);
pin_obj.flags = pins[i].obj_flags;
if (i == 0 && pin_info.attrs.pin.reference == 0x80) {
Expand Down
31 changes: 20 additions & 11 deletions src/minidriver/minidriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -5871,9 +5871,6 @@ DWORD WINAPI CardAuthenticateEx(__in PCARD_DATA pCardData,
}
}

if(pcAttemptsRemaining)
(*pcAttemptsRemaining) = (DWORD) -1;

auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
/* save the pin type */
auth_method = auth_info->auth_method;
Expand Down Expand Up @@ -5947,6 +5944,16 @@ DWORD WINAPI CardAuthenticateEx(__in PCARD_DATA pCardData,
/* restore the pin type */
auth_info->auth_method = auth_method;

if(pcAttemptsRemaining) {
if (0 > auth_info->tries_left) {
/* Card modules that do not support a count of remaining
* authentication attempts should return a value of 1 for this
* parameter if the value 1 */
(*pcAttemptsRemaining) = 1;
} else
(*pcAttemptsRemaining) = auth_info->tries_left;
}

if (r) {
logprintf(pCardData, 1, "PIN code verification failed: %s; tries left %i\n", sc_strerror(r), auth_info->tries_left);

Expand All @@ -5955,9 +5962,6 @@ DWORD WINAPI CardAuthenticateEx(__in PCARD_DATA pCardData,
(*pcAttemptsRemaining) = 0;
MD_FUNC_RETURN(pCardData, 1, SCARD_W_CHV_BLOCKED);
}

if(pcAttemptsRemaining)
(*pcAttemptsRemaining) = auth_info->tries_left;
MD_FUNC_RETURN(pCardData, 1, md_translate_OpenSC_to_Windows_error(r, SCARD_W_WRONG_CHV));
}

Expand Down Expand Up @@ -6064,9 +6068,6 @@ DWORD WINAPI CardChangeAuthenticatorEx(__in PCARD_DATA pCardData,

pin_obj = vs->pin_objs[dwTargetPinId];

if(pcAttemptsRemaining)
(*pcAttemptsRemaining) = (DWORD) -1;

/* FIXME: this does not enforce dwAuthenticatingPinId */
rv = md_dialog_perform_pin_operation(pCardData,
(dwFlags & PIN_CHANGE_FLAG_UNBLOCK ?
Expand All @@ -6078,6 +6079,16 @@ DWORD WINAPI CardChangeAuthenticatorEx(__in PCARD_DATA pCardData,
pbTargetData, &target_len,
DisplayPinpadUI, dwTargetPinId);

if(pcAttemptsRemaining) {
if (0 > auth_info->tries_left) {
/* Card modules that do not support a count of remaining
* authentication attempts should return a value of 1 for this
* parameter if the value 1 */
(*pcAttemptsRemaining) = 1;
} else
(*pcAttemptsRemaining) = auth_info->tries_left;
}

if (rv) {
logprintf(pCardData, 2, "Failed to %s %s PIN: '%s' (%i)\n",
(dwFlags & PIN_CHANGE_FLAG_CHANGEPIN?"change":"unblock"),
Expand All @@ -6089,8 +6100,6 @@ DWORD WINAPI CardChangeAuthenticatorEx(__in PCARD_DATA pCardData,
MD_FUNC_RETURN(pCardData, 1, SCARD_W_CHV_BLOCKED);
}

if(pcAttemptsRemaining)
(*pcAttemptsRemaining) = auth_info->tries_left;
MD_FUNC_RETURN(pCardData, 1, md_translate_OpenSC_to_Windows_error(rv, SCARD_W_WRONG_CHV));
}

Expand Down
1 change: 1 addition & 0 deletions src/tools/pkcs15-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ static int list_pins(void)
printf("Card has %d Authentication object(s).\n\n", r);

for (i = 0; i < r; i++) {
sc_pkcs15_get_pin_info(p15card, objs[i]);
print_pin_info(objs[i]);
printf("\n");
}
Expand Down