Skip to content

Commit 70a9e77

Browse files
MkfsSionJakuje
authored andcommitted
openpgp: Fix retry counter of encryption PIN in SC_PIN_CMD_GET_INFO emulation for card supporting OpenPGP card spec v2.0 and later
The meaning of byte 6 of DO C4 has changed from the retry counter of the encryption PIN (CHV2) to that of resetting code since OpenPGP card spec v2.0, and PW1 now serves as both the signature and encryption PIN. Map PIN reference from 82 to 81 to correct retry counter of encryption PIN for these cards.
1 parent c70be5a commit 70a9e77

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libopensc/card-openpgp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,14 @@ pgp_pin_cmd(sc_card_t *card, struct sc_pin_cmd_data *data, int *tries_left)
24682468
LOG_TEST_RET(card->ctx, SC_ERROR_OBJECT_NOT_VALID,
24692469
"CHV status bytes have unexpected length");
24702470

2471+
/* The definition of fields of DO C4 changed between OpenPGP
2472+
* card specification v1.1 and v2.0. There is no longer a separate
2473+
* CHV2 retry counter but only one retry counter for both PW1 mode 1
2474+
* and mode 2 at byte 5 (count from 1) of the DO.
2475+
*/
2476+
if (priv->bcd_version >= OPENPGP_CARD_2_0 && data->pin_reference == 0x82)
2477+
data->pin_reference = 0x81;
2478+
24712479
data->pin1.tries_left = c4data[3 + (data->pin_reference & 0x0F)];
24722480
data->pin1.max_tries = 3;
24732481
data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;

0 commit comments

Comments
 (0)