laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/43238?usp=email )
Change subject: sim: fix APDU case detection for EMV commands under CLA=0x80 ......................................................................
sim: fix APDU case detection for EMV commands under CLA=0x80
osim_determine_apdu_case() looks up uicc_ins_tbl_80 to classify APDUs, which only covered SIM/UICC/GlobalPlatform instructions. Two gaps broke real EMV contact transactions relayed through simtrace2-cardem-pcsc:
- GPO (0xA8) and GENERATE AC (0xAE) were missing entirely, causing "FATAL: Unknown APDU case 0" and killing the cardem process mid transaction. - GET DATA (0xCA) fell through to gp_cla_ins_helper()'s P3==0 heuristic, which misclassifies EMV's standard 6Cxx-retry pattern (retry has P3 != 0) as case 4 instead of case 2, hanging on GET DATA 9F17 (PIN Try Counter).
Adding explicit CLA=0x80 entries for these three instructions, checked before the ambiguous GP heuristic, fixes both.
Change-Id: I6424397cb888f372fb44b4e984adf3ab8f4cd40b --- M src/sim/class_tables.c 1 file changed, 9 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/38/43238/1
diff --git a/src/sim/class_tables.c b/src/sim/class_tables.c index 7500fc5..c510f73 100644 --- a/src/sim/class_tables.c +++ b/src/sim/class_tables.c @@ -238,6 +238,15 @@ [0x14] = 3, /* TERMINAL RESPONSE */ [0x76] = 4, /* SUSPEND UICC */ [0x7A] = 4, /* EXCHANGE CAPABILITIES */ + /* EMV (Book 3, Table 3) proprietary CLA=0x80 commands, not covered by any ETSI/GP table */ + [0xA8] = 4, /* GET PROCESSING OPTIONS */ + [0xAE] = 4, /* GENERATE APPLICATION CRYPTOGRAM */ + /* EMV GET DATA (Book 3, 6.5.7) is always case 2 (Le only, never Lc), unlike + * GlobalPlatform's overloaded 0xCA which gp_cla_ins_helper() disambiguates by + * P3==0 vs !=0 -- that heuristic misclassifies the standard EMV 6Cxx-retry + * pattern (first try Le=00, retry Le=<actual length>) as case 4. Matching here + * (exact CLA=0x80) takes priority over the broader 0xF0-masked GP entries. */ + [0xCA] = 2, /* GET DATA */ };
/* Card Specification v2.3.1*/