From e1a7b61b1ffd5339d79761ad9b9670e37c076219 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Thu, 15 Apr 2021 19:51:24 +0300 Subject: [PATCH 1/3] show some general crypto description --- client/src/emv/cmdemv.c | 21 +++++++++++++++++++-- client/src/emv/emv_tags.c | 14 +++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/client/src/emv/cmdemv.c b/client/src/emv/cmdemv.c index 83f268f57..fd02528a6 100644 --- a/client/src/emv/cmdemv.c +++ b/client/src/emv/cmdemv.c @@ -1076,13 +1076,30 @@ static int CmdEMVExec(const char *Cmd) { PrintAndLogEx(NORMAL, "AC: %s", sprint_hex(AC->value, AC->len)); if (IAD) { PrintAndLogEx(NORMAL, "IAD: %s", sprint_hex(IAD->value, IAD->len)); - - if (IAD->len >= IAD->value[0] + 1) { + + // https://mst-company.ru/blog/ekvajring-emv-tranzaktsiya-emv-transaction-flow-chast-4-pdol-i-beskontaktnye-karty-osobennosti-qvsdc-i-quics + if (IAD->value[0] == 0x1f) { + PrintAndLogEx(NORMAL, "\tKey index: 0x%02x", IAD->value[2]); + PrintAndLogEx(NORMAL, "\tCrypto ver: 0x%02x(%03d)", IAD->value[1], IAD->value[1]); + PrintAndLogEx(NORMAL, "\tCVR: %s", sprint_hex(&IAD->value[3], 5)); + struct tlvdb *cvr = tlvdb_fixed(0x20, 5, &IAD->value[3]); + TLVPrintFromTLVLev(cvr, 1); + PrintAndLogEx(NORMAL, "\tIDD option id: 0x%02x", IAD->value[8]); + PrintAndLogEx(NORMAL, "\tIDD: %s", sprint_hex(&IAD->value[9], 23)); + } else if (IAD->len >= IAD->value[0] + 1) { PrintAndLogEx(NORMAL, "\tKey index: 0x%02x", IAD->value[1]); PrintAndLogEx(NORMAL, "\tCrypto ver: 0x%02x(%03d)", IAD->value[2], IAD->value[2]); PrintAndLogEx(NORMAL, "\tCVR: %s", sprint_hex(&IAD->value[3], IAD->value[0] - 2)); struct tlvdb *cvr = tlvdb_fixed(0x20, IAD->value[0] - 2, &IAD->value[3]); TLVPrintFromTLVLev(cvr, 1); + if (IAD->len >= 8) { + int iddLen = IAD->value[7]; + PrintAndLogEx(NORMAL, "\tIDD length: %d", iddLen); + if (iddLen >= 1) + PrintAndLogEx(NORMAL, "\tIDD option id: 0x%02x", IAD->value[8]); + if (iddLen >= 2) + PrintAndLogEx(NORMAL, "\tIDD: %s", sprint_hex(&IAD->value[9], iddLen - 1)); + } } } else { PrintAndLogEx(WARNING, "WARNING: IAD not found."); diff --git a/client/src/emv/emv_tags.c b/client/src/emv/emv_tags.c index 5bdecc665..acafa18d3 100644 --- a/client/src/emv/emv_tags.c +++ b/client/src/emv/emv_tags.c @@ -557,7 +557,7 @@ static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, i return; } - if (tlv->len != tlv->value[0] + 1) { + if (tlv->len != 5 && tlv->len != tlv->value[0] + 1) { PrintAndLogEx(INFO, "%*s" NOLF, (level * 4), " "); PrintAndLogEx(NORMAL, " INVALID length!"); return; @@ -581,6 +581,14 @@ static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, i PrintAndLogEx(INFO, "%*s" NOLF, (level * 4), " "); PrintAndLogEx(NORMAL, " PIN try: %x", tlv->value[2] >> 4); } + if (tlv->len >= 3 && (tlv->value[2] & 0x40)) { + PrintAndLogEx(INFO, "%*s" NOLF, (level * 4), " "); + PrintAndLogEx(NORMAL, " PIN try exceeded"); + } + if (tlv->len >= 4 && (tlv->value[3] >> 4)) { + PrintAndLogEx(INFO, "%*s" NOLF, (level * 4), " "); + PrintAndLogEx(NORMAL, " Issuer script counter: %x", tlv->value[3] >> 4); + } if (tlv->len >= 4 && (tlv->value[3] & 0x0F)) { PrintAndLogEx(INFO, "%*s" NOLF, (level * 4), " "); PrintAndLogEx(NORMAL, " Issuer discretionary bits: %x", tlv->value[3] & 0x0F); @@ -589,6 +597,10 @@ static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, i PrintAndLogEx(INFO, "%*s" NOLF, (level * 4), " "); PrintAndLogEx(NORMAL, " Successfully processed issuer script commands: %x", tlv->value[4] >> 4); } + if (tlv->len >= 5 && (tlv->value[4] & 0x02)) { + PrintAndLogEx(INFO, "%*s" NOLF, (level * 4), " "); + PrintAndLogEx(NORMAL, " CDCVM OK"); + } // mask 0F 0F F0 0F uint8_t data[20] = {0}; From f4f602324dbe9697eac6a41206cbbe186435e644 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Thu, 15 Apr 2021 19:53:52 +0300 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c9b851a2..ef3269c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Change emv commands now works with tokenized cards (@merlokk) - Change `hf 15 restore` - now also support EML/JSON (@iceman1001) - Change - all commands now use cliparser (@iceman1001) - Change `lf t55xx restore` - now also support JSON (@iceman1001) From b627934fb42871c1e7aa9265e169af2c6a02f6d6 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Thu, 15 Apr 2021 19:56:20 +0300 Subject: [PATCH 3/3] fix tabs --- client/src/emv/cmdemv.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/client/src/emv/cmdemv.c b/client/src/emv/cmdemv.c index fd02528a6..9a1c4aa76 100644 --- a/client/src/emv/cmdemv.c +++ b/client/src/emv/cmdemv.c @@ -1079,26 +1079,26 @@ static int CmdEMVExec(const char *Cmd) { // https://mst-company.ru/blog/ekvajring-emv-tranzaktsiya-emv-transaction-flow-chast-4-pdol-i-beskontaktnye-karty-osobennosti-qvsdc-i-quics if (IAD->value[0] == 0x1f) { - PrintAndLogEx(NORMAL, "\tKey index: 0x%02x", IAD->value[2]); - PrintAndLogEx(NORMAL, "\tCrypto ver: 0x%02x(%03d)", IAD->value[1], IAD->value[1]); - PrintAndLogEx(NORMAL, "\tCVR: %s", sprint_hex(&IAD->value[3], 5)); + PrintAndLogEx(NORMAL, " Key index: 0x%02x", IAD->value[2]); + PrintAndLogEx(NORMAL, " Crypto ver: 0x%02x(%03d)", IAD->value[1], IAD->value[1]); + PrintAndLogEx(NORMAL, " CVR: %s", sprint_hex(&IAD->value[3], 5)); struct tlvdb *cvr = tlvdb_fixed(0x20, 5, &IAD->value[3]); TLVPrintFromTLVLev(cvr, 1); - PrintAndLogEx(NORMAL, "\tIDD option id: 0x%02x", IAD->value[8]); - PrintAndLogEx(NORMAL, "\tIDD: %s", sprint_hex(&IAD->value[9], 23)); + PrintAndLogEx(NORMAL, " IDD option id: 0x%02x", IAD->value[8]); + PrintAndLogEx(NORMAL, " IDD: %s", sprint_hex(&IAD->value[9], 23)); } else if (IAD->len >= IAD->value[0] + 1) { - PrintAndLogEx(NORMAL, "\tKey index: 0x%02x", IAD->value[1]); - PrintAndLogEx(NORMAL, "\tCrypto ver: 0x%02x(%03d)", IAD->value[2], IAD->value[2]); - PrintAndLogEx(NORMAL, "\tCVR: %s", sprint_hex(&IAD->value[3], IAD->value[0] - 2)); + PrintAndLogEx(NORMAL, " Key index: 0x%02x", IAD->value[1]); + PrintAndLogEx(NORMAL, " Crypto ver: 0x%02x(%03d)", IAD->value[2], IAD->value[2]); + PrintAndLogEx(NORMAL, " CVR: %s", sprint_hex(&IAD->value[3], IAD->value[0] - 2)); struct tlvdb *cvr = tlvdb_fixed(0x20, IAD->value[0] - 2, &IAD->value[3]); TLVPrintFromTLVLev(cvr, 1); if (IAD->len >= 8) { int iddLen = IAD->value[7]; - PrintAndLogEx(NORMAL, "\tIDD length: %d", iddLen); + PrintAndLogEx(NORMAL, " IDD length: %d", iddLen); if (iddLen >= 1) - PrintAndLogEx(NORMAL, "\tIDD option id: 0x%02x", IAD->value[8]); + PrintAndLogEx(NORMAL, " IDD option id: 0x%02x", IAD->value[8]); if (iddLen >= 2) - PrintAndLogEx(NORMAL, "\tIDD: %s", sprint_hex(&IAD->value[9], iddLen - 1)); + PrintAndLogEx(NORMAL, " IDD: %s", sprint_hex(&IAD->value[9], iddLen - 1)); } } } else {