From 67b340d838533bee75ff39657615b1ab5c2e0114 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 14 Jan 2023 12:26:30 +0100 Subject: [PATCH] swapped to ISO7816 defines --- client/src/emv/emvcore.c | 13 ++++++------- client/src/iso7816/iso7816core.c | 5 ++--- client/src/ksx6924/ksx6924core.c | 9 +++++---- client/src/mifare/desfirecore.c | 24 ++++++++++++------------ 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/client/src/emv/emvcore.c b/client/src/emv/emvcore.c index 17aa2610e..34aa4d4be 100644 --- a/client/src/emv/emvcore.c +++ b/client/src/emv/emvcore.c @@ -17,13 +17,11 @@ //----------------------------------------------------------------------------- #include "emvcore.h" - #include - -#include "commonutil.h" // ARRAYLEN -#include "comms.h" // DropField +#include "commonutil.h" // ARRAYLEN +#include "comms.h" // DropField #include "cmdparser.h" -#include "cmdsmartcard.h" // ExchangeAPDUSC +#include "cmdsmartcard.h" // ExchangeAPDUSC #include "ui.h" #include "cmdhf14a.h" #include "cmdhf14b.h" @@ -31,6 +29,7 @@ #include "emv_tags.h" #include "emvjson.h" #include "util_posix.h" +#include "protocols.h" // ISO7816 APDU return codes // Got from here. Thanks! // https://eftlab.co.uk/index.php/site-map/knowledge-base/211-emv-aid-rid-pix @@ -392,7 +391,7 @@ int EMVSearchPSE(Iso7816CommandChannel channel, bool ActivateField, bool LeaveFi res = EMVSelectPSE(channel, ActivateField, true, PSENum, data, sizeof(data), &datalen, &sw); if (!res) { - if (sw != 0x9000) { + if (sw != ISO7816_OK) { PrintAndLogEx(FAILED, "Select PSE error. APDU error: %04x.", sw); return 1; } @@ -419,7 +418,7 @@ int EMVSearchPSE(Iso7816CommandChannel channel, bool ActivateField, bool LeaveFi } // error catch! - if (sw != 0x9000) { + if (sw != ISO7816_OK) { sfidatalen[ui] = 0; PrintAndLogEx(FAILED, "PPSE get Error. APDU error: %04x.", sw); break; diff --git a/client/src/iso7816/iso7816core.c b/client/src/iso7816/iso7816core.c index 5db7d32aa..7e0dd2c7f 100644 --- a/client/src/iso7816/iso7816core.c +++ b/client/src/iso7816/iso7816core.c @@ -17,9 +17,7 @@ //----------------------------------------------------------------------------- #include "iso7816core.h" - #include - #include "commonutil.h" // ARRAYLEN #include "comms.h" // DropField #include "cmdparser.h" @@ -29,6 +27,7 @@ #include "cmdhf14b.h" #include "iso14b.h" // iso14b_raw_cmd_t #include "util_posix.h" +#include "protocols.h" // ISO7816 APDU return codes //iceman: this logging setting, should be unified with client debug etc. static bool APDULogging = false; @@ -170,7 +169,7 @@ int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool activate_field, bool l *sw = isw; } - if (isw != 0x9000) { + if (isw != ISO7816_OK) { if (APDULogging) { if (*sw >> 8 == 0x61) { PrintAndLogEx(ERR, "APDU chaining len %02x", *sw & 0xFF); diff --git a/client/src/ksx6924/ksx6924core.c b/client/src/ksx6924/ksx6924core.c index b04f87358..39b390039 100644 --- a/client/src/ksx6924/ksx6924core.c +++ b/client/src/ksx6924/ksx6924core.c @@ -38,6 +38,7 @@ #include "util.h" #include "comms.h" // clearCommandBuffer #include "commonutil.h" // ntohl (pm3 version) +#include "protocols.h" // ISO7816 APDU return codes // Date type. This is the actual on-card format. typedef struct { @@ -402,7 +403,7 @@ bool KSX6924TrySelect(void) { return false; } - if (sw != 0x9000) { + if (sw != ISO7816_OK) { if (sw) { PrintAndLogEx(FAILED, "Not a KS X 6924 card! APDU response: %04x - %s", @@ -444,7 +445,7 @@ bool KSX6924GetBalance(uint32_t *result) { return false; } - if (sw != 0x9000) { + if (sw != ISO7816_OK) { return false; } @@ -476,7 +477,7 @@ bool KSX6924InitializeCard(uint8_t mpda1, uint8_t mpda2, uint8_t mpda3, uint8_t return false; } - if (sw != 0x9000) { + if (sw != ISO7816_OK) { return false; } @@ -574,7 +575,7 @@ bool KSX6924ProprietaryGetRecord(uint8_t id, uint8_t *result, size_t result_len) return false; } - if (sw != 0x9000) { + if (sw != ISO7816_OK) { return false; } diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index ab572b4d0..3e002a7ef 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -32,9 +32,9 @@ #include "aes.h" #include "ui.h" #include "crc.h" -#include "crc16.h" // crc16 ccitt +#include "crc16.h" // crc16 ccitt #include "crc32.h" -#include "protocols.h" +#include "protocols.h" // ISO7816 APDU return codes #include "cmdhf14a.h" #include "iso7816/apduinfo.h" // APDU manipulation / errorcodes #include "iso7816/iso7816core.h" // APDU logging @@ -470,7 +470,7 @@ static int DESFIRESendApduEx(bool activate_field, sAPDU_t apdu, uint16_t le, uin if (sw) *sw = isw; - if (isw != 0x9000 && + if (isw != ISO7816_OK && isw != DESFIRE_GET_ISO_STATUS(MFDES_S_OPERATION_OK) && isw != DESFIRE_GET_ISO_STATUS(MFDES_S_SIGNATURE) && isw != DESFIRE_GET_ISO_STATUS(MFDES_S_ADDITIONAL_FRAME) && @@ -1655,7 +1655,7 @@ static bool DesfireCheckISOAuthCmd(DesfireISOSelectWay way, uint32_t appID, char uint8_t p2 = ((app_level) ? 0x80 : 0x00) | keyNum; res = DesfireExchangeISO(false, &dctx, (sAPDU_t) {0x00, ISO7816_EXTERNAL_AUTHENTICATION, p1, p2, rndlen * 2, piccrnd}, 0, resp, &resplen, &sw); DropField(); - return (sw == 0x9000 || sw == 0x6982); + return (sw == ISO7816_OK || sw == ISO7816_SECURITY_STATUS_NOT_SATISFIED); } void DesfireCheckAuthCommands(DesfireISOSelectWay way, uint32_t appID, char *dfname, uint8_t keyNum, AuthCommandsChk_t *authCmdCheck) { @@ -2859,7 +2859,7 @@ int DesfireISOSelectEx(DesfireContext_t *dctx, bool fieldon, DesfireISOSelectCon size_t xresplen = 0; uint16_t sw = 0; int res = DesfireExchangeISO(fieldon, dctx, (sAPDU_t) {0x00, ISO7816_SELECT_FILE, cntr, ((resp == NULL) ? 0x0C : 0x00), datalen, data}, APDU_INCLUDE_LE_00, xresp, &xresplen, &sw); - if (res == PM3_SUCCESS && sw != 0x9000) + if (res == PM3_SUCCESS && sw != ISO7816_OK) return PM3_ESOFT; if (resp != NULL && resplen != NULL) { @@ -2885,7 +2885,7 @@ int DesfireISOSelectDF(DesfireContext_t *dctx, char *dfname, uint8_t *resp, size int DesfireISOGetChallenge(DesfireContext_t *dctx, DesfireCryptoAlgorithm keytype, uint8_t *resp, size_t *resplen) { uint16_t sw = 0; int res = DesfireExchangeISO(false, dctx, (sAPDU_t) {0x00, ISO7816_GET_CHALLENGE, 0x00, 0x00, 0x00, NULL}, DesfireGetRndLenForKey(keytype), resp, resplen, &sw); - if (res == PM3_SUCCESS && sw != 0x9000) + if (res == PM3_SUCCESS && sw != ISO7816_OK) return PM3_ESOFT; return res; @@ -2900,7 +2900,7 @@ int DesfireISOExternalAuth(DesfireContext_t *dctx, bool app_level, uint8_t keynu uint16_t sw = 0; int res = DesfireExchangeISO(false, dctx, (sAPDU_t) {0x00, ISO7816_EXTERNAL_AUTHENTICATION, p1, p2, DesfireGetRndLenForKey(keytype) * 2, data}, 0, resp, &resplen, &sw); - if (res == PM3_SUCCESS && sw != 0x9000) + if (res == PM3_SUCCESS && sw != ISO7816_OK) return PM3_ESOFT; return res; @@ -2913,7 +2913,7 @@ int DesfireISOInternalAuth(DesfireContext_t *dctx, bool app_level, uint8_t keynu uint16_t sw = 0; int res = DesfireExchangeISO(false, dctx, (sAPDU_t) {0x00, ISO7816_INTERNAL_AUTHENTICATION, p1, p2, keylen, data}, keylen * 2, resp, resplen, &sw); - if (res == PM3_SUCCESS && sw != 0x9000) + if (res == PM3_SUCCESS && sw != ISO7816_OK) return PM3_ESOFT; return res; @@ -2929,7 +2929,7 @@ int DesfireISOReadBinary(DesfireContext_t *dctx, bool use_file_id, uint8_t filei uint16_t sw = 0; int res = DesfireExchangeISO(false, dctx, (sAPDU_t) {0x00, ISO7816_READ_BINARY, p1, p2, 0, NULL}, (length == 0) ? APDU_INCLUDE_LE_00 : length, resp, resplen, &sw); - if (res == PM3_SUCCESS && sw != 0x9000) + if (res == PM3_SUCCESS && sw != ISO7816_OK) return PM3_ESOFT; return res; @@ -2948,7 +2948,7 @@ int DesfireISOUpdateBinary(DesfireContext_t *dctx, bool use_file_id, uint8_t fil uint16_t sw = 0; int res = DesfireExchangeISO(false, dctx, (sAPDU_t) {0x00, ISO7816_UPDATE_BINARY, p1, p2, datalen, data}, 0, resp, &resplen, &sw); - if (res == PM3_SUCCESS && sw != 0x9000) + if (res == PM3_SUCCESS && sw != ISO7816_OK) return PM3_ESOFT; return res; @@ -2959,7 +2959,7 @@ int DesfireISOReadRecords(DesfireContext_t *dctx, uint8_t recordnum, bool read_a uint16_t sw = 0; int res = DesfireExchangeISO(false, dctx, (sAPDU_t) {0x00, ISO7816_READ_RECORDS, recordnum, p2, 0, NULL}, (length == 0) ? APDU_INCLUDE_LE_00 : length, resp, resplen, &sw); - if (res == PM3_SUCCESS && sw != 0x9000) + if (res == PM3_SUCCESS && sw != ISO7816_OK) return PM3_ESOFT; return res; @@ -2973,7 +2973,7 @@ int DesfireISOAppendRecord(DesfireContext_t *dctx, uint8_t fileid, uint8_t *data uint16_t sw = 0; int res = DesfireExchangeISO(false, dctx, (sAPDU_t) {0x00, ISO7816_APPEND_RECORD, 0x00, p2, datalen, data}, 0, resp, &resplen, &sw); - if (res == PM3_SUCCESS && sw != 0x9000) + if (res == PM3_SUCCESS && sw != ISO7816_OK) return PM3_ESOFT; return res;