From 86696a4b2494b7e4f74fb707b67425fff7b8f825 Mon Sep 17 00:00:00 2001 From: Vincent JARDIN Date: Mon, 29 Mar 2021 16:45:07 +0000 Subject: [PATCH 1/2] IASECC/CPX: fix APDU errors for SE get data On a CPX, this object needs to be read from 3F00. For instance: $ opensc-explorer -r 2 OpenSC [3F00]> cd 0002 OpenSC [3F00/0002]> apdu 00 CB 3F FF 0A 4D 08 70 06 BF FB 05 02 7B 80 Sending: 00 CB 3F FF 0A 4D 08 70 06 BF FB 05 02 7B 80 Received (SW1=0x6A, SW2=0x88) Failure: Data object not found OpenSC [3F00/0002]> apdu 00 A4 09 04 02 3F 00 Sending: 00 A4 09 04 02 3F 00 Received (SW1=0x90, SW2=0x00) Success! OpenSC [3F00/0002]> apdu 00 CB 3F FF 0A 4D 08 70 06 BF FB 05 02 7B 80 Sending: 00 CB 3F FF 0A 4D 08 70 06 BF FB 05 02 7B 80 Received (SW1=0x90, SW2=0x00) Success! Currently, this patch limits to the CPX cards since I cannot know the behaviour for the other cards. I could not find any reference from the standard. Fix: issue #2275 --- src/libopensc/card-iasecc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libopensc/card-iasecc.c b/src/libopensc/card-iasecc.c index 6520275b69..7dfa3ad780 100644 --- a/src/libopensc/card-iasecc.c +++ b/src/libopensc/card-iasecc.c @@ -1710,6 +1710,11 @@ iasecc_se_get_info(struct sc_card *card, struct iasecc_se_info *se) LOG_FUNC_CALLED(ctx); + if (iasecc_is_cpx(card)) { + rv = iasecc_select_mf(card, NULL); + LOG_TEST_RET(ctx, rv, "MF invalid"); + } + if (se->reference > IASECC_SE_REF_MAX) LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS); From 2c88f9dfe852fad0f0ba1a42adb0c8e683177a82 Mon Sep 17 00:00:00 2001 From: Vincent JARDIN Date: Mon, 29 Mar 2021 16:55:03 +0000 Subject: [PATCH 2/2] IASECC/CPX: Fix SDO path Some objects need to be read from a specific path. IASECC_SDO_PRVKEY_TAG: from 3F00:0001 IASECC_SDO_CHV_TAG: from 3F00 --- src/libopensc/card-iasecc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/libopensc/card-iasecc.c b/src/libopensc/card-iasecc.c index 7dfa3ad780..40abed06b9 100644 --- a/src/libopensc/card-iasecc.c +++ b/src/libopensc/card-iasecc.c @@ -2871,6 +2871,34 @@ iasecc_sdo_get_tagged_data(struct sc_card *card, int sdo_tag, struct iasecc_sdo LOG_FUNC_CALLED(ctx); + sc_log(ctx, "sdo_tag=0x%x sdo_ref=0x%x sdo_class=0x%x", sdo_tag, + sdo->sdo_ref, sdo->sdo_class); + + /* XXX: for the CPx, the SDO are available from some specific path */ + if (iasecc_is_cpx(card)) { + struct sc_path path; + char *path_str = NULL; + switch(sdo_tag) { + case IASECC_SDO_PRVKEY_TAG: + /* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 90 02 03 7F 48 80 */ + path_str = "3F00:0001"; + break; + case IASECC_SDO_CHV_TAG: + /* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 81 01 03 7F 41 80 */ + path_str = "3F00"; + break; + default: + path_str = NULL; + break; + } + if (path_str) { + sc_log(ctx, "Warning: Enforce the path=%s", path_str); + sc_format_path(path_str, &path); + rv = iasecc_select_file(card, &path, NULL); + LOG_TEST_RET(ctx, rv, "path error"); + } + } + sbuf[offs--] = 0x80; sbuf[offs--] = sdo_tag & 0xFF; if ((sdo_tag >> 8) & 0xFF)