only look if no key is applied

This commit is contained in:
iceman1001 2021-02-21 11:04:15 +01:00
commit fad29cb755

View file

@ -940,23 +940,28 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
} }
bool verbose = arg_get_lit(clictx, 4); bool verbose = arg_get_lit(clictx, 4);
CLIParserFree(clictx); CLIParserFree(clictx);
size_t keylen = 0;
uint8_t dec_data[8] = {0}; uint8_t dec_data[8] = {0};
bool use_sc = false;
bool use_sc = IsCryptoHelperPresent(verbose); if (have_key == false) {
use_sc = IsCryptoHelperPresent(verbose);
if (have_key == false && use_sc == false) { if (use_sc == false) {
size_t keylen = 0;
int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(INFO, "Couldn't find any decryption methods"); PrintAndLogEx(INFO, "Couldn't find any decryption methods");
return PM3_EINVARG; return PM3_EINVARG;
} }
if (keylen != 16) {
PrintAndLogEx(ERR, "Failed to load transport key from file");
return PM3_EINVARG;
}
memcpy(key, keyptr, sizeof(key)); memcpy(key, keyptr, sizeof(key));
free(keyptr); free(keyptr);
} }
}
// tripledes // tripledes
mbedtls_des3_context ctx; mbedtls_des3_context ctx;
@ -1157,19 +1162,25 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) {
CLIParserFree(clictx); CLIParserFree(clictx);
bool use_sc = IsCryptoHelperPresent(verbose); bool use_sc = false;
if (have_key == false) {
if (have_key == false && use_sc == false) { use_sc = IsCryptoHelperPresent(verbose);
if (use_sc == false) {
size_t keylen = 0; size_t keylen = 0;
int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen); int res = loadFile_safe(ICLASS_DECRYPTION_BIN, "", (void **)&keyptr, &keylen);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Failed to find the transport key"); PrintAndLogEx(ERR, "Failed to find any encryption methods");
return PM3_EINVARG; return PM3_EINVARG;
} }
if (keylen != 16) {
PrintAndLogEx(ERR, "Failed to load transport key from file");
return PM3_EINVARG;
}
memcpy(key, keyptr, sizeof(key)); memcpy(key, keyptr, sizeof(key));
free(keyptr); free(keyptr);
} }
}
if (use_sc) { if (use_sc) {
Encrypt(blk_data, blk_data); Encrypt(blk_data, blk_data);