Disable the secure channel at logout (#1048)

Fixes https://github.com/OpenSC/OpenSC/issues/1036
This commit is contained in:
rickyepoderi 2017-05-13 16:15:08 +02:00 committed by Frank Morgner
parent 427c175c08
commit d9d247e6cd
1 changed files with 16 additions and 4 deletions

View File

@ -1406,14 +1406,26 @@ static int dnie_get_challenge(struct sc_card *card, u8 * rnd, size_t len)
static int dnie_logout(struct sc_card *card)
{
int result = SC_SUCCESS;
sc_file_t *file = NULL;
if ((card == NULL) || (card->ctx == NULL))
return SC_ERROR_INVALID_ARGUMENTS;
LOG_FUNC_CALLED(card->ctx);
/* disable and free any sm channel related data */
result =
cwa_create_secure_channel(card, GET_DNIE_PRIV_DATA(card)->cwa_provider, CWA_SM_OFF);
/* TODO: _logout() see comments.txt on what to do here */
if (card->sm_ctx.sm_mode != SM_MODE_NONE) {
/* mark the channel as closed */
result = cwa_create_secure_channel(card,
GET_DNIE_PRIV_DATA(card)->cwa_provider, CWA_SM_OFF);
LOG_TEST_RET(card->ctx, result, "Cannot close the secure channel");
/* request the Master File to provoke an SM error and close the channel */
result = dnie_compose_and_send_apdu(card, (const u8 *) DNIE_MF_NAME,
sizeof(DNIE_MF_NAME) - 1, 4, &file);
if (result == SC_ERROR_SM)
result = SC_SUCCESS;
}
if (file != NULL)
sc_file_free(file);
LOG_FUNC_RETURN(card->ctx, result);
}