Skip to content

Commit 3544cbe

Browse files
committed
epass2003 - Fix misshandling of SM mode
When calling to erase the card (which the code says it does not handle) the sm.mode is left set even if sm mode can not be established. This can cause the problem with the next APDU failing which can cause a conversion to a sm_apdu being returned as NULL. also see: OpenSC#3196
1 parent 65edad8 commit 3544cbe

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/libopensc/card-epass2003.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -2831,7 +2831,6 @@ epass2003_create_file(struct sc_card *card, sc_file_t * file)
28312831
apdu.lc = len;
28322832
apdu.datalen = len;
28332833
apdu.data = sbuf;
2834-
28352834
r = sc_transmit_apdu_t(card, &apdu);
28362835
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
28372836
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
@@ -3215,6 +3214,7 @@ epass2003_erase_card(struct sc_card *card)
32153214
static const unsigned char mf_path[2] = { 0x3f, 0x00 };
32163215
sc_apdu_t apdu;
32173216
int r;
3217+
int saved_sm_mode = 0;
32183218

32193219
LOG_FUNC_CALLED(card->ctx);
32203220
sc_invalidate_cache(card);
@@ -3224,7 +3224,13 @@ epass2003_erase_card(struct sc_card *card)
32243224
apdu.cla = 0x80;
32253225
apdu.data = install_magic_pin;
32263226
apdu.datalen = apdu.lc = sizeof(install_magic_pin);
3227+
3228+
saved_sm_mode = card->sm_ctx.sm_mode;
3229+
card->sm_ctx.sm_mode = 0;
3230+
32273231
r = sc_transmit_apdu(card, &apdu);
3232+
card->sm_ctx.sm_mode = saved_sm_mode;
3233+
32283234
LOG_TEST_RET(card->ctx, r, "APDU install magic pin failed");
32293235
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
32303236
LOG_TEST_RET(card->ctx, r, "install magic pin failed");

src/pkcs15init/pkcs15-epass2003.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ static int epass2003_pkcs15_erase_card(struct sc_profile *profile,
3737
{
3838
SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
3939

40-
if (sc_select_file(p15card->card, sc_get_mf_path(), NULL) < 0)
41-
return SC_SUCCESS;
40+
if (sc_select_file(p15card->card, sc_get_mf_path(), NULL) < 0) {
41+
sc_do_log(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE_TOOL,NULL,0,NULL,
42+
"epass2003_pkcs15__erase_card failed calling sc_select_file, continue with erase. \n");
43+
}
4244

4345
return sc_card_ctl(p15card->card, SC_CARDCTL_ERASE_CARD, 0);
4446
}

0 commit comments

Comments
 (0)