From 782feb934ac5ec5f25f91ce2a5deeba2a651357a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 21 Sep 2019 18:32:07 +0200 Subject: [PATCH] split slow tests --- client/cmdhficlass.c | 6 ++++-- client/emv/cmdemv.c | 6 ++++-- client/emv/test/crypto_test.c | 16 +++++++++++++--- client/emv/test/crypto_test.h | 2 +- client/emv/test/cryptotest.c | 4 ++-- client/emv/test/cryptotest.h | 2 +- client/loclass/elite_crack.c | 5 +++-- client/loclass/elite_crack.h | 2 +- pm3test.sh | 17 ++++++++++++++--- 9 files changed, 43 insertions(+), 17 deletions(-) diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 5f8ed9fbc..691072174 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -229,10 +229,11 @@ static int usage_hf_iclass_sniff(void) { return PM3_SUCCESS; } static int usage_hf_iclass_loclass(void) { - PrintAndLogEx(NORMAL, "Usage: hf iclass loclass [options]"); + PrintAndLogEx(NORMAL, "Usage: hf iclass loclass [h] [t [l]] [f ]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h Show this help"); PrintAndLogEx(NORMAL, " t Perform self-test"); + PrintAndLogEx(NORMAL, " t l Perform self-test, including long ones"); PrintAndLogEx(NORMAL, " f Bruteforce iclass dumpfile"); PrintAndLogEx(NORMAL, " An iclass dumpfile is assumed to consist of an arbitrary number of"); PrintAndLogEx(NORMAL, " malicious CSNs, and their protocol responses"); @@ -1831,10 +1832,11 @@ static int CmdHFiClass_loclass(const char *Cmd) { return PM3_EFILE; } } else if (opt == 't') { + char opt2 = tolower(param_getchar(Cmd, 1)); int errors = testCipherUtils(); errors += testMAC(); errors += doKeyTests(0); - errors += testElite(); + errors += testElite(opt2=='l'); if (errors) PrintAndLogEx(ERR, "There were errors!!!"); return PM3_ESOFT; } diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index 8bb630074..d45181060 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -1716,19 +1716,21 @@ static int CmdEMVList(const char *Cmd) { static int CmdEMVTest(const char *Cmd) { CLIParserInit("emv test", "Executes tests\n", - "Usage:\n\temv test\n"); + "Usage:\n\temv test [l]\n"); void *argtable[] = { arg_param_begin, arg_lit0("iI", "ignore", "ignore timing tests for VM"), + arg_lit0("lL", "long", "run long tests too"), arg_param_end }; CLIExecWithReturn(Cmd, argtable, true); bool ignoreTimeTest = arg_get_lit(1); + bool runSlowTests = arg_get_lit(2); CLIParserFree(); - return ExecuteCryptoTests(true, ignoreTimeTest); + return ExecuteCryptoTests(true, ignoreTimeTest, runSlowTests); } static int CmdEMVRoca(const char *Cmd) { diff --git a/client/emv/test/crypto_test.c b/client/emv/test/crypto_test.c index cdf22a995..4a40952a8 100644 --- a/client/emv/test/crypto_test.c +++ b/client/emv/test/crypto_test.c @@ -301,8 +301,9 @@ close_pub: return ret; } -int exec_crypto_test(bool verbose) { - unsigned int keylengths[] = {1024, 1152, 1408, 1984, 2048, 3072, 4096}; +int exec_crypto_test(bool verbose, bool include_slow_tests) { + unsigned int keylengths[] = {1024, 2048}; + unsigned int extra_keylengths[] = {1152, 1408, 1984, 3072, 4096}; int i; int ret; fprintf(stdout, "\n"); @@ -322,6 +323,15 @@ int exec_crypto_test(bool verbose) { return ret; } } - + if (include_slow_tests) { + for (i = 0; i < ARRAYLEN(extra_keylengths); i++) { + unsigned int kl = extra_keylengths[i]; + ret = test_genkey(kl, message, kl / 8, verbose); + if (ret) { + fprintf(stderr, "Crypto generate key[%u] test: failed\n", kl); + return ret; + } + } + } return 0; } diff --git a/client/emv/test/crypto_test.h b/client/emv/test/crypto_test.h index 024a950d5..4b8fcf074 100644 --- a/client/emv/test/crypto_test.h +++ b/client/emv/test/crypto_test.h @@ -17,5 +17,5 @@ #define __CRYPTO_TEST_H #include -int exec_crypto_test(bool verbose); +int exec_crypto_test(bool verbose, bool include_slow_tests); #endif diff --git a/client/emv/test/cryptotest.c b/client/emv/test/cryptotest.c index b8ea1239e..f343ebbea 100644 --- a/client/emv/test/cryptotest.c +++ b/client/emv/test/cryptotest.c @@ -33,7 +33,7 @@ #include "crypto/libpcrypto.h" #include "emv/emv_roca.h" -int ExecuteCryptoTests(bool verbose, bool ignore_time) { +int ExecuteCryptoTests(bool verbose, bool ignore_time, bool include_slow_tests) { int res; bool TestFail = false; @@ -94,7 +94,7 @@ int ExecuteCryptoTests(bool verbose, bool ignore_time) { res = exec_cda_test(verbose); if (res) TestFail = true; - res = exec_crypto_test(verbose); + res = exec_crypto_test(verbose, include_slow_tests); if (res) TestFail = true; res = roca_self_test(); diff --git a/client/emv/test/cryptotest.h b/client/emv/test/cryptotest.h index aeecce556..579a5a66d 100644 --- a/client/emv/test/cryptotest.h +++ b/client/emv/test/cryptotest.h @@ -12,5 +12,5 @@ #define __CRYPTOTEST_H #include -int ExecuteCryptoTests(bool verbose, bool ignore_time); +int ExecuteCryptoTests(bool verbose, bool ignore_time, bool include_slow_tests); #endif diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index bf9aee5b3..c7a617f6a 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -637,7 +637,7 @@ static int _testHash1() { return 0; } -int testElite() { +int testElite(bool slowtests) { PrintAndLogEx(INFO, "Testing iClass Elite functinality..."); PrintAndLogEx(INFO, "Testing hash2"); uint8_t k_cus[8] = {0x5B, 0x7C, 0x62, 0xC4, 0x91, 0xC1, 0x1B, 0x39}; @@ -669,6 +669,7 @@ int testElite() { errors += _testHash1(); PrintAndLogEx(INFO, "Testing key diversification ..."); errors += _test_iclass_key_permutation(); - errors += _testBruteforce(); + if (slowtests) + errors += _testBruteforce(); return errors; } diff --git a/client/loclass/elite_crack.h b/client/loclass/elite_crack.h index 819d3de47..8b357ac66 100644 --- a/client/loclass/elite_crack.h +++ b/client/loclass/elite_crack.h @@ -124,7 +124,7 @@ int calculateMasterKey(uint8_t first16bytes[], uint64_t master_key[]); * @brief Test function * @return */ -int testElite(void); +int testElite(bool slowtests); /** Here are some pretty optimal values that can be used to recover necessary data in only diff --git a/pm3test.sh b/pm3test.sh index 8785bf8df..de9134ba1 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -3,6 +3,12 @@ PM3PATH=$(dirname "$0") cd "$PM3PATH" || exit 1 +if [ "$1" == "long" ]; then + SLOWTESTS=true +else + SLOWTESTS=false +fi + C_RED='\033[0;31m' C_GREEN='\033[0;32m' C_YELLOW='\033[0;33m' @@ -95,9 +101,14 @@ while true; do printf "\n${C_BLUE}Testing HF:${C_NC}\n" if ! CheckExecute "hf mf offline text" "./client/proxmark3 -c 'hf mf'" "at_enc"; then break; fi - if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi - if ! CheckExecute "hf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "verified ok"; then break; fi - if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi + if $SLOWTESTS; then + if ! CheckExecute "hf mf hardnested test" "./client/proxmark3 -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi + if ! CheckExecute "hf iclass test" "./client/proxmark3 -c 'hf iclass loclass t l'" "verified ok"; then break; fi + if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test -l'" "Test(s) \[ OK"; then break; fi + else + if ! CheckExecute "hf iclass test" "./client/proxmark3 -c 'hf iclass loclass t'" "OK!"; then break; fi + if ! CheckExecute "emv test" "./client/proxmark3 -c 'emv test'" "Test(s) \[ OK"; then break; fi + fi printf "\n${C_BLUE}Testing tools:${C_NC}\n" # Need a decent example for mfkey32...