diff --git a/hsm2040.c b/hsm2040.c index 0954a60..4d7034d 100644 --- a/hsm2040.c +++ b/hsm2040.c @@ -1567,8 +1567,11 @@ void card_thread() goto done; #endif } - else if (m == EV_EXIT) + else if (m == EV_EXIT) { + if (current_app && current_app->unload) + current_app->unload(); break; + } process_apdu(); diff --git a/sc_hsm.c b/sc_hsm.c index a7552fe..b2cf720 100644 --- a/sc_hsm.c +++ b/sc_hsm.c @@ -22,11 +22,13 @@ static uint8_t tmp_dkek[IV_SIZE+32]; static int sc_hsm_process_apdu(); static void init_sc_hsm(); +static int sc_hsm_unload(); app_t *sc_hsm_select_aid(app_t *a) { if (!memcmp(apdu.cmd_apdu_data, sc_hsm_aid+1, MIN(apdu.cmd_apdu_data_len,sc_hsm_aid[0]))) { a->aid = sc_hsm_aid; a->process_apdu = sc_hsm_process_apdu; + a->unload = sc_hsm_unload; init_sc_hsm(); return a; } @@ -40,6 +42,13 @@ void __attribute__ ((constructor)) sc_hsm_ctor() { void init_sc_hsm() { scan_flash(); has_session_pin = has_session_sopin = false; + isUserAuthenticated = false; +} + +int sc_hsm_unload() { + has_session_pin = has_session_sopin = false; + isUserAuthenticated = false; + return HSM_OK; } static int encrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, int len) @@ -100,7 +109,6 @@ void select_file(file_t *pe) { } if (currentEF == file_openpgp || currentEF == file_sc_hsm) { selected_applet = currentEF; - isUserAuthenticated = false; } } static int cmd_select() {