From 9f069a7e311b867ccec381f065297e3d609efa8d Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Sun, 15 May 2022 19:48:31 +0200 Subject: [PATCH] When PUT DATA or GET DATA with previously selected EF (via SELECT or SELECT DATA), it puts/writes the data into the selected EF. Signed-off-by: Pol Henarejos --- src/openpgp/openpgp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/openpgp/openpgp.c b/src/openpgp/openpgp.c index c801c83..aa599fc 100644 --- a/src/openpgp/openpgp.c +++ b/src/openpgp/openpgp.c @@ -764,6 +764,9 @@ static int cmd_get_data() { if (!authenticate_action(ef, ACL_OP_READ_SEARCH)) { return SW_SECURITY_STATUS_NOT_SATISFIED(); } + if (currentEF && (currentEF->fid & 0x1FF0) == (fid & 0x1FF0)) { //previously selected + ef = currentEF; + } if (ef->data) { uint16_t fids[] = {1,fid}; uint16_t data_len = parse_do(fids, 1); @@ -906,6 +909,9 @@ static int cmd_put_data() { fid = EF_PW_PRIV; apdu.cmd_apdu_data_len = 4; //we silently ommit the reset parameters } + if (currentEF && (currentEF->fid & 0x1FF0) == (fid & 0x1FF0)) { //previously selected + ef = currentEF; + } if (apdu.cmd_apdu_data_len > 0 && (ef->type & FILE_DATA_FLASH)) { int r = flash_write_data_to_file(ef, apdu.cmd_apdu_data, apdu.cmd_apdu_data_len); if (r != CCID_OK)