diff --git a/appveyor.yml b/appveyor.yml index a32c6a56a..a817ff1ac 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -376,13 +376,14 @@ test_script: ExecTest "hf mf offline text" "hf mf" {bash -lc "cd ~/client;./proxmark3 -c 'hf mf'"} "at_enc" - ExecTest "hf mf hardnested" "hf mf hardnested" {bash -lc "cd ~/client;./proxmark3 -c 'hf mf hardnested t 1 000000000000'"} "found:" - - ExecTest "hf mf iclass" "hf mf iclass" {bash -lc "cd ~/client;./proxmark3 -c 'hf iclass loclass t'"} "verified ok" - - #proxmark crypto tests + # Long tests: + # ExecTest "hf mf hardnested" "hf mf hardnested" {bash -lc "cd ~/client;./proxmark3 -c 'hf mf hardnested t 1 000000000000'"} "found:" + # ExecTest "hf mf iclass" "hf mf iclass" {bash -lc "cd ~/client;./proxmark3 -c 'hf iclass loclass t l'"} "verified ok" + # ExecTest "emv test" "emv test" {bash -lc "cd ~/client;./proxmark3 -c 'emv test -i -l'"} "Test?s? ? OK" + # Short tests: + ExecTest "hf mf iclass" "hf mf iclass" {bash -lc "cd ~/client;./proxmark3 -c 'hf iclass loclass t'"} "OK!" ExecTest "emv test" "emv test" {bash -lc "cd ~/client;./proxmark3 -c 'emv test -i'"} "Test?s? ? OK" diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 089a320ad..4a469e6e1 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1977,11 +1977,6 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { } void MifareCIdent() { -#define GEN_1A 1 -#define GEN_1B 2 -#define GEN_2 4 -#define GEN_UNFUSED 5 - // variables uint8_t isGen = 0; uint8_t rec[1] = {0x00}; @@ -1997,16 +1992,13 @@ void MifareCIdent() { // Generation 1 test ReaderTransmitBitsPar(wupC1, 7, NULL, NULL); - - if (ReaderReceive(rec, recpar) || (rec[0] != 0x0a)) { - + if (ReaderReceive(rec, recpar) && (rec[0] == 0x0a)) { ReaderTransmit(wupC2, sizeof(wupC2), NULL); - if (!ReaderReceive(rec, recpar) || (rec[0] != 0x0a)) { - isGen = GEN_1B; + isGen = MAGIC_GEN_1B; goto OUT; }; - isGen = GEN_1A; + isGen = MAGIC_GEN_1A; goto OUT; } @@ -2017,20 +2009,19 @@ void MifareCIdent() { int res = iso14443a_select_card(uid, NULL, &cuid, true, 0, true); if (res == 2) { - Dbprintf("cident AA55C396 == %08X", cuid); if (cuid == 0xAA55C396) { - isGen = GEN_UNFUSED; + isGen = MAGIC_GEN_UNFUSED; goto OUT; } ReaderTransmit(rats, sizeof(rats), NULL); res = ReaderReceive(buf, par); if (memcmp(buf, "\x09\x78\x00\x91\x02\xDA\xBC\x19\x10\xF0\x05", 11) == 0) { - isGen = GEN_2; + isGen = MAGIC_GEN_2; goto OUT; } if (memcmp(buf, "\x0D\x78\x00\x71\x02\x88\x49\xA1\x30\x20\x15\x06\x08\x56\x3D", 15) == 0) { - isGen = GEN_2; + isGen = MAGIC_GEN_2; } }; 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/fileutils.c b/client/fileutils.c index 35fa735ea..6efe4c17b 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -74,15 +74,15 @@ int fileExists(const char *filename) { * @param filename * @return */ -int is_regular_file(const char *filename) { +bool is_regular_file(const char *filename) { #ifdef _WIN32 struct _stat st; _stat(filename, &st); - return S_ISREG(st.st_mode); + return S_ISREG(st.st_mode) != 0; #else struct stat st; stat(filename, &st); - return S_ISREG(st.st_mode); + return S_ISREG(st.st_mode) != 0; #endif } /** @@ -90,15 +90,15 @@ int is_regular_file(const char *filename) { * @param filename * @return */ -int is_directory(const char *filename) { +bool is_directory(const char *filename) { #ifdef _WIN32 struct _stat st; _stat(filename, &st); - return S_ISDIR(st.st_mode); + return S_ISDIR(st.st_mode) != 0; #else struct stat st; stat(filename, &st); - return S_ISDIR(st.st_mode); + return S_ISDIR(st.st_mode) != 0; #endif } @@ -1053,7 +1053,7 @@ int searchFile(char **foundpath, const char *pm3dir, const char *searchname, con if (searchname == NULL || strlen(searchname) == 0) return PM3_EINVARG; - if (is_directory(searchname) != 0) + if (is_directory(searchname)) return PM3_EINVARG; 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/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index 429605a4e..e4cec00c0 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -1033,16 +1033,16 @@ void detect_classic_magic(void) { } switch (isGeneration) { - case 1: + case MAGIC_GEN_1A: PrintAndLogEx(SUCCESS, "Answers to magic commands (GEN 1a): " _GREEN_("YES")); break; - case 2: + case MAGIC_GEN_1B: PrintAndLogEx(SUCCESS, "Answers to magic commands (GEN 1b): " _GREEN_("YES")); break; - case 4: + case MAGIC_GEN_2: PrintAndLogEx(SUCCESS, "Answers to magic commands (GEN 2 / CUID): " _GREEN_("YES")); break; - case 5: + case MAGIC_GEN_UNFUSED: PrintAndLogEx(SUCCESS, "Answers to magic commands (Write Once / FUID): " _GREEN_("YES")); break; default: diff --git a/include/protocols.h b/include/protocols.h index 9b47266c3..747e4e346 100644 --- a/include/protocols.h +++ b/include/protocols.h @@ -205,6 +205,11 @@ ISO 7816-4 Basic interindustry commands. For command APDU's. #define MAGIC_WIPE 0x40 #define MAGIC_SINGLE (MAGIC_WUPC | MAGIC_HALT | MAGIC_INIT | MAGIC_OFF) //0x1E +// by CMD_HF_MIFARE_CIDENT +#define MAGIC_GEN_1A 1 +#define MAGIC_GEN_1B 2 +#define MAGIC_GEN_2 4 +#define MAGIC_GEN_UNFUSED 5 /** 06 00 = INITIATE 0E xx = SELECT ID (xx = Chip-ID) 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... diff --git a/tools/jtag_openocd/interface-raspberrypi2.cfg b/tools/jtag_openocd/interface-raspberrypi2.cfg index b779cd290..dc97479d5 100644 --- a/tools/jtag_openocd/interface-raspberrypi2.cfg +++ b/tools/jtag_openocd/interface-raspberrypi2.cfg @@ -17,7 +17,7 @@ interface bcm2835gpio # This file is meant for recent versions of Raspberry Pi # You can check yours with: # dd if=/proc/device-tree/soc/ranges bs=4 skip=1 count=1 2>/dev/null|xxd -p -# if it returns 20000000, use interface-raspberrypi2.cfg +# if it returns 20000000, use interface-raspberrypi.cfg # if it returns 3F000000, you're fine bcm2835gpio_peripheral_base 0x3F000000