diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 904f2adab..f257e9354 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -1984,8 +1984,7 @@ static int CmdHF14ADesAuth(const char *Cmd) { SetAPDULogging(APDULogging); CLIParserFree(ctx); - //res = DesfireSelectAndAuthenticateISO(&dctx, securechann, (appid != 0), appid, appisoid, false, 0, noauth, verbose); - res = DesfireSelectAndAuthenticateEx(&dctx, securechann, id, false, verbose); + res = DesfireSelectAndAuthenticateW(&dctx, securechann, selectway, id, false, 0, false, verbose); if (res != PM3_SUCCESS) { DropField(); PrintAndLogEx(FAILED, "Select or authentication %s 0x%06x " _RED_("failed") ". Result [%d] %s", DesfireSelectWayToStr(selectway), id, res, DesfireAuthErrorToStr(res)); @@ -1995,7 +1994,7 @@ static int CmdHF14ADesAuth(const char *Cmd) { if (DesfireMFSelected(selectway, id)) PrintAndLogEx(SUCCESS, "PICC selected and authenticated " _GREEN_("succesfully")); else - PrintAndLogEx(SUCCESS, "Application %s " _CYAN_("%06x") " selected and authenticated " _GREEN_("succesfully"), DesfireSelectWayToStr(selectway), id); + PrintAndLogEx(SUCCESS, "Application %s " _CYAN_("%0*x") " selected and authenticated " _GREEN_("succesfully"), DesfireSelectWayToStr(selectway), selectway == ISW6bAID ? 6 : 4, id); PrintAndLogEx(SUCCESS, _CYAN_("Context: ")); DesfirePrintContext(&dctx); diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index f9725887a..fbdde02e5 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -965,44 +965,44 @@ int DesfireSelectAndAuthenticate(DesfireContext *dctx, DesfireSecureChannel secu return DesfireSelectAndAuthenticateEx(dctx, secureChannel, aid, false, verbose); } -int DesfireSelectAndAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool useaid, uint32_t aid, uint16_t isoappid, bool selectfile, uint16_t isofileid, bool noauth, bool verbose) { +int DesfireSelectAndAuthenticateW(DesfireContext *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool selectfile, uint16_t isofileid, bool noauth, bool verbose) { if (verbose) DesfirePrintContext(dctx); int res = 0; - if (useaid) { + if (way == ISW6bAID && dctx->cmdSet == DCCISO) { dctx->cmdSet = DCCNativeISO; if (verbose) PrintAndLogEx(INFO, "Select via " _CYAN_("native iso wrapping") " interface"); - res = DesfireSelectAIDHex(dctx, aid, false, 0); + res = DesfireSelectAIDHex(dctx, id, false, 0); if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, "Desfire select " _RED_("error") "."); return 200; } if (verbose) - PrintAndLogEx(INFO, "App %06x via native iso channel is " _GREEN_("selected"), aid); + PrintAndLogEx(INFO, "App %06x via native iso channel is " _GREEN_("selected"), id); dctx->cmdSet = DCCISO; } else { - res = DesfireSelectEx(dctx, true, ISWIsoID, isoappid, NULL); + res = DesfireSelectEx(dctx, true, way, id, NULL); if (res != PM3_SUCCESS) { - PrintAndLogEx(ERR, "Desfire iso application select " _RED_("error") "."); + PrintAndLogEx(ERR, "Desfire %s select " _RED_("error") ".", DesfireSelectWayToStr(way)); return 202; } if (verbose) - PrintAndLogEx(INFO, "Application iso id %04x is " _GREEN_("selected"), isoappid); + PrintAndLogEx(INFO, "%s %0*x is " _GREEN_("selected"), DesfireSelectWayToStr(way), way == ISW6bAID ? 6 : 4, id); + } - if (selectfile) { - res = DesfireSelectEx(dctx, false, ISWIsoID, isofileid, NULL); - if (res != PM3_SUCCESS) { - PrintAndLogEx(ERR, "Desfire iso file select " _RED_("error") "."); - return 203; - } - - if (verbose) - PrintAndLogEx(INFO, "Application iso id %04x file iso id %04x is " _GREEN_("selected"), isoappid, isofileid); + if (selectfile) { + res = DesfireSelectEx(dctx, false, ISWIsoID, isofileid, NULL); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Desfire iso file select " _RED_("error") "."); + return 203; } + + if (verbose) + PrintAndLogEx(INFO, "Application %s %04x file iso id %04x is " _GREEN_("selected"), DesfireSelectWayToStr(way), id, isofileid); } if (!noauth) { @@ -1023,6 +1023,10 @@ int DesfireSelectAndAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel s return PM3_SUCCESS; } +int DesfireSelectAndAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool useaid, uint32_t aid, uint16_t isoappid, bool selectfile, uint16_t isofileid, bool noauth, bool verbose) { + return DesfireSelectAndAuthenticateW(dctx, secureChannel, useaid ? ISW6bAID : ISWIsoID, useaid ? aid : isoappid, selectfile, isofileid, noauth, verbose); +} + static int DesfireAuthenticateEV1(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool verbose) { // 3 different way to authenticate AUTH (CRC16) , AUTH_ISO (CRC32) , AUTH_AES (CRC32) // 4 different crypto arg1 DES, 3DES, 3K3DES, AES diff --git a/client/src/mifare/desfirecore.h b/client/src/mifare/desfirecore.h index 8efc3052e..300ebe8d6 100644 --- a/client/src/mifare/desfirecore.h +++ b/client/src/mifare/desfirecore.h @@ -178,6 +178,7 @@ int DesfireSelect(DesfireContext *ctx, DesfireISOSelectWay way, uint32_t id, cha const char *DesfireAuthErrorToStr(int error); int DesfireSelectAndAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool verbose); int DesfireSelectAndAuthenticateEx(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool noauth, bool verbose); +int DesfireSelectAndAuthenticateW(DesfireContext *dctx, DesfireSecureChannel secureChannel, DesfireISOSelectWay way, uint32_t id, bool selectfile, uint16_t isofileid, bool noauth, bool verbose); int DesfireSelectAndAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool useaid, uint32_t aid, uint16_t isoappid, bool selectfile, uint16_t isofileid, bool noauth, bool verbose); int DesfireAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, bool verbose); void DesfireCheckAuthCommands(uint32_t appAID, char *dfname, uint8_t keyNum, AuthCommandsChk *authCmdCheck);