From e05c479ad6f25b40eba6f73b230e90e4c0047c1c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2026 11:46:37 +0700 Subject: [PATCH] hf gp: label the default applet, fail when every SELECT is accepted hf gp info also tries the OpenPlatform card manager AID A000000003000000 before falling back to the default applet. That fallback now warns and is titled "Default applet" instead of "Security Domain". hf gp aids returns PM3_ESOFT when the card accepts any SELECT, instead of PM3_SUCCESS. Co-Authored-By: Claude Opus 5.5 --- client/src/cmdhfgp.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/client/src/cmdhfgp.c b/client/src/cmdhfgp.c index 7f5fd09a8..2b89a07ba 100644 --- a/client/src/cmdhfgp.c +++ b/client/src/cmdhfgp.c @@ -500,6 +500,7 @@ int gp_find_aids(Iso7816CommandChannel channel, const uint8_t *prefix, size_t pr if (hit) { PrintAndLogEx(FAILED, "Card answers any SELECT, cannot tell real AIDs apart"); PrintAndLogEx(HINT, "Hint: try `" _YELLOW_("hf 14a info -s") "` instead"); + res = PM3_ESOFT; goto out; } @@ -657,7 +658,9 @@ static int CmdHFGPAids(const char *Cmd) { return res; } +// GP ISD, then the OpenPlatform / Visa card manager of older cards static const uint8_t gp_isd_aid[] = {0xA0, 0x00, 0x00, 0x01, 0x51, 0x00, 0x00, 0x00}; +static const uint8_t gp_op_isd_aid[] = {0xA0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00}; // first TLV with tag in buf[0..len), value returned in *val / *vlen static bool gp_tlv_find(const uint8_t *buf, size_t len, tlv_tag_t tag, const uint8_t **val, size_t *vlen) { @@ -984,8 +987,19 @@ int gp_info(Iso7816CommandChannel channel, bool verbose) { return PM3_ECARDEXCHANGE; } - // ISD with a non-default AID, the default applet usually is the ISD if (sw != ISO7816_OK) { + sAPDU_t op = {0x00, 0xA4, 0x04, 0x00, sizeof(gp_op_isd_aid), (uint8_t *)gp_op_isd_aid}; + res = Iso7816ExchangeEx(channel, false, true, op, true, 0, resp, sizeof(resp), &resp_len, &sw); + if (res != PM3_SUCCESS && sw == 0) { + PrintAndLogEx(FAILED, "Exchange failed"); + DropFieldEx(channel); + return PM3_ECARDEXCHANGE; + } + } + + // ISD with a non-default AID, the default applet may be the ISD, or not + bool isd = (sw == ISO7816_OK); + if (isd == false) { sAPDU_t def = {0x00, 0xA4, 0x04, 0x00, 0, NULL}; res = Iso7816ExchangeEx(channel, false, true, def, true, 0, resp, sizeof(resp), &resp_len, &sw); if ((res != PM3_SUCCESS && sw == 0) || sw != ISO7816_OK) { @@ -993,10 +1007,15 @@ int gp_info(Iso7816CommandChannel channel, bool verbose) { DropFieldEx(channel); return PM3_ESOFT; } + PrintAndLogEx(WARNING, "ISD not selectable by AID, data below is from the default applet"); } PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "--- " _CYAN_("Security Domain") " ----------------------"); + if (isd) { + PrintAndLogEx(INFO, "--- " _CYAN_("Security Domain") " ----------------------"); + } else { + PrintAndLogEx(INFO, "--- " _CYAN_("Default applet") " -----------------------"); + } const uint8_t *name = NULL; size_t name_len = 0;