diff options
Diffstat (limited to 'libcacard')
-rw-r--r-- | libcacard/cac.c | 10 | ||||
-rw-r--r-- | libcacard/vcard.c | 5 | ||||
-rw-r--r-- | libcacard/vcard_emul.h | 1 | ||||
-rw-r--r-- | libcacard/vcard_emul_nss.c | 16 |
4 files changed, 25 insertions, 7 deletions
diff --git a/libcacard/cac.c b/libcacard/cac.c index ae8c3784b9..f38fdceddd 100644 --- a/libcacard/cac.c +++ b/libcacard/cac.c @@ -115,6 +115,7 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu, VCardAppletPrivate *applet_private; int size, next; unsigned char *sign_buffer; + bool retain_sign_buffer = FALSE; vcard_7816_status_t status; VCardStatus ret = VCARD_FAIL; @@ -178,6 +179,7 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu, pki_applet->sign_buffer = sign_buffer; pki_applet->sign_buffer_len = size; *response = vcard_make_response(VCARD7816_STATUS_SUCCESS); + retain_sign_buffer = TRUE; break; case 0x00: /* we now have the whole buffer, do the operation, result will be @@ -200,9 +202,11 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu, VCARD7816_STATUS_ERROR_P1_P2_INCORRECT); break; } - g_free(sign_buffer); - pki_applet->sign_buffer = NULL; - pki_applet->sign_buffer_len = 0; + if (!retain_sign_buffer) { + g_free(sign_buffer); + pki_applet->sign_buffer = NULL; + pki_applet->sign_buffer_len = 0; + } ret = VCARD_DONE; break; case CAC_READ_BUFFER: diff --git a/libcacard/vcard.c b/libcacard/vcard.c index 87ad5166a8..d140a8ed1a 100644 --- a/libcacard/vcard.c +++ b/libcacard/vcard.c @@ -250,6 +250,11 @@ void vcard_select_applet(VCard *card, int channel, VCardApplet *applet) { assert(channel < MAX_CHANNEL); + + /* If using an emulated card, make sure to log out of any already logged in + * session. */ + vcard_emul_logout(card); + card->current_applet[channel] = applet; /* reset the applet */ if (applet && applet->reset_applet) { diff --git a/libcacard/vcard_emul.h b/libcacard/vcard_emul.h index 963563f86d..f09ee98dc8 100644 --- a/libcacard/vcard_emul.h +++ b/libcacard/vcard_emul.h @@ -40,6 +40,7 @@ int vcard_emul_get_login_count(VCard *card); /* login into the card, return the 7816 status word (sw2 || sw1) */ vcard_7816_status_t vcard_emul_login(VCard *card, unsigned char *pin, int pin_len); +void vcard_emul_logout(VCard *card); /* * key functions diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c index 07b446481e..950edee069 100644 --- a/libcacard/vcard_emul_nss.c +++ b/libcacard/vcard_emul_nss.c @@ -401,7 +401,7 @@ vcard_emul_login(VCard *card, unsigned char *pin, int pin_len) } void -vcard_emul_reset(VCard *card, VCardPower power) +vcard_emul_logout(VCard *card) { PK11SlotInfo *slot; @@ -409,16 +409,24 @@ vcard_emul_reset(VCard *card, VCardPower power) return; } + slot = vcard_emul_card_get_slot(card); + if (PK11_IsLoggedIn(slot, NULL)) { + PK11_Logout(slot); /* NOTE: ignoring SECStatus return value */ + } +} + +void +vcard_emul_reset(VCard *card, VCardPower power) +{ /* * if we reset the card (either power on or power off), we lose our login * state */ + vcard_emul_logout(card); + /* TODO: we may also need to send insertion/removal events? */ - slot = vcard_emul_card_get_slot(card); - PK11_Logout(slot); /* NOTE: ignoring SECStatus return value */ } - static VReader * vcard_emul_find_vreader_from_slot(PK11SlotInfo *slot) { |