Skip to content

Commit

Permalink
md: return pcAttemptsRemaining:=1 if the card doesn't support it
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmorgner committed Apr 24, 2023
1 parent 25a3ff5 commit e5dbcd9
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/minidriver/minidriver.c
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

0 comments on commit e5dbcd9

Please sign in to comment.