Skip to content

Commit

Permalink
jpki/iso7816: explicityl check for PIN length != 0 on VERIFY
Browse files Browse the repository at this point in the history
If we want to verify the PIN, we don't want the status request, which
results in an almost identical APDU (VERIFY APDU with no data). However,
as the request for verifying the PIN results in a CASE 3 APDU,
`sc_check_apdu()` will check for missing data for the verification so
that an error is returned and no PIN bypass is possible.
  • Loading branch information
frankmorgner committed Oct 23, 2023
1 parent 67a3874 commit a2e36f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libopensc/card-jpki.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ jpki_pin_cmd(sc_card_t *card, struct sc_pin_cmd_data *data, int *tries_left)

switch (data->cmd) {
case SC_PIN_CMD_VERIFY:
/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
if (data->pin1.len == 0)
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_PIN_LENGTH);
sc_format_apdu(card, &apdu, SC_APDU_CASE_3, 0x20, 0x00, 0x80);
apdu.data = data->pin1.data;
apdu.datalen = data->pin1.len;
Expand Down
3 changes: 3 additions & 0 deletions src/libopensc/iso7816.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,9 @@ iso7816_build_pin_apdu(struct sc_card *card, struct sc_apdu *apdu,
switch (data->cmd) {
case SC_PIN_CMD_VERIFY:
ins = 0x20;
/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
if (data->pin1.len == 0)
return SC_ERROR_INVALID_PIN_LENGTH;
if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
return r;
len = r;
Expand Down

0 comments on commit a2e36f7

Please sign in to comment.