From fad29cb7553b949084e38c48639973faba038a86 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 21 Feb 2021 11:04:15 +0100 Subject: [PATCH] only look if no key is applied --- client/src/cmdhficlass.c | 55 ++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 45268b4da..716e03436 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -940,22 +940,27 @@ static int CmdHFiClassDecrypt(const char *Cmd) { } bool verbose = arg_get_lit(clictx, 4); - CLIParserFree(clictx); - size_t keylen = 0; uint8_t dec_data[8] = {0}; - - bool use_sc = IsCryptoHelperPresent(verbose); - - if (have_key == false && use_sc == false) { - int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); - if (res != PM3_SUCCESS) { - PrintAndLogEx(INFO, "Couldn't find any decryption methods"); - return PM3_EINVARG; + bool use_sc = false; + if (have_key == false) { + use_sc = IsCryptoHelperPresent(verbose); + if (use_sc == false) { + size_t keylen = 0; + int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); + if (res != PM3_SUCCESS) { + PrintAndLogEx(INFO, "Couldn't find any decryption methods"); + return PM3_EINVARG; + } + + if (keylen != 16) { + PrintAndLogEx(ERR, "Failed to load transport key from file"); + return PM3_EINVARG; + } + memcpy(key, keyptr, sizeof(key)); + free(keyptr); } - memcpy(key, keyptr, sizeof(key)); - free(keyptr); } // tripledes @@ -1157,18 +1162,24 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) { CLIParserFree(clictx); - bool use_sc = IsCryptoHelperPresent(verbose); + bool use_sc = false; + if (have_key == false) { + use_sc = IsCryptoHelperPresent(verbose); + if (use_sc == false) { + size_t keylen = 0; + int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Failed to find any encryption methods"); + return PM3_EINVARG; + } - if (have_key == false && use_sc == false) { - size_t keylen = 0; - int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); - if (res != PM3_SUCCESS) { - PrintAndLogEx(ERR, "Failed to find the transport key"); - return PM3_EINVARG; + if (keylen != 16) { + PrintAndLogEx(ERR, "Failed to load transport key from file"); + return PM3_EINVARG; + } + memcpy(key, keyptr, sizeof(key)); + free(keyptr); } - - memcpy(key, keyptr, sizeof(key)); - free(keyptr); } if (use_sc) {