From b6a65405a06413f7ce513159521e7a8028aaf5ea Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Mon, 19 Jul 2021 19:05:07 +0300 Subject: [PATCH] remove debug --- client/src/cmdhfmfdes.c | 110 -------------------------- client/src/mifare/desfirecore.c | 11 +-- client/src/mifare/desfiresecurechan.c | 4 - 3 files changed, 1 insertion(+), 124 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index e8fb349e0..6b429cd47 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -4977,7 +4977,6 @@ static int CmdHF14ADesChangeKey(const char *Cmd) { if (appid == 0x000000) { PrintAndLogEx(WARNING, "Changing the root aid (0x000000)"); - return PM3_ESOFT; // TODO!!!! } if (appid) @@ -5007,115 +5006,6 @@ static int CmdHF14ADesChangeKey(const char *Cmd) { DropField(); return res; - - return PM3_SUCCESS; - - - - - - - - - - - - - - - /* CLIParserContext *ctx; - CLIParserInit(&ctx, "hf mfdes changekey", - "Change MIFARE DESFire Key.\n" - "Make sure to select aid or authenticate aid before running this command.", - "hf mfdes changekey -n 0 -t 1 -k 0000000000000000 -u 1 -j 0102030405060708 -> DES, keynumber 0" - ); - - void *argtable[] = { - arg_param_begin, - arg_int0("n", "keyno", "", "Key number used for authentification"), - arg_int0("t", "algo", "", "Current key algo (1 = DES, 2 = 3DES(2K2DES), 3 = 3K3DES, 4 = AES)"), - arg_str0("k", "key", "", "Current Key (HEX 8-24 bytes)"), - arg_int0("u", "newalgo", "", "New key algo (1 = DES, 2 = 3DES(2K2DES), 3 = 3K3DES, 4 = AES)"), - arg_str0("j", "newkey", "", "New Key (HEX 8-24 bytes)"), - arg_int0("v", "aesver", "", "AES version (if AES is used)"), - arg_param_end - }; - CLIExecWithReturn(ctx, Cmd, argtable, false); - - uint8_t cmdKeyNo = arg_get_int_def(ctx, 1, 0); - uint8_t cmdAuthAlgo = arg_get_int_def(ctx, 2, 0); - uint8_t key[24] = {0}; - int keylen = 0; - int res_klen = CLIParamHexToBuf(arg_get_str(ctx, 3), key, 24, &keylen); - - uint8_t newcmdAuthAlgo = arg_get_int_def(ctx, 4, 0); - uint8_t newkey[24] = {0}; - int newkeylen = 0; - int res_newklen = CLIParamHexToBuf(arg_get_str(ctx, 5), newkey, 24, &newkeylen); - - uint8_t aesversion = arg_get_int_def(ctx, 6, 0); - CLIParserFree(ctx); - - //DropFieldDesfire(); - // NR DESC KEYLENGHT - // ------------------------ - // 1 = DES 8 - // 2 = 3DES 16 - // 3 = 3K 3DES 24 - // 4 = AES 16 - uint8_t keylength = 8; - if (cmdAuthAlgo == MFDES_ALGO_AES) { - keylength = 16; - } else if (cmdAuthAlgo == MFDES_ALGO_3DES) { - keylength = 16; - } else if (cmdAuthAlgo == MFDES_ALGO_DES) { - keylength = 8; - } else if (cmdAuthAlgo == MFDES_ALGO_3K3DES) { - keylength = 24; - } - - uint8_t newkeylength = 8; - if (newcmdAuthAlgo == MFDES_ALGO_AES) { - newkeylength = 16; - } else if (newcmdAuthAlgo == MFDES_ALGO_3DES) { - newkeylength = 16; - } else if (newcmdAuthAlgo == MFDES_ALGO_DES) { - newkeylength = 8; - } else if (newcmdAuthAlgo == MFDES_ALGO_3K3DES) { - newkeylength = 24; - } - - if (res_klen || (keylen < 8) || (keylen > 24)) { - PrintAndLogEx(ERR, "Specified key must have %d bytes length", keylen); - return PM3_EINVARG; - } - - if (res_newklen || (newkeylen < 8) || (newkeylen > 24)) { - PrintAndLogEx(ERR, "Specified new key must have %d bytes length", newkeylen); - return PM3_EINVARG; - } - - if (keylen != keylength) { - PrintAndLogEx(WARNING, "Key must include %d hex symbols, got %d", keylength, keylen); - return PM3_EINVARG; - } - - if (newkeylen != newkeylength) { - PrintAndLogEx(WARNING, "New key must include %d hex symbols, got %d", keylength, newkeylen); - return PM3_EINVARG; - } - - PrintAndLogEx(INFO, "changing key number " _YELLOW_("0x%02x"), cmdKeyNo); - PrintAndLogEx(INFO, "old key: %s ( %s )", sprint_hex_inrow(key, keylen), getEncryptionAlgoStr(cmdAuthAlgo)); - PrintAndLogEx(INFO, "new key: %s ( %s )", sprint_hex_inrow(newkey, newkeylen), getEncryptionAlgoStr(newcmdAuthAlgo)); - - int res = mifare_desfire_change_key(cmdKeyNo, newkey, newcmdAuthAlgo, key, cmdAuthAlgo, aesversion); - if (res == PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "Change key ( " _GREEN_("ok") " )"); - } else { - PrintAndLogEx(FAILED, "Change key ( " _RED_("fail") " )"); - } - return res;*/ } static int CmdHF14ADesCreateApp(const char *Cmd) { diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index 40f77fb03..476728505 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -1123,18 +1123,13 @@ int DesfireChangeKey(DesfireContext *dctx, bool change_master_key, uint8_t newke nkeylen = desfire_get_key_length(T_3DES); } - PrintAndLogEx(SUCCESS, "--oldk [%d]: %s", desfire_get_key_length(oldkeytype), sprint_hex(okeybuf, desfire_get_key_length(oldkeytype))); - PrintAndLogEx(SUCCESS, "--newk [%d]: %s", nkeylen, sprint_hex(nkeybuf, nkeylen)); - // set key version for DES. if newkeyver > 0xff - setting key version is disabled if (newkeytype != T_AES && newkeyver < 0x100) { DesfireDESKeySetVersion(nkeybuf, newkeytype, newkeyver); if (verbose) - PrintAndLogEx(INFO, "changed new key: %s [%d] %s", CLIGetOptionListStr(DesfireAlgoOpts, newkeytype), desfire_get_key_length(newkeytype), sprint_hex(newkey, desfire_get_key_length(newkeytype))); + PrintAndLogEx(INFO, "changed new key: %s [%d] %s", CLIGetOptionListStr(DesfireAlgoOpts, newkeytype), desfire_get_key_length(newkeytype), sprint_hex(nkeybuf, desfire_get_key_length(newkeytype))); } - PrintAndLogEx(SUCCESS, "--newk [%d]: %s", nkeylen, sprint_hex(nkeybuf, nkeylen)); - // xor if we change current auth key if (newkeynum == dctx->keyNum) { memcpy(cdata, nkeybuf, nkeylen); @@ -1145,12 +1140,10 @@ int DesfireChangeKey(DesfireContext *dctx, bool change_master_key, uint8_t newke // add key version for AES size_t cdatalen = nkeylen; - PrintAndLogEx(SUCCESS, "--cdata [%d]: %s kv = 0x%02x", cdatalen, sprint_hex(cdata, cdatalen), newkeyver); if (newkeytype == T_AES) { cdata[cdatalen] = newkeyver; cdatalen++; } - PrintAndLogEx(SUCCESS, "--cdata [%d]: %s", cdatalen, sprint_hex(cdata, cdatalen)); // add crc||crc_new_key if (dctx->secureChannel == DACd40) { @@ -1169,7 +1162,6 @@ int DesfireChangeKey(DesfireContext *dctx, bool change_master_key, uint8_t newke cdatalen += 4; } } - PrintAndLogEx(SUCCESS, "--cdata [%d]: %s", cdatalen, sprint_hex(cdata, cdatalen)); // get padded data length size_t rlen = padded_data_length(cdatalen, desfire_get_key_block_length(newkeytype)); @@ -1177,7 +1169,6 @@ int DesfireChangeKey(DesfireContext *dctx, bool change_master_key, uint8_t newke // send command uint8_t resp[257] = {0}; size_t resplen = 0; - PrintAndLogEx(SUCCESS, "--pckdata [%d]: %s", rlen + 1, sprint_hex(&pckcdata[1], rlen + 1)); int res = DesfireChangeKeyCmd(dctx, &pckcdata[1], rlen + 1, resp, &resplen); // check response diff --git a/client/src/mifare/desfiresecurechan.c b/client/src/mifare/desfiresecurechan.c index 4c3dcd76b..f63659ec1 100644 --- a/client/src/mifare/desfiresecurechan.c +++ b/client/src/mifare/desfiresecurechan.c @@ -167,15 +167,11 @@ static void DesfireSecureChannelEncodeEV1(DesfireContext *ctx, uint8_t cmd, uint if (srcdatalen == 0 || srcdatalen <= hdrlen) return; - PrintAndLogEx(SUCCESS, "--ch hdrlen: %d, cmd: %02x", hdrlen, cmd); - //dstdata[0] = cmd; memcpy(&dstdata[0], srcdata, hdrlen); memcpy(data, &srcdata[hdrlen], srcdatalen); rlen = padded_data_length(srcdatalen - hdrlen, desfire_get_key_block_length(ctx->keyType)); - PrintAndLogEx(SUCCESS, "--ch src rlen: %d data: %s", rlen, sprint_hex(data, rlen)); DesfireCryptoEncDec(ctx, true, data, rlen, &dstdata[hdrlen], true); *dstdatalen = hdrlen + rlen; - PrintAndLogEx(SUCCESS, "--ch dst len: %d data: %s", *dstdatalen, sprint_hex(dstdata, *dstdatalen)); } }