Skip to content

Commit d577802

Browse files
marschapfrankmorgner
authored andcommitted
OpenPGP: emulate SC_PIN_CMD_GET_INFO command for cards not supporting it
1 parent 7092d32 commit d577802

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/libopensc/card-openpgp.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,28 @@ pgp_pin_cmd(sc_card_t *card, struct sc_pin_cmd_data *data, int *tries_left)
18821882
LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
18831883
"key-id should be 1, 2, 3.");
18841884
}
1885+
1886+
/* emulate SC_PIN_CMD_GET_INFO command for cards not supporting it */
1887+
if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
1888+
u8 c4data[10];
1889+
int r;
1890+
1891+
r = sc_get_data(card, 0x00c4, c4data, sizeof(c4data));
1892+
LOG_TEST_RET(card->ctx, r, "reading CHV status bytes failed");
1893+
1894+
if (r != 7)
1895+
LOG_TEST_RET(card->ctx, SC_ERROR_OBJECT_NOT_VALID,
1896+
"CHV status bytes have unexpected length");
1897+
1898+
data->pin1.tries_left = c4data[4 + (data->pin_reference & 0x0F)];
1899+
data->pin1.max_tries = 3;
1900+
data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
1901+
if (tries_left != NULL)
1902+
*tries_left = data->pin1.tries_left;
1903+
1904+
LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
1905+
}
1906+
18851907
LOG_FUNC_RETURN(card->ctx, iso_ops->pin_cmd(card, data, tries_left));
18861908
}
18871909

0 commit comments

Comments
 (0)