Skip to content

Commit ec17122

Browse files
committed
epass2003 - improved SM handling
Test return from epass2003_refresh If fails during epass2003, continue without setting: card->sm_ctx.sm_mode = SM_MODE_TRANSMIT; On branch epass2003-sm-new Changes to be committed: modified: libopensc/card-epass2003.c
1 parent 3544cbe commit ec17122

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/libopensc/card-epass2003.c

+13-7
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,15 @@ epass2003_check_sw(struct sc_card *card, unsigned int sw1, unsigned int sw2)
268268
static int
269269
sc_transmit_apdu_t(sc_card_t *card, sc_apdu_t *apdu)
270270
{
271+
int r;
271272
size_t resplen = apdu->resplen;
272-
int r = sc_transmit_apdu(card, apdu);
273-
if ( ((0x69 == apdu->sw1) && (0x85 == apdu->sw2)) || ((0x69 == apdu->sw1) && (0x88 == apdu->sw2)))
273+
274+
r = sc_transmit_apdu(card, apdu);
275+
if (apdu && (((0x69 == apdu->sw1) && (0x85 == apdu->sw2)) || ((0x69 == apdu->sw1) && (0x88 == apdu->sw2))))
274276
{
275-
epass2003_refresh(card);
277+
r = epass2003_refresh(card);
278+
LOG_TEST_RET(card->ctx, r, "epass2003_refresh failed");
279+
276280
/* renew old resplen */
277281
apdu->resplen = resplen;
278282
r = sc_transmit_apdu(card, apdu);
@@ -962,8 +966,8 @@ epass2003_refresh(struct sc_card *card)
962966
card->sm_ctx.sm_mode = 0;
963967
memset(exdata->icv_mac, 0, sizeof(exdata->icv_mac));
964968
r = mutual_auth(card, g_init_key_enc, g_init_key_mac);
965-
card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
966969
LOG_TEST_RET(card->ctx, r, "mutual_auth failed");
970+
card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
967971
}
968972

969973
return r;
@@ -1766,6 +1770,7 @@ static int epass2003_match_card(struct sc_card *card)
17661770
static int
17671771
epass2003_init(struct sc_card *card)
17681772
{
1773+
int r = 0;
17691774
unsigned int flags;
17701775
unsigned int ext_flags;
17711776
unsigned char data[SC_MAX_APDU_BUFFER_SIZE] = { 0 };
@@ -1827,9 +1832,10 @@ epass2003_init(struct sc_card *card)
18271832
card->sm_ctx.ops.free_sm_apdu = epass2003_sm_free_wrapped_apdu;
18281833

18291834
/* FIXME (VT): rather then set/unset 'g_sm', better to implement filter for APDUs to be wrapped */
1830-
epass2003_refresh(card);
1831-
1832-
card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
1835+
r =epass2003_refresh(card);
1836+
if (r < 0) {
1837+
sc_log(card->ctx, "epass2003_refresh failed: %d continue without SM", r);
1838+
}
18331839

18341840
flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
18351841

0 commit comments

Comments
 (0)