From ac216b6cbd5c145c796d1951a05b2c2b8b01c5ad Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Wed, 29 Dec 2021 14:43:54 +1300 Subject: [PATCH 01/26] Add comments for common AIDs --- client/src/cmdhfmfdes.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index c8b165dda..3ecbfe843 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -155,6 +155,17 @@ typedef struct aidhdr { uint8_t name[16]; } PACKED aidhdr_t; +typedef struct { + const char *aid; + const char *comment; +} mfdesCommonAID_t; + +static const mfdesCommonAID_t commonAids[] = { + // AID, name/comment + { "\xf4\x81\x2f", "Gallagher card data application" }, + { "\xf4\x81\x20", "Gallagher card application directory" }, // Can be 0xF48120 - 0xF4812B, but I've only ever seen 0xF48120 +}; + static int CmdHelp(const char *Cmd); static int CLIGetUint32Hex(CLIParserContext *ctx, uint8_t paramnum, uint32_t defaultValue, uint32_t *value, bool *valuePresent, uint8_t nlen, const char *lengthErrorStr) { @@ -244,6 +255,16 @@ static char *getVersionStr(uint8_t major, uint8_t minor) { //04 01 01 01 00 1A 05 } +static char noCommentStr[1] = { 0x00 }; +static const char *getAidCommentStr(uint8_t *aid) { + for (int i = 0; i < ARRAYLEN(commonAids); i++) { + if (memcmp(aid, commonAids[i].aid, 3) == 0) { + return commonAids[i].comment; + } + } + return noCommentStr; +} + static nxp_cardtype_t getCardType(uint8_t major, uint8_t minor) { if (major == 0x00) @@ -3056,8 +3077,13 @@ static int CmdHF14ADesGetAIDs(const char *Cmd) { if (buflen >= 3) { PrintAndLogEx(INFO, "---- " _CYAN_("AID list") " ----"); - for (int i = 0; i < buflen; i += 3) - PrintAndLogEx(INFO, "AID: %06x", DesfireAIDByteToUint(&buf[i])); + for (int i = 0; i < buflen; i += 3) { + const char* commentStr = getAidCommentStr(&buf[i]); + if ((void *) commentStr == &noCommentStr) + PrintAndLogEx(INFO, "AID: %06x", DesfireAIDByteToUint(&buf[i])); + else + PrintAndLogEx(INFO, "AID: %06x (%s)", DesfireAIDByteToUint(&buf[i]), commentStr); + } } else { PrintAndLogEx(INFO, "There is no applications on the card"); } From f0b82c63116bf69f1b0bb0acc1ea764337ff1476 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Wed, 29 Dec 2021 20:54:03 +1300 Subject: [PATCH 02/26] Extract gallagher encoding/decoding Change input parameters to be `arg_u640` so that we can check they are the right lengths (and not have them silently truncated) --- client/CMakeLists.txt | 1 + client/Makefile | 1 + client/android/CMakeLists.txt | 1 + client/experimental_lib/CMakeLists.txt | 1 + client/src/cmdlfgallagher.c | 153 +++++-------------------- client/src/mifare/gallaghercore.c | 119 +++++++++++++++++++ client/src/mifare/gallaghercore.h | 22 ++++ 7 files changed, 176 insertions(+), 122 deletions(-) create mode 100644 client/src/mifare/gallaghercore.c create mode 100644 client/src/mifare/gallaghercore.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 464300497..471046545 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -234,6 +234,7 @@ set (TARGET_SOURCES ${PM3_ROOT}/client/src/mifare/desfiresecurechan.c ${PM3_ROOT}/client/src/mifare/desfirecore.c ${PM3_ROOT}/client/src/mifare/desfiretest.c + ${PM3_ROOT}/client/src/mifare/gallaghercore.c ${PM3_ROOT}/client/src/uart/uart_posix.c ${PM3_ROOT}/client/src/uart/uart_win32.c ${PM3_ROOT}/client/src/ui/overlays.ui diff --git a/client/Makefile b/client/Makefile index 97e09be8b..8389e95df 100644 --- a/client/Makefile +++ b/client/Makefile @@ -612,6 +612,7 @@ SRCS = mifare/aiddesfire.c \ mifare/desfirecore.c \ mifare/desfiresecurechan.c \ mifare/desfiretest.c \ + mifare/gallaghercore.c \ mifare/mad.c \ mifare/mfkey.c \ mifare/mifare4.c \ diff --git a/client/android/CMakeLists.txt b/client/android/CMakeLists.txt index 51b36807e..374979103 100644 --- a/client/android/CMakeLists.txt +++ b/client/android/CMakeLists.txt @@ -99,6 +99,7 @@ add_library(pm3rrg_rdv4 SHARED ${PM3_ROOT}/client/src/mifare/desfiresecurechan.c ${PM3_ROOT}/client/src/mifare/desfirecore.c ${PM3_ROOT}/client/src/mifare/desfiretest.c + ${PM3_ROOT}/client/src/mifare/gallaghercore.c ${PM3_ROOT}/client/src/uart/uart_posix.c ${PM3_ROOT}/client/src/uart/uart_win32.c ${PM3_ROOT}/client/src/ui/overlays.ui diff --git a/client/experimental_lib/CMakeLists.txt b/client/experimental_lib/CMakeLists.txt index 901c687fd..8d3ed3adf 100644 --- a/client/experimental_lib/CMakeLists.txt +++ b/client/experimental_lib/CMakeLists.txt @@ -233,6 +233,7 @@ set (TARGET_SOURCES ${PM3_ROOT}/client/src/mifare/desfiresecurechan.c ${PM3_ROOT}/client/src/mifare/desfirecore.c ${PM3_ROOT}/client/src/mifare/desfiretest.c + ${PM3_ROOT}/client/src/mifare/gallaghercore.c ${PM3_ROOT}/client/src/uart/uart_posix.c ${PM3_ROOT}/client/src/uart/uart_win32.c ${PM3_ROOT}/client/src/ui/overlays.ui diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index bcc09e53e..c8d13d62b 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -9,7 +9,10 @@ // ASK/MAN, RF/32, 96 bits long (unknown cs) (0x00088060) // sample Q5 , ASK RF/32, STT, 96 bits (3blocks) ( 0x9000F006) //----------------------------------------------------------------------------- +// Modified by: Matt Moran (@DarkMatterMatt), 2021 + #include "cmdlfgallagher.h" +#include "mifare/gallaghercore.h" #include // memcpy #include // tolower #include @@ -29,56 +32,6 @@ static int CmdHelp(const char *Cmd); -static void scramble(uint8_t *arr, uint8_t len) { - uint8_t lut[] = { - 0xa3, 0xb0, 0x80, 0xc6, 0xb2, 0xf4, 0x5c, 0x6c, 0x81, 0xf1, 0xbb, 0xeb, 0x55, 0x67, 0x3c, 0x05, - 0x1a, 0x0e, 0x61, 0xf6, 0x22, 0xce, 0xaa, 0x8f, 0xbd, 0x3b, 0x1f, 0x5e, 0x44, 0x04, 0x51, 0x2e, - 0x4d, 0x9a, 0x84, 0xea, 0xf8, 0x66, 0x74, 0x29, 0x7f, 0x70, 0xd8, 0x31, 0x7a, 0x6d, 0xa4, 0x00, - 0x82, 0xb9, 0x5f, 0xb4, 0x16, 0xab, 0xff, 0xc2, 0x39, 0xdc, 0x19, 0x65, 0x57, 0x7c, 0x20, 0xfa, - 0x5a, 0x49, 0x13, 0xd0, 0xfb, 0xa8, 0x91, 0x73, 0xb1, 0x33, 0x18, 0xbe, 0x21, 0x72, 0x48, 0xb6, - 0xdb, 0xa0, 0x5d, 0xcc, 0xe6, 0x17, 0x27, 0xe5, 0xd4, 0x53, 0x42, 0xf3, 0xdd, 0x7b, 0x24, 0xac, - 0x2b, 0x58, 0x1e, 0xa7, 0xe7, 0x86, 0x40, 0xd3, 0x98, 0x97, 0x71, 0xcb, 0x3a, 0x0f, 0x01, 0x9b, - 0x6e, 0x1b, 0xfc, 0x34, 0xa6, 0xda, 0x07, 0x0c, 0xae, 0x37, 0xca, 0x54, 0xfd, 0x26, 0xfe, 0x0a, - 0x45, 0xa2, 0x2a, 0xc4, 0x12, 0x0d, 0xf5, 0x4f, 0x69, 0xe0, 0x8a, 0x77, 0x60, 0x3f, 0x99, 0x95, - 0xd2, 0x38, 0x36, 0x62, 0xb7, 0x32, 0x7e, 0x79, 0xc0, 0x46, 0x93, 0x2f, 0xa5, 0xba, 0x5b, 0xaf, - 0x52, 0x1d, 0xc3, 0x75, 0xcf, 0xd6, 0x4c, 0x83, 0xe8, 0x3d, 0x30, 0x4e, 0xbc, 0x08, 0x2d, 0x09, - 0x06, 0xd9, 0x25, 0x9e, 0x89, 0xf2, 0x96, 0x88, 0xc1, 0x8c, 0x94, 0x0b, 0x28, 0xf0, 0x47, 0x63, - 0xd5, 0xb3, 0x68, 0x56, 0x9c, 0xf9, 0x6f, 0x41, 0x50, 0x85, 0x8b, 0x9d, 0x59, 0xbf, 0x9f, 0xe2, - 0x8e, 0x6a, 0x11, 0x23, 0xa1, 0xcd, 0xb5, 0x7d, 0xc7, 0xa9, 0xc8, 0xef, 0xdf, 0x02, 0xb8, 0x03, - 0x6b, 0x35, 0x3e, 0x2c, 0x76, 0xc9, 0xde, 0x1c, 0x4b, 0xd1, 0xed, 0x14, 0xc5, 0xad, 0xe9, 0x64, - 0x4a, 0xec, 0x8d, 0xf7, 0x10, 0x43, 0x78, 0x15, 0x87, 0xe4, 0xd7, 0x92, 0xe1, 0xee, 0xe3, 0x90 - }; - - for (int i = 0; i < len; i++) { - arr[i] = lut[arr[i]]; - } -} - -static void descramble(uint8_t *arr, uint8_t len) { - uint8_t lut[] = { - 0x2f, 0x6e, 0xdd, 0xdf, 0x1d, 0x0f, 0xb0, 0x76, 0xad, 0xaf, 0x7f, 0xbb, 0x77, 0x85, 0x11, 0x6d, - 0xf4, 0xd2, 0x84, 0x42, 0xeb, 0xf7, 0x34, 0x55, 0x4a, 0x3a, 0x10, 0x71, 0xe7, 0xa1, 0x62, 0x1a, - 0x3e, 0x4c, 0x14, 0xd3, 0x5e, 0xb2, 0x7d, 0x56, 0xbc, 0x27, 0x82, 0x60, 0xe3, 0xae, 0x1f, 0x9b, - 0xaa, 0x2b, 0x95, 0x49, 0x73, 0xe1, 0x92, 0x79, 0x91, 0x38, 0x6c, 0x19, 0x0e, 0xa9, 0xe2, 0x8d, - 0x66, 0xc7, 0x5a, 0xf5, 0x1c, 0x80, 0x99, 0xbe, 0x4e, 0x41, 0xf0, 0xe8, 0xa6, 0x20, 0xab, 0x87, - 0xc8, 0x1e, 0xa0, 0x59, 0x7b, 0x0c, 0xc3, 0x3c, 0x61, 0xcc, 0x40, 0x9e, 0x06, 0x52, 0x1b, 0x32, - 0x8c, 0x12, 0x93, 0xbf, 0xef, 0x3b, 0x25, 0x0d, 0xc2, 0x88, 0xd1, 0xe0, 0x07, 0x2d, 0x70, 0xc6, - 0x29, 0x6a, 0x4d, 0x47, 0x26, 0xa3, 0xe4, 0x8b, 0xf6, 0x97, 0x2c, 0x5d, 0x3d, 0xd7, 0x96, 0x28, - 0x02, 0x08, 0x30, 0xa7, 0x22, 0xc9, 0x65, 0xf8, 0xb7, 0xb4, 0x8a, 0xca, 0xb9, 0xf2, 0xd0, 0x17, - 0xff, 0x46, 0xfb, 0x9a, 0xba, 0x8f, 0xb6, 0x69, 0x68, 0x8e, 0x21, 0x6f, 0xc4, 0xcb, 0xb3, 0xce, - 0x51, 0xd4, 0x81, 0x00, 0x2e, 0x9c, 0x74, 0x63, 0x45, 0xd9, 0x16, 0x35, 0x5f, 0xed, 0x78, 0x9f, - 0x01, 0x48, 0x04, 0xc1, 0x33, 0xd6, 0x4f, 0x94, 0xde, 0x31, 0x9d, 0x0a, 0xac, 0x18, 0x4b, 0xcd, - 0x98, 0xb8, 0x37, 0xa2, 0x83, 0xec, 0x03, 0xd8, 0xda, 0xe5, 0x7a, 0x6b, 0x53, 0xd5, 0x15, 0xa4, - 0x43, 0xe9, 0x90, 0x67, 0x58, 0xc0, 0xa5, 0xfa, 0x2a, 0xb1, 0x75, 0x50, 0x39, 0x5c, 0xe6, 0xdc, - 0x89, 0xfc, 0xcf, 0xfe, 0xf9, 0x57, 0x54, 0x64, 0xa8, 0xee, 0x23, 0x0b, 0xf1, 0xea, 0xfd, 0xdb, - 0xbd, 0x09, 0xb5, 0x5b, 0x05, 0x86, 0x13, 0xf3, 0x24, 0xc5, 0x3f, 0x44, 0x72, 0x7c, 0x7e, 0x36 - }; - - for (int i = 0; i < len; i++) { - arr[i] = lut[arr[i]]; - } -} - //see ASK/MAN Demod for what args are accepted int demodGallagher(bool verbose) { (void) verbose; // unused so far @@ -113,6 +66,7 @@ int demodGallagher(bool verbose) { // bytes uint8_t arr[8] = {0}; for (int i = 0, pos = 0; i < ARRAYLEN(arr); i++) { + // first 16 bits are the 7FEA prefix, then every 9th bit is a checksum-bit for the preceding byte pos = 16 + (9 * i); arr[i] = bytebits_to_byte(g_DemodBuffer + pos, 8); } @@ -121,22 +75,15 @@ int demodGallagher(bool verbose) { uint8_t crc = bytebits_to_byte(g_DemodBuffer + 16 + (9 * 8), 8); uint8_t calc_crc = CRC8Cardx(arr, ARRAYLEN(arr)); - descramble(arr, ARRAYLEN(arr)); + uint8_t region_code, issue_level; + uint16_t facility_code; + uint32_t card_number; - // 4bit region code - uint8_t rc = (arr[3] & 0x1E) >> 1; + decodeCardholderCredentials(arr, ®ion_code, &facility_code, &card_number, &issue_level); - // 16bit FC - uint16_t fc = (arr[5] & 0x0F) << 12 | arr[1] << 4 | ((arr[7] >> 4) & 0x0F); - - // 24bit CN - uint32_t cn = arr[0] << 16 | (arr[4] & 0x1F) << 11 | arr[2] << 3 | (arr[3] & 0xE0) >> 5; - - // 4bit issue level - uint8_t il = arr[7] & 0x0F; - - PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") " FC: " _GREEN_("%u") " CN: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"), rc, fc, cn, il); - PrintAndLogEx(SUCCESS, " Displayed: " _GREEN_("%C%u"), rc + 'A', fc); + PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") " Facility: " _GREEN_("%u") " Card No.: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"), + region_code, facility_code, card_number, issue_level); + PrintAndLogEx(SUCCESS, " Displayed: " _GREEN_("%C%u"), region_code + 'A', facility_code); PrintAndLogEx(SUCCESS, " Raw: %08X%08X%08X", raw1, raw2, raw3); PrintAndLogEx(SUCCESS, " CRC: %02X - %02X (%s)", crc, calc_crc, (crc == calc_crc) ? "ok" : "fail"); return PM3_SUCCESS; @@ -185,34 +132,6 @@ static int CmdGallagherReader(const char *Cmd) { return PM3_SUCCESS; } -static bool isValidGallagherParams(int8_t rc, int32_t fc, int32_t cn, int8_t il) { - bool isValid = true; - - // if one is set, all must be set - if (rc < 0 || fc < 0 || cn < 0 || il < 0) { - PrintAndLogEx(FAILED, "If rc/fc/cn/il is specified, all must be set"); - isValid = false; - } - // validate input - if (rc > 0x0f) { - PrintAndLogEx(FAILED, "Region code must be less than 16 (4 bits)"); - isValid = false; - } - if (fc > 0xffff) { - PrintAndLogEx(FAILED, "Facility code must be less than 65536 (2 bytes)"); - isValid = false; - } - if (cn > 0xffffff) { - PrintAndLogEx(FAILED, "Card number must be less than 16777216 (3 bytes)"); - isValid = false; - } - if (il > 0x0f) { - PrintAndLogEx(FAILED, "Issue level must be less than 16 (4 bits)"); - isValid = false; - } - return isValid; -} - static void setBitsInBlocks(uint32_t *blocks, uint8_t *pos, uint32_t data, uint8_t data_len) { for (int i = data_len - 1; i >= 0; i--) { uint8_t blk = *pos / 32; @@ -225,18 +144,8 @@ static void setBitsInBlocks(uint32_t *blocks, uint8_t *pos, uint32_t data, uint8 static void createBlocks(uint32_t *blocks, uint8_t rc, uint16_t fc, uint32_t cn, uint8_t il) { // put data into the correct places (Gallagher obfuscation) - uint8_t arr[8] = {0}; - arr[0] = (cn & 0xffffff) >> 16; - arr[1] = (fc & 0xfff) >> 4; - arr[2] = (cn & 0x7ff) >> 3; - arr[3] = (cn & 0x7) << 5 | (rc & 0xf) << 1; - arr[4] = (cn & 0xffff) >> 11; - arr[5] = (fc & 0xffff) >> 12; - arr[6] = 0; - arr[7] = (fc & 0xf) << 4 | (il & 0xf); - - // more obfuscation - scramble(arr, ARRAYLEN(arr)); + uint8_t arr[8] = { 0x00 }; + encodeCardholderCredentials(arr, rc, fc, cn, il); blocks[0] = blocks[1] = blocks[2] = 0; uint8_t pos = 0; @@ -273,10 +182,10 @@ static int CmdGallagherClone(const char *Cmd) { arg_str0("r", "raw", "", "raw hex data. 12 bytes max"), arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"), arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"), - arg_int0(NULL, "rc", "", "Region code. 4 bits max"), - arg_int0(NULL, "fc", "", "Facility code. 2 bytes max"), - arg_int0(NULL, "cn", "", "Card number. 3 bytes max"), - arg_int0(NULL, "il", "", "Issue level. 4 bits max"), + arg_u64_0(NULL, "rc", "", "Region code. 4 bits max"), + arg_u64_0(NULL, "fc", "", "Facility code. 2 bytes max"), + arg_u64_0(NULL, "cn", "", "Card number. 3 bytes max"), + arg_u64_0(NULL, "il", "", "Issue level. 4 bits max"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); @@ -292,10 +201,10 @@ static int CmdGallagherClone(const char *Cmd) { bool q5 = arg_get_lit(ctx, 2); bool em = arg_get_lit(ctx, 3); - int16_t region_code = arg_get_int_def(ctx, 4, -1); - int32_t facility_code = arg_get_int_def(ctx, 5, -1); - uint64_t card_number = arg_get_int_def(ctx, 6, -1); - uint32_t issue_level = arg_get_int_def(ctx, 7, -1); + uint64_t region_code = arg_get_u64_def(ctx, 4, -1); // uint16, will be validated later + uint64_t facility_code = arg_get_u64_def(ctx, 5, -1); // uint32, will be validated later + uint64_t card_number = arg_get_u64_def(ctx, 6, -1); // uint64 + uint64_t issue_level = arg_get_u64_def(ctx, 7, -1); // uint32, will be validated later CLIParserFree(ctx); bool use_raw = raw_len > 0; @@ -316,7 +225,7 @@ static int CmdGallagherClone(const char *Cmd) { PrintAndLogEx(FAILED, "Can't specify both raw and rc/fc/cn/il at the same time"); return PM3_EINVARG; } - if (!isValidGallagherParams(region_code, facility_code, card_number, issue_level)) { + if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { return PM3_EINVARG; } } @@ -373,10 +282,10 @@ static int CmdGallagherSim(const char *Cmd) { void *argtable[] = { arg_param_begin, arg_str0("r", "raw", "", "raw hex data. 12 bytes max"), - arg_int0(NULL, "rc", "", "Region code. 4 bits max"), - arg_int0(NULL, "fc", "", "Facility code. 2 bytes max"), - arg_int0(NULL, "cn", "", "Card number. 3 bytes max"), - arg_int0(NULL, "il", "", "Issue level. 4 bits max"), + arg_u64_0(NULL, "rc", "", "Region code. 4 bits max"), + arg_u64_0(NULL, "fc", "", "Facility code. 2 bytes max"), + arg_u64_0(NULL, "cn", "", "Card number. 3 bytes max"), + arg_u64_0(NULL, "il", "", "Issue level. 4 bits max"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); @@ -391,10 +300,10 @@ static int CmdGallagherSim(const char *Cmd) { return PM3_EINVARG; } - int16_t region_code = arg_get_int_def(ctx, 2, -1); - int32_t facility_code = arg_get_int_def(ctx, 3, -1); - uint64_t card_number = arg_get_int_def(ctx, 4, -1); - uint32_t issue_level = arg_get_int_def(ctx, 5, -1); + uint64_t region_code = arg_get_u64_def(ctx, 2, -1); // uint16, will be validated later + uint64_t facility_code = arg_get_u64_def(ctx, 3, -1); // uint32, will be validated later + uint64_t card_number = arg_get_u64_def(ctx, 4, -1); // uint64 + uint64_t issue_level = arg_get_u64_def(ctx, 5, -1); // uint32, will be validated later CLIParserFree(ctx); bool use_raw = raw_len > 0; @@ -410,7 +319,7 @@ static int CmdGallagherSim(const char *Cmd) { PrintAndLogEx(FAILED, "Can't specify both raw and rc/fc/cn/il at the same time"); return PM3_EINVARG; } - if (!isValidGallagherParams(region_code, facility_code, card_number, issue_level)) { + if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { return PM3_EINVARG; } } diff --git a/client/src/mifare/gallaghercore.c b/client/src/mifare/gallaghercore.c new file mode 100644 index 000000000..71ad88300 --- /dev/null +++ b/client/src/mifare/gallaghercore.c @@ -0,0 +1,119 @@ +/** + * Matt Moran (@DarkMatterMatt), 2021 + * ----------------------------------------------------------------------------- + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * ----------------------------------------------------------------------------- + * Common functionality for low/high-frequency GALLAGHER tag encoding & decoding. + */ +#include "gallaghercore.h" +#include "common.h" +#include "ui.h" + +static void scramble(uint8_t *arr, uint8_t len) { + uint8_t lut[] = { + 0xa3, 0xb0, 0x80, 0xc6, 0xb2, 0xf4, 0x5c, 0x6c, 0x81, 0xf1, 0xbb, 0xeb, 0x55, 0x67, 0x3c, 0x05, + 0x1a, 0x0e, 0x61, 0xf6, 0x22, 0xce, 0xaa, 0x8f, 0xbd, 0x3b, 0x1f, 0x5e, 0x44, 0x04, 0x51, 0x2e, + 0x4d, 0x9a, 0x84, 0xea, 0xf8, 0x66, 0x74, 0x29, 0x7f, 0x70, 0xd8, 0x31, 0x7a, 0x6d, 0xa4, 0x00, + 0x82, 0xb9, 0x5f, 0xb4, 0x16, 0xab, 0xff, 0xc2, 0x39, 0xdc, 0x19, 0x65, 0x57, 0x7c, 0x20, 0xfa, + 0x5a, 0x49, 0x13, 0xd0, 0xfb, 0xa8, 0x91, 0x73, 0xb1, 0x33, 0x18, 0xbe, 0x21, 0x72, 0x48, 0xb6, + 0xdb, 0xa0, 0x5d, 0xcc, 0xe6, 0x17, 0x27, 0xe5, 0xd4, 0x53, 0x42, 0xf3, 0xdd, 0x7b, 0x24, 0xac, + 0x2b, 0x58, 0x1e, 0xa7, 0xe7, 0x86, 0x40, 0xd3, 0x98, 0x97, 0x71, 0xcb, 0x3a, 0x0f, 0x01, 0x9b, + 0x6e, 0x1b, 0xfc, 0x34, 0xa6, 0xda, 0x07, 0x0c, 0xae, 0x37, 0xca, 0x54, 0xfd, 0x26, 0xfe, 0x0a, + 0x45, 0xa2, 0x2a, 0xc4, 0x12, 0x0d, 0xf5, 0x4f, 0x69, 0xe0, 0x8a, 0x77, 0x60, 0x3f, 0x99, 0x95, + 0xd2, 0x38, 0x36, 0x62, 0xb7, 0x32, 0x7e, 0x79, 0xc0, 0x46, 0x93, 0x2f, 0xa5, 0xba, 0x5b, 0xaf, + 0x52, 0x1d, 0xc3, 0x75, 0xcf, 0xd6, 0x4c, 0x83, 0xe8, 0x3d, 0x30, 0x4e, 0xbc, 0x08, 0x2d, 0x09, + 0x06, 0xd9, 0x25, 0x9e, 0x89, 0xf2, 0x96, 0x88, 0xc1, 0x8c, 0x94, 0x0b, 0x28, 0xf0, 0x47, 0x63, + 0xd5, 0xb3, 0x68, 0x56, 0x9c, 0xf9, 0x6f, 0x41, 0x50, 0x85, 0x8b, 0x9d, 0x59, 0xbf, 0x9f, 0xe2, + 0x8e, 0x6a, 0x11, 0x23, 0xa1, 0xcd, 0xb5, 0x7d, 0xc7, 0xa9, 0xc8, 0xef, 0xdf, 0x02, 0xb8, 0x03, + 0x6b, 0x35, 0x3e, 0x2c, 0x76, 0xc9, 0xde, 0x1c, 0x4b, 0xd1, 0xed, 0x14, 0xc5, 0xad, 0xe9, 0x64, + 0x4a, 0xec, 0x8d, 0xf7, 0x10, 0x43, 0x78, 0x15, 0x87, 0xe4, 0xd7, 0x92, 0xe1, 0xee, 0xe3, 0x90 + }; + + for (int i = 0; i < len; i++) { + arr[i] = lut[arr[i]]; + } +} + +static void descramble(uint8_t *arr, uint8_t len) { + uint8_t lut[] = { + 0x2f, 0x6e, 0xdd, 0xdf, 0x1d, 0x0f, 0xb0, 0x76, 0xad, 0xaf, 0x7f, 0xbb, 0x77, 0x85, 0x11, 0x6d, + 0xf4, 0xd2, 0x84, 0x42, 0xeb, 0xf7, 0x34, 0x55, 0x4a, 0x3a, 0x10, 0x71, 0xe7, 0xa1, 0x62, 0x1a, + 0x3e, 0x4c, 0x14, 0xd3, 0x5e, 0xb2, 0x7d, 0x56, 0xbc, 0x27, 0x82, 0x60, 0xe3, 0xae, 0x1f, 0x9b, + 0xaa, 0x2b, 0x95, 0x49, 0x73, 0xe1, 0x92, 0x79, 0x91, 0x38, 0x6c, 0x19, 0x0e, 0xa9, 0xe2, 0x8d, + 0x66, 0xc7, 0x5a, 0xf5, 0x1c, 0x80, 0x99, 0xbe, 0x4e, 0x41, 0xf0, 0xe8, 0xa6, 0x20, 0xab, 0x87, + 0xc8, 0x1e, 0xa0, 0x59, 0x7b, 0x0c, 0xc3, 0x3c, 0x61, 0xcc, 0x40, 0x9e, 0x06, 0x52, 0x1b, 0x32, + 0x8c, 0x12, 0x93, 0xbf, 0xef, 0x3b, 0x25, 0x0d, 0xc2, 0x88, 0xd1, 0xe0, 0x07, 0x2d, 0x70, 0xc6, + 0x29, 0x6a, 0x4d, 0x47, 0x26, 0xa3, 0xe4, 0x8b, 0xf6, 0x97, 0x2c, 0x5d, 0x3d, 0xd7, 0x96, 0x28, + 0x02, 0x08, 0x30, 0xa7, 0x22, 0xc9, 0x65, 0xf8, 0xb7, 0xb4, 0x8a, 0xca, 0xb9, 0xf2, 0xd0, 0x17, + 0xff, 0x46, 0xfb, 0x9a, 0xba, 0x8f, 0xb6, 0x69, 0x68, 0x8e, 0x21, 0x6f, 0xc4, 0xcb, 0xb3, 0xce, + 0x51, 0xd4, 0x81, 0x00, 0x2e, 0x9c, 0x74, 0x63, 0x45, 0xd9, 0x16, 0x35, 0x5f, 0xed, 0x78, 0x9f, + 0x01, 0x48, 0x04, 0xc1, 0x33, 0xd6, 0x4f, 0x94, 0xde, 0x31, 0x9d, 0x0a, 0xac, 0x18, 0x4b, 0xcd, + 0x98, 0xb8, 0x37, 0xa2, 0x83, 0xec, 0x03, 0xd8, 0xda, 0xe5, 0x7a, 0x6b, 0x53, 0xd5, 0x15, 0xa4, + 0x43, 0xe9, 0x90, 0x67, 0x58, 0xc0, 0xa5, 0xfa, 0x2a, 0xb1, 0x75, 0x50, 0x39, 0x5c, 0xe6, 0xdc, + 0x89, 0xfc, 0xcf, 0xfe, 0xf9, 0x57, 0x54, 0x64, 0xa8, 0xee, 0x23, 0x0b, 0xf1, 0xea, 0xfd, 0xdb, + 0xbd, 0x09, 0xb5, 0x5b, 0x05, 0x86, 0x13, 0xf3, 0x24, 0xc5, 0x3f, 0x44, 0x72, 0x7c, 0x7e, 0x36 + }; + + for (int i = 0; i < len; i++) { + arr[i] = lut[arr[i]]; + } +} + +void decodeCardholderCredentials(uint8_t *eight_bytes, uint8_t *region_code, uint16_t *facility_code, uint32_t *card_number, uint8_t *issue_level) { + uint8_t *arr = eight_bytes; + + descramble(arr, 8); + + // 4bit region code + *region_code = (arr[3] & 0x1E) >> 1; + + // 16bit facility code + *facility_code = (arr[5] & 0x0F) << 12 | arr[1] << 4 | ((arr[7] >> 4) & 0x0F); + + // 24bit card number + *card_number = arr[0] << 16 | (arr[4] & 0x1F) << 11 | arr[2] << 3 | (arr[3] & 0xE0) >> 5; + + // 4bit issue level + *issue_level = arr[7] & 0x0F; +} + +void encodeCardholderCredentials(uint8_t *eight_bytes, uint8_t region_code, uint16_t facility_code, uint32_t card_number, uint8_t issue_level) { + // put data into the correct places (Gallagher obfuscation) + eight_bytes[0] = (card_number & 0xffffff) >> 16; + eight_bytes[1] = (facility_code & 0xfff) >> 4; + eight_bytes[2] = (card_number & 0x7ff) >> 3; + eight_bytes[3] = (card_number & 0x7) << 5 | (region_code & 0xf) << 1; + eight_bytes[4] = (card_number & 0xffff) >> 11; + eight_bytes[5] = (facility_code & 0xffff) >> 12; + eight_bytes[6] = 0; + eight_bytes[7] = (facility_code & 0xf) << 4 | (issue_level & 0xf); + + // more obfuscation + scramble(eight_bytes, 8); +} + +bool isValidGallagherCredentials(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level) { + bool isValid = true; + + // validate input + if (region_code > 0x0f) { + PrintAndLogEx(FAILED, "Region code must be 0 <= rc <= 15 (4 bits), received: %d", region_code); + isValid = false; + } + if (facility_code > 0xffff) { + PrintAndLogEx(FAILED, "Facility code must be 0 <= fc <= 65535 (2 bytes), received: %d", facility_code); + isValid = false; + } + if (card_number > 0xffffff) { + PrintAndLogEx(FAILED, "Card number must be 0 <= cn <= 16777215 (3 bytes), received: %d", card_number); + isValid = false; + } + if (issue_level > 0x0f) { + PrintAndLogEx(FAILED, "Issue level must be 0 <= il <= 15 (4 bits), received: %d", issue_level); + isValid = false; + } + return isValid; +} diff --git a/client/src/mifare/gallaghercore.h b/client/src/mifare/gallaghercore.h new file mode 100644 index 000000000..e55f2e693 --- /dev/null +++ b/client/src/mifare/gallaghercore.h @@ -0,0 +1,22 @@ +/** + * Matt Moran (@DarkMatterMatt), 2021 + * ----------------------------------------------------------------------------- + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * ----------------------------------------------------------------------------- + * Common functionality for low/high-frequency GALLAGHER tag encoding & decoding. + */ +#ifndef MIFARE_GALLAGHERCORE_H__ +#define MIFARE_GALLAGHERCORE_H__ + +#include "common.h" + +void encodeCardholderCredentials(uint8_t *eight_bytes, uint8_t region_code, uint16_t facility_code, uint32_t card_number, uint8_t issue_level); + +void decodeCardholderCredentials(uint8_t *eight_bytes, uint8_t *region_code, uint16_t *facility_code, uint32_t *card_number, uint8_t *issue_level); + +bool isValidGallagherCredentials(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level); + +#endif From a1db6836733ba5e2c317cb112e3ba290515bfbb2 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Wed, 29 Dec 2021 23:42:06 +1300 Subject: [PATCH 03/26] Add basic structure for `hf gallagher` --- client/CMakeLists.txt | 1 + client/Makefile | 1 + client/android/CMakeLists.txt | 1 + client/experimental_lib/CMakeLists.txt | 1 + client/src/cmdhf.c | 2 + client/src/cmdhfgallagher.c | 139 +++++++++++++++++++++++++ client/src/cmdhfgallagher.h | 20 ++++ 7 files changed, 165 insertions(+) create mode 100644 client/src/cmdhfgallagher.c create mode 100644 client/src/cmdhfgallagher.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 471046545..574303188 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -255,6 +255,7 @@ set (TARGET_SOURCES ${PM3_ROOT}/client/src/cmdhfepa.c ${PM3_ROOT}/client/src/cmdhffelica.c ${PM3_ROOT}/client/src/cmdhffido.c + ${PM3_ROOT}/client/src/cmdhfgallagher.c ${PM3_ROOT}/client/src/cmdhfcipurse.c ${PM3_ROOT}/client/src/cmdhficlass.c ${PM3_ROOT}/client/src/cmdhfjooki.c diff --git a/client/Makefile b/client/Makefile index 8389e95df..2bbc72af6 100644 --- a/client/Makefile +++ b/client/Makefile @@ -506,6 +506,7 @@ SRCS = mifare/aiddesfire.c \ cmdhfemrtd.c \ cmdhffelica.c \ cmdhffido.c \ + cmdhfgallagher.c \ cmdhfksx6924.c \ cmdhfcipurse.c \ cmdhficlass.c \ diff --git a/client/android/CMakeLists.txt b/client/android/CMakeLists.txt index 374979103..9bc0f59cd 100644 --- a/client/android/CMakeLists.txt +++ b/client/android/CMakeLists.txt @@ -120,6 +120,7 @@ add_library(pm3rrg_rdv4 SHARED ${PM3_ROOT}/client/src/cmdhfepa.c ${PM3_ROOT}/client/src/cmdhffelica.c ${PM3_ROOT}/client/src/cmdhffido.c + ${PM3_ROOT}/client/src/cmdhfgallagher.c ${PM3_ROOT}/client/src/cmdhfcipurse.c ${PM3_ROOT}/client/src/cmdhficlass.c ${PM3_ROOT}/client/src/cmdhfjooki.c diff --git a/client/experimental_lib/CMakeLists.txt b/client/experimental_lib/CMakeLists.txt index 8d3ed3adf..c4ab858f7 100644 --- a/client/experimental_lib/CMakeLists.txt +++ b/client/experimental_lib/CMakeLists.txt @@ -254,6 +254,7 @@ set (TARGET_SOURCES ${PM3_ROOT}/client/src/cmdhfepa.c ${PM3_ROOT}/client/src/cmdhffelica.c ${PM3_ROOT}/client/src/cmdhffido.c + ${PM3_ROOT}/client/src/cmdhfgallagher.c ${PM3_ROOT}/client/src/cmdhfcipurse.c ${PM3_ROOT}/client/src/cmdhficlass.c ${PM3_ROOT}/client/src/cmdhfjooki.c diff --git a/client/src/cmdhf.c b/client/src/cmdhf.c index 9b5841d71..ce87a5e62 100644 --- a/client/src/cmdhf.c +++ b/client/src/cmdhf.c @@ -33,6 +33,7 @@ #include "cmdhftopaz.h" // TOPAZ #include "cmdhffelica.h" // ISO18092 / FeliCa #include "cmdhffido.h" // FIDO authenticators +#include "cmdhfgallagher.h" // Gallagher DESFire cards #include "cmdhfksx6924.h" // KS X 6924 #include "cmdhfcipurse.h" // CIPURSE transport cards #include "cmdhfthinfilm.h" // Thinfilm @@ -414,6 +415,7 @@ static command_t CommandTable[] = { {"emrtd", CmdHFeMRTD, AlwaysAvailable, "{ Machine Readable Travel Document... }"}, {"felica", CmdHFFelica, AlwaysAvailable, "{ ISO18092 / FeliCa RFIDs... }"}, {"fido", CmdHFFido, AlwaysAvailable, "{ FIDO and FIDO2 authenticators... }"}, + {"gallagher", CmdHFGallagher, AlwaysAvailable, "{ Gallagher DESFire RFIDs... }"}, {"ksx6924", CmdHFKSX6924, AlwaysAvailable, "{ KS X 6924 (T-Money, Snapper+) RFIDs }"}, {"jooki", CmdHF_Jooki, AlwaysAvailable, "{ Jooki RFIDs... }"}, {"iclass", CmdHFiClass, AlwaysAvailable, "{ ICLASS RFIDs... }"}, diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c new file mode 100644 index 000000000..90fff183c --- /dev/null +++ b/client/src/cmdhfgallagher.c @@ -0,0 +1,139 @@ +/** + * Matt Moran (@DarkMatterMatt), 2021 + * ----------------------------------------------------------------------------- + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * ----------------------------------------------------------------------------- + * High frequency GALLAGHER tag commands. + * MIFARE DESFire, AIDs 2081F4-2F81F4 + */ + +#include "cmdhfgallagher.h" +#include "mifare/gallaghercore.h" +#include +#include "common.h" +#include "cmdparser.h" +#include "cliparser.h" +#include "ui.h" + +static int CmdHelp(const char *Cmd); + +static int CmdGallagherReader(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf gallagher reader", + "read a GALLAGHER tag", + "hf gallagher reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + if (cm) { + PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); + } + + do { + // read + } while (cm && !kbd_enter_pressed()); + return PM3_SUCCESS; +} + +static int CmdGallagherClone(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf gallagher clone", + "clone a GALLAGHER card to a blank DESFire card.", + "hf gallagher clone --rc 1 --fc 22 --cn 3333 --il 4" + ); + + void *argtable[] = { + arg_param_begin, + arg_u64_1(NULL, "rc", "", "Region code. 4 bits max"), + arg_u64_1(NULL, "fc", "", "Facility code. 2 bytes max"), + arg_u64_1(NULL, "cn", "", "Card number. 3 bytes max"), + arg_u64_1(NULL, "il", "", "Issue level. 4 bits max"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + uint64_t region_code = arg_get_u64(ctx, 1); // uint16, will be validated later + uint64_t facility_code = arg_get_u64(ctx, 2); // uint32, will be validated later + uint64_t card_number = arg_get_u64(ctx, 3); // uint64 + uint64_t issue_level = arg_get_u64(ctx, 4); // uint32, will be validated later + CLIParserFree(ctx); + + if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { + return PM3_EINVARG; + } + + // TODO: create data + + PrintAndLogEx(INFO, "Preparing to clone Gallagher from specified data."); + + // TODO: write data + + PrintAndLogEx(SUCCESS, "Done"); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf gallagher reader`") " to verify"); + return PM3_ENOTIMPL; +} + +static int CmdGallagherSim(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf gallagher sim", + "Enables simulation of GALLAGHER card with specified card number.\n" + "Simulation runs until the button is pressed or another USB command is issued.\n", + "hf gallagher sim --rc 1 --fc 22 --cn 3333 --il 4" + ); + + void *argtable[] = { + arg_param_begin, + arg_u64_1(NULL, "rc", "", "Region code. 4 bits max"), + arg_u64_1(NULL, "fc", "", "Facility code. 2 bytes max"), + arg_u64_1(NULL, "cn", "", "Card number. 3 bytes max"), + arg_u64_1(NULL, "il", "", "Issue level. 4 bits max"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + uint64_t region_code = arg_get_u64(ctx, 1); // uint16, will be validated later + uint64_t facility_code = arg_get_u64(ctx, 2); // uint32, will be validated later + uint64_t card_number = arg_get_u64(ctx, 3); // uint64 + uint64_t issue_level = arg_get_u64(ctx, 4); // uint32, will be validated later + CLIParserFree(ctx); + + if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { + return PM3_EINVARG; + } + + // TODO: create data + + // TODO: simulate + + return PM3_ENOTIMPL; +} + +static command_t CommandTable[] = { + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"reader", CmdGallagherReader, IfPm3Iso14443, "attempt to read and extract tag data"}, + {"clone", CmdGallagherClone, IfPm3Iso14443, "clone GALLAGHER tag to a blank DESFire card"}, + {"sim", CmdGallagherSim, IfPm3Iso14443, "simulate GALLAGHER tag"}, + {NULL, NULL, NULL, NULL} +}; + +static int CmdHelp(const char *Cmd) { + (void) Cmd; // Cmd is not used so far + CmdsHelp(CommandTable); + return PM3_SUCCESS; +} + +int CmdHFGallagher(const char *Cmd) { + clearCommandBuffer(); + return CmdsParse(CommandTable, Cmd); +} diff --git a/client/src/cmdhfgallagher.h b/client/src/cmdhfgallagher.h new file mode 100644 index 000000000..26faa11b0 --- /dev/null +++ b/client/src/cmdhfgallagher.h @@ -0,0 +1,20 @@ +/** + * Matt Moran (@DarkMatterMatt), 2021 + * ----------------------------------------------------------------------------- + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * ----------------------------------------------------------------------------- + * High frequency GALLAGHER tag commands. + * MIFARE DESFire, AIDs 2081F4-2F81F4 + */ +#ifndef CMDHFGALLAGHER_H__ +#define CMDHFGALLAGHER_H__ + +#include "common.h" + +int CmdHFGallagher(const char *Cmd); + +#endif + From 491c93e7151b2587b3f08771ec0aa1748db529b5 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Sat, 1 Jan 2022 17:34:53 +1300 Subject: [PATCH 04/26] Add CardholderCredentials struct --- client/src/cmdlfgallagher.c | 33 ++++++++++++++++++++----------- client/src/mifare/gallaghercore.c | 31 +++++++++++++++++------------ client/src/mifare/gallaghercore.h | 12 +++++++++-- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index c8d13d62b..ed46c8143 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -75,15 +75,12 @@ int demodGallagher(bool verbose) { uint8_t crc = bytebits_to_byte(g_DemodBuffer + 16 + (9 * 8), 8); uint8_t calc_crc = CRC8Cardx(arr, ARRAYLEN(arr)); - uint8_t region_code, issue_level; - uint16_t facility_code; - uint32_t card_number; - - decodeCardholderCredentials(arr, ®ion_code, &facility_code, &card_number, &issue_level); + GallagherCredentials_t creds = {0}; + decodeCardholderCredentials(arr, &creds); PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") " Facility: " _GREEN_("%u") " Card No.: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"), - region_code, facility_code, card_number, issue_level); - PrintAndLogEx(SUCCESS, " Displayed: " _GREEN_("%C%u"), region_code + 'A', facility_code); + creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); + PrintAndLogEx(SUCCESS, " Displayed: " _GREEN_("%C%u"), creds.region_code + 'A', creds.facility_code); PrintAndLogEx(SUCCESS, " Raw: %08X%08X%08X", raw1, raw2, raw3); PrintAndLogEx(SUCCESS, " CRC: %02X - %02X (%s)", crc, calc_crc, (crc == calc_crc) ? "ok" : "fail"); return PM3_SUCCESS; @@ -142,10 +139,10 @@ static void setBitsInBlocks(uint32_t *blocks, uint8_t *pos, uint32_t data, uint8 } } -static void createBlocks(uint32_t *blocks, uint8_t rc, uint16_t fc, uint32_t cn, uint8_t il) { +static void createBlocks(uint32_t *blocks, GallagherCredentials_t *creds) { // put data into the correct places (Gallagher obfuscation) - uint8_t arr[8] = { 0x00 }; - encodeCardholderCredentials(arr, rc, fc, cn, il); + uint8_t arr[8] = {0}; + encodeCardholderCredentials(arr, creds); blocks[0] = blocks[1] = blocks[2] = 0; uint8_t pos = 0; @@ -236,8 +233,14 @@ static int CmdGallagherClone(const char *Cmd) { blocks[i] = bytes_to_num(raw + ((i - 1) * 4), sizeof(uint32_t)); } } else { + GallagherCredentials_t creds = { + .region_code = region_code, + .facility_code = facility_code, + .card_number = card_number, + .issue_level = issue_level, + }; // fill blocks 1 to 3 with Gallagher data - createBlocks(blocks + 1, region_code, facility_code, card_number, issue_level); + createBlocks(blocks + 1, &creds); } //Pac - compat mode, NRZ, data rate 40, 3 data blocks @@ -326,8 +329,14 @@ static int CmdGallagherSim(const char *Cmd) { if (!use_raw) { // generate Gallagher data + GallagherCredentials_t creds = { + .region_code = region_code, + .facility_code = facility_code, + .card_number = card_number, + .issue_level = issue_level, + }; uint32_t blocks[3]; - createBlocks(blocks, region_code, facility_code, card_number, issue_level); + createBlocks(blocks, &creds); // convert to the normal 'raw' format for (int i = 0; i < ARRAYLEN(blocks); i++) { diff --git a/client/src/mifare/gallaghercore.c b/client/src/mifare/gallaghercore.c index 71ad88300..1613fd3c6 100644 --- a/client/src/mifare/gallaghercore.c +++ b/client/src/mifare/gallaghercore.c @@ -62,34 +62,39 @@ static void descramble(uint8_t *arr, uint8_t len) { } } -void decodeCardholderCredentials(uint8_t *eight_bytes, uint8_t *region_code, uint16_t *facility_code, uint32_t *card_number, uint8_t *issue_level) { +void decodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds) { uint8_t *arr = eight_bytes; descramble(arr, 8); // 4bit region code - *region_code = (arr[3] & 0x1E) >> 1; + creds->region_code = (arr[3] & 0x1E) >> 1; // 16bit facility code - *facility_code = (arr[5] & 0x0F) << 12 | arr[1] << 4 | ((arr[7] >> 4) & 0x0F); + creds->facility_code = (arr[5] & 0x0F) << 12 | arr[1] << 4 | ((arr[7] >> 4) & 0x0F); // 24bit card number - *card_number = arr[0] << 16 | (arr[4] & 0x1F) << 11 | arr[2] << 3 | (arr[3] & 0xE0) >> 5; + creds->card_number = arr[0] << 16 | (arr[4] & 0x1F) << 11 | arr[2] << 3 | (arr[3] & 0xE0) >> 5; // 4bit issue level - *issue_level = arr[7] & 0x0F; + creds->issue_level = arr[7] & 0x0F; } -void encodeCardholderCredentials(uint8_t *eight_bytes, uint8_t region_code, uint16_t facility_code, uint32_t card_number, uint8_t issue_level) { +void encodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds) { + uint8_t rc = creds->region_code; + uint8_t fc = creds->facility_code; + uint8_t cn = creds->card_number; + uint8_t il = creds->issue_level; + // put data into the correct places (Gallagher obfuscation) - eight_bytes[0] = (card_number & 0xffffff) >> 16; - eight_bytes[1] = (facility_code & 0xfff) >> 4; - eight_bytes[2] = (card_number & 0x7ff) >> 3; - eight_bytes[3] = (card_number & 0x7) << 5 | (region_code & 0xf) << 1; - eight_bytes[4] = (card_number & 0xffff) >> 11; - eight_bytes[5] = (facility_code & 0xffff) >> 12; + eight_bytes[0] = (cn & 0xffffff) >> 16; + eight_bytes[1] = (fc & 0xfff) >> 4; + eight_bytes[2] = (cn & 0x7ff) >> 3; + eight_bytes[3] = (cn & 0x7) << 5 | (rc & 0xf) << 1; + eight_bytes[4] = (cn & 0xffff) >> 11; + eight_bytes[5] = (fc & 0xffff) >> 12; eight_bytes[6] = 0; - eight_bytes[7] = (facility_code & 0xf) << 4 | (issue_level & 0xf); + eight_bytes[7] = (fc & 0xf) << 4 | (il & 0xf); // more obfuscation scramble(eight_bytes, 8); diff --git a/client/src/mifare/gallaghercore.h b/client/src/mifare/gallaghercore.h index e55f2e693..37164f92e 100644 --- a/client/src/mifare/gallaghercore.h +++ b/client/src/mifare/gallaghercore.h @@ -12,10 +12,18 @@ #define MIFARE_GALLAGHERCORE_H__ #include "common.h" +#include -void encodeCardholderCredentials(uint8_t *eight_bytes, uint8_t region_code, uint16_t facility_code, uint32_t card_number, uint8_t issue_level); +typedef struct { + uint8_t region_code; + uint16_t facility_code; + uint32_t card_number; + uint8_t issue_level; +} GallagherCredentials_t; -void decodeCardholderCredentials(uint8_t *eight_bytes, uint8_t *region_code, uint16_t *facility_code, uint32_t *card_number, uint8_t *issue_level); +void encodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds); + +void decodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds); bool isValidGallagherCredentials(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level); From 13ff8d50cfadf3ecbf7922323200d5322db2ebdb Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Sat, 1 Jan 2022 22:22:57 +1300 Subject: [PATCH 05/26] Add `hf gallagher reader` command --- client/src/cmdhfgallagher.c | 192 ++++++++++++++++++++++++++++++++++-- client/src/cmdhfgallagher.h | 4 +- 2 files changed, 186 insertions(+), 10 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 90fff183c..d80bea83a 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -11,39 +11,213 @@ */ #include "cmdhfgallagher.h" +#include "mifare.h" +#include "mifare/desfirecore.h" #include "mifare/gallaghercore.h" #include +#include #include "common.h" +#include "commonutil.h" #include "cmdparser.h" #include "cliparser.h" #include "ui.h" +static void reverseAid(uint8_t *aid) { + uint8_t tmp = aid[0]; + aid[0] = aid[2]; + aid[2] = tmp; +}; + static int CmdHelp(const char *Cmd); +static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, uint8_t destBufLen, uint8_t *numEntries, bool verbose) { + if (destBufLen != 3 * 36) { + PrintAndLogEx(ERR, "readCardApplicationDirectory destination buffer is incorrectly sized. " + "Received length %d, expected %d", destBufLen, 3 * 36); + return PM3_EINVARG; + } + + DesfireSetCommMode(ctx, DCMPlain); + + // Get card AIDs from Card Application Directory (which contains 1 to 3 files) + uint8_t cadAid[] = { 0xF4, 0x81, 0x2F }; + int res = DesfireSelectAID(ctx, cadAid, NULL); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Read up to 3 files with 6x 6-byte entries each + for (uint8_t i = 0; i < 3; i++) { + size_t readLen; + DesfireReadFile(ctx, i, 0, 36, &destBuf[i * 36], &readLen); + } + + // Keep only valid entries + *numEntries = 0; + for (uint8_t i = 0; i < destBufLen; i += 6) { + if (memcmp(&destBuf[i], "\0\0\0\0\0\0", 6) == 0) break; + *numEntries += 1; + } + + if (verbose) { + // Print what we found + PrintAndLogEx(SUCCESS, "Card Application Directory contains:" NOLF); + for (int i = 0; i < *numEntries; i++) + PrintAndLogEx(NORMAL, "%s %06x" NOLF, (i == 0) ? "" : ",", DesfireAIDByteToUint(&destBuf[i*6 + 3])); + PrintAndLogEx(NORMAL, ""); + } + + return PM3_SUCCESS; +} + +static int readCardApplicationCredentials(DesfireContext_t *ctx, uint8_t *aid, uint8_t *sitekey, GallagherCredentials_t *creds, bool verbose) { + // Check that card UID has been set + if (ctx->uidlen == 0) { + PrintAndLogEx(ERR, "Card UID must be set in DesfireContext (required for key diversification)"); + return PM3_EINVARG; + } + + // Set up context + DesfireSetKeyNoClear(ctx, 2, T_AES, sitekey); + DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); + DesfireSetCommMode(ctx, DCMPlain); + DesfireSetCommandSet(ctx, DCCNativeISO); + + // Select and authenticate to AID + int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, le24toh(aid), false, verbose); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Read file 0 (contains credentials) + uint8_t buf[16] = { 0x00 }; + size_t readLen = 0; + DesfireSetCommMode(ctx, DCMEncrypted); + res = DesfireReadFile(ctx, 0, 0, 16, buf, &readLen); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Check file contained 16 bytes of data + if (readLen != 16) { + PrintAndLogEx(ERR, "Failed reading file 0 in %06x", DesfireAIDByteToUint(aid)); + return PM3_EFAILED; + } + + // Check second half of file is the bitwise inverse of the first half + for (uint8_t i = 8; i < 16; i++) + buf[i] ^= 0xFF; + if (memcmp(buf, &buf[8], 8) != 0) { + PrintAndLogEx(ERR, "Invalid cardholder data in file 0. Received %s", sprint_hex_inrow(buf, 16)); + return PM3_EFAILED; + } + + decodeCardholderCredentials(buf, creds); + + // TODO: read MIFARE Enhanced Security file + // https://github.com/megabug/gallagher-research/blob/master/formats/mes.md + + return PM3_SUCCESS; +} + +static int readCard(uint8_t *aid, uint8_t *sitekey, bool verbose, bool continuousMode) { + DropField(); + clearCommandBuffer(); + + // Set up context + DesfireContext_t dctx = {0}; + DesfireClearContext(&dctx); + + // Get card UID (for key diversification) + int res = DesfireGetCardUID(&dctx); + HF_GALLAGHER_FAIL_IF_ERROR(res, verbose || !continuousMode, "Failed retrieving card UID."); + + // Find AIDs to process (from CLI args or the Card Application Directory) + uint8_t cad[36 * 3] = {0}; + uint8_t numEntries = 0; + if (aid != NULL) { + memcpy(&cad[3], aid, 3); + reverseAid(&cad[3]); // CAD stores AIDs backwards + numEntries = 1; + } else { + res = readCardApplicationDirectory(&dctx, cad, ARRAYLEN(cad), &numEntries, verbose); + HF_GALLAGHER_FAIL_IF_ERROR(res, verbose || !continuousMode, "Failed reading card application directory."); + } + + // Loop through each application in the CAD + for (uint8_t i = 0; i < numEntries * 6; i += 6) { + uint16_t region_code = cad[i + 0]; + uint16_t facility_code = (cad[i + 1] << 8) + cad[i + 2]; + + // Copy AID out of CAD record + uint8_t currentAid[3]; + memcpy(currentAid, &cad[3], 3); + reverseAid(currentAid); // CAD stores AIDs backwards + + if (verbose) { + if (region_code > 0 || facility_code > 0) + PrintAndLogEx(INFO, "Reading AID: %06x, region: %u, facility: %u", DesfireAIDByteToUint(currentAid), region_code, facility_code); + else + PrintAndLogEx(INFO, "Reading AID: %06x", DesfireAIDByteToUint(currentAid)); + } + + // Read & decode credentials + GallagherCredentials_t creds = {0}; + res = readCardApplicationCredentials(&dctx, currentAid, sitekey, &creds, verbose); + HF_GALLAGHER_FAIL_IF_ERROR(res, verbose || !continuousMode, "Failed reading card application credentials."); + + PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), + creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); + } + + return PM3_SUCCESS; +} + static int CmdGallagherReader(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher reader", "read a GALLAGHER tag", - "hf gallagher reader -@ -> continuous reader mode" + "hf gallagher reader --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" + " -> act as a reader that doesn't skips the Card Application Directory and uses a non-default site key\n" + "hf gallagher reader -@ -> continuous reader mode" ); void *argtable[] = { arg_param_begin, - arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_str0(NULL, "aid", "", "Application ID to read (3 bytes)"), + arg_str1("k", "sitekey", "", "Master site key to compute diversified keys (16 bytes)"), + arg_lit0(NULL, "apdu", "show APDU requests and responses"), + arg_lit0("v", "verbose", "Verbose mode"), + arg_lit0("@", "continuous", "Continuous reader mode"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); - bool cm = arg_get_lit(ctx, 1); - CLIParserFree(ctx); - if (cm) { - PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); + int aidLen = 0; + uint8_t aid[3] = {0}; + CLIGetHexWithReturn(ctx, 1, aid, &aidLen); + if (aidLen > 0 && aidLen != 3) { + PrintAndLogEx(ERR, "--aid must be 3 bytes"); + return PM3_EINVARG; + } + reverseAid(aid); // PM3 displays AIDs backwards + + int sitekeyLen = 0; + uint8_t sitekey[16] = {0}; + CLIGetHexWithReturn(ctx, 2, sitekey, &sitekeyLen); + if (sitekeyLen > 0 && sitekeyLen != 16) { + PrintAndLogEx(ERR, "--sitekey must be 16 bytes"); + return PM3_EINVARG; } + SetAPDULogging(arg_get_lit(ctx, 3)); + bool verbose = arg_get_lit(ctx, 4); + bool continuousMode = arg_get_lit(ctx, 5); + CLIParserFree(ctx); + + if (continuousMode) + PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); + + int res; do { - // read - } while (cm && !kbd_enter_pressed()); - return PM3_SUCCESS; + res = readCard(aidLen > 0 ? aid : NULL, sitekey, verbose, continuousMode); + } while (continuousMode && !kbd_enter_pressed()); + + return continuousMode ? PM3_SUCCESS : res; } static int CmdGallagherClone(const char *Cmd) { diff --git a/client/src/cmdhfgallagher.h b/client/src/cmdhfgallagher.h index 26faa11b0..ba1073fe2 100644 --- a/client/src/cmdhfgallagher.h +++ b/client/src/cmdhfgallagher.h @@ -16,5 +16,7 @@ int CmdHFGallagher(const char *Cmd); -#endif +#define HF_GALLAGHER_RETURN_IF_ERROR(res) if (res != PM3_SUCCESS) { return res; } +#define HF_GALLAGHER_FAIL_IF_ERROR(res, verbose, reason) if (res != PM3_SUCCESS) { if (verbose) PrintAndLogEx(ERR, reason " Error code %d", res); DropField(); return res; } +#endif From 7b0a85a0af4dbd96bd96189a5795aacb4e97cd57 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Mon, 3 Jan 2022 16:39:18 +1300 Subject: [PATCH 06/26] Fix incorrect types in `encodeCardholderCredentials` --- client/src/mifare/gallaghercore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/mifare/gallaghercore.c b/client/src/mifare/gallaghercore.c index 1613fd3c6..adb72b65c 100644 --- a/client/src/mifare/gallaghercore.c +++ b/client/src/mifare/gallaghercore.c @@ -82,8 +82,8 @@ void decodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *c void encodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds) { uint8_t rc = creds->region_code; - uint8_t fc = creds->facility_code; - uint8_t cn = creds->card_number; + uint16_t fc = creds->facility_code; + uint32_t cn = creds->card_number; uint8_t il = creds->issue_level; // put data into the correct places (Gallagher obfuscation) From aed687cb9620307441f611c27fedbe8fc6572b32 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Mon, 3 Jan 2022 17:02:10 +1300 Subject: [PATCH 07/26] Add basic cloning support --- client/src/cmdhfgallagher.c | 354 ++++++++++++++++++++++++++++++++++-- client/src/cmdhfgallagher.h | 15 ++ 2 files changed, 355 insertions(+), 14 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index d80bea83a..2365c2703 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -11,6 +11,7 @@ */ #include "cmdhfgallagher.h" +#include "generator.h" #include "mifare.h" #include "mifare/desfirecore.h" #include "mifare/gallaghercore.h" @@ -48,6 +49,8 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, for (uint8_t i = 0; i < 3; i++) { size_t readLen; DesfireReadFile(ctx, i, 0, 36, &destBuf[i * 36], &readLen); + // end if the last entry is NULL + if (memcmp(&destBuf[36 * i + 30], "\0\0\0\0\0\0", 6) == 0) break; } // Keep only valid entries @@ -82,11 +85,11 @@ static int readCardApplicationCredentials(DesfireContext_t *ctx, uint8_t *aid, u DesfireSetCommandSet(ctx, DCCNativeISO); // Select and authenticate to AID - int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, le24toh(aid), false, verbose); + int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, DesfireAIDByteToUint(aid), false, verbose); HF_GALLAGHER_RETURN_IF_ERROR(res); // Read file 0 (contains credentials) - uint8_t buf[16] = { 0x00 }; + uint8_t buf[16] = {0}; size_t readLen = 0; DesfireSetCommMode(ctx, DCMEncrypted); res = DesfireReadFile(ctx, 0, 0, 16, buf, &readLen); @@ -220,39 +223,362 @@ static int CmdGallagherReader(const char *Cmd) { return continuousMode ? PM3_SUCCESS : res; } +int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNo, uint32_t aid, uint8_t *keyOut) { + // Generate diversification input + uint8_t kdfInputLen = 11; + int res = mfdes_kdf_input_gallagher(uid, uidLen, keyNo, aid, keyOut, &kdfInputLen); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Make temporary DesfireContext + DesfireContext_t dctx = {0}; + DesfireSetKey(&dctx, 0, T_AES, sitekey); + + // Diversify input & copy to output buffer + MifareKdfAn10922(&dctx, DCOMasterKey, keyOut, kdfInputLen); + memcpy(keyOut, dctx.key, CRYPTO_AES128_KEY_SIZE); + + return PM3_SUCCESS; +} + +static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t *sitekey, uint8_t *aid, bool verbose) { + DesfireSetCommMode(ctx, DCMPlain); + DesfireSetCommandSet(ctx, DCCNativeISO); + int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, 0x000000, false, verbose); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Create application + DesfireCryptoAlgorithm dstalgo = T_AES; + uint8_t keycount = 3; + uint8_t ks1 = 0x0B; + uint8_t ks2 = (DesfireKeyAlgoToType(dstalgo) << 6) | keycount;; + + uint8_t data[5] = {0}; + memcpy(&data[0], aid, 3); + data[3] = ks1; + data[4] = ks2; + + DesfireSetCommMode(ctx, DCMMACed); + res = DesfireCreateApplication(ctx, data, ARRAYLEN(data)); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Select the new application + DesfireSetCommMode(ctx, DCMPlain); + res = DesfireSelectEx(ctx, true, ISW6bAID, DesfireAIDByteToUint(aid), NULL); + HF_GALLAGHER_RETURN_IF_ERROR(res); + if (verbose) + PrintAndLogEx(INFO, "AID: %06x is " _GREEN_("selected"), DesfireAIDByteToUint(aid)); + + // Add key 2, then key 0 (we must authenticate with key 0 in order to make changes) + for (int i = 2; i >= 0; i -= 2) { + // Diversify key + uint8_t buf[CRYPTO_AES128_KEY_SIZE] = {0}; + res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, i, DesfireAIDByteToUint(aid), buf); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + if (verbose) + PrintAndLogEx(INFO, " Diversified key %d: " _GREEN_("%s"), i, sprint_hex_inrow(buf, ARRAYLEN(buf))); + + // Authenticate + uint8_t blankKey[DESFIRE_MAX_KEY_SIZE] = {0}; + DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); + DesfireSetCommMode(ctx, DCMPlain); + res = DesfireAuthenticate(ctx, DACEV1, verbose); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Change key + DesfireSetCommMode(ctx, DCMEncryptedPlain); + res = DesfireChangeKey(ctx, false, i, dstalgo, 1, buf, dstalgo, blankKey, true); + HF_GALLAGHER_RETURN_IF_ERROR(res); + if (verbose) + PrintAndLogEx(INFO, " Successfully set key %d", i); + } + + return PM3_SUCCESS; +} + +static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *sitekey, uint8_t *aid, GallagherCredentials_t *creds, bool verbose) { + // Set up context + DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); + DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); + DesfireSetCommMode(ctx, DCMPlain); + + // Select application + int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, DesfireAIDByteToUint(aid), false, verbose); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Prepare create file command + uint8_t fileType = 0; // standard data file + uint8_t fileId = 0x00; + uint8_t fileSize = 16; + uint8_t fileAccessMode = 0x03; // encrypted + uint32_t fileRights = 0x2000; // key 0 has God mode, key 2 can read + + uint8_t data[7] = {0}; + data[0] = fileId; + data[1] = fileAccessMode; + data[2] = fileRights & 0xff; + data[3] = (fileRights >> 8) & 0xff; + Uint3byteToMemLe(&data[4], fileSize); + + // Create file + res = DesfireCreateFile(ctx, fileType, data, ARRAYLEN(data), false); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Create file contents (2nd half is the bitwise inverse of the encoded creds) + uint8_t contents[16] = {0}; + encodeCardholderCredentials(contents, creds); + for (int i = 0; i < 8; i++) + contents[i + 8] = contents[i] ^ 0xFF; + + // Write file + DesfireSetCommMode(ctx, DCMEncrypted); + res = DesfireWriteFile(ctx, fileId, 0, ARRAYLEN(contents), contents); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + return PM3_SUCCESS; +} + +static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verbose) { + DesfireClearSession(ctx); + DesfireSetCommMode(ctx, DCMPlain); + DesfireSetCommandSet(ctx, DCCNativeISO); + int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, 0x000000, false, verbose); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Create application + uint32_t aid = 0x2F81F4; + DesfireCryptoAlgorithm dstalgo = T_AES; + uint8_t keycount = 1; + uint8_t ks1 = 0x0B; + uint8_t ks2 = (DesfireKeyAlgoToType(dstalgo) << 6) | keycount;; + + uint8_t data[5] = {0}; + DesfireAIDUintToByte(aid, &data[0]); + data[3] = ks1; + data[4] = ks2; + + DesfireSetCommMode(ctx, DCMMACed); + res = DesfireCreateApplication(ctx, data, ARRAYLEN(data)); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Select the new application + DesfireSetCommMode(ctx, DCMPlain); + res = DesfireSelectEx(ctx, true, ISW6bAID, aid, NULL); + HF_GALLAGHER_RETURN_IF_ERROR(res); + if (verbose) + PrintAndLogEx(INFO, "AID: %06x is " _GREEN_("selected"), aid); + + // Diversify key + uint8_t buf[CRYPTO_AES128_KEY_SIZE] = {0}; + res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, 0, aid, buf); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + if (verbose) + PrintAndLogEx(INFO, " Diversified key 0: " _GREEN_("%s"), sprint_hex_inrow(buf, ARRAYLEN(buf))); + + // Authenticate + uint8_t blankKey[DESFIRE_MAX_KEY_SIZE] = {0}; + DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); + DesfireSetCommMode(ctx, DCMPlain); + res = DesfireAuthenticate(ctx, DACEV1, verbose); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Change key + DesfireSetCommMode(ctx, DCMEncryptedPlain); + res = DesfireChangeKey(ctx, false, 0, dstalgo, 1, buf, dstalgo, blankKey, true); + HF_GALLAGHER_RETURN_IF_ERROR(res); + if (verbose) + PrintAndLogEx(INFO, " Successfully set key 0"); + + return PM3_SUCCESS; +} + +static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint8_t *aid, GallagherCredentials_t *creds, bool verbose) { + uint32_t cadAid = 0x2F81F4; + + + // Check if CAD exists + uint8_t cad[36 * 3] = {0}; + uint8_t numEntries = 0; + int res = DesfireSelectEx(ctx, true, ISW6bAID, cadAid, NULL); + if (res == PM3_SUCCESS) { + res = readCardApplicationDirectory(ctx, cad, ARRAYLEN(cad), &numEntries, verbose); + HF_GALLAGHER_RETURN_IF_ERROR(res); + } else { + DesfireSetCommandSet(ctx, DCCNativeISO); + res = createGallagherCAD(ctx, sitekey, verbose); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Check that there is space for the new entry + if (numEntries == 18) { + PrintAndLogEx(ERR, "Card application directory is full."); + return PM3_EFATAL; + } + } + + uint8_t fileId = numEntries / 6; // 6 entries per file + uint8_t entryNum = numEntries % 6; + + // Create entry + uint8_t *entry = &cad[numEntries * 6]; + entry[0] = creds->region_code; + entry[1] = (creds->facility_code >> 8) & 0xFF; + entry[2] = creds->facility_code & 0xFF; + memcpy(&entry[3], aid, 3); + reverseAid(&entry[3]); // CAD stores AIDs backwards + + // Set up context + DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); + DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); + DesfireSetCommMode(ctx, DCMPlain); + + // Select application + res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, cadAid, false, verbose); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Create file if necessary + if (entryNum == 0) { + // Prepare create file command + uint8_t fileType = 0; // standard data file + uint8_t fileSize = 36; + uint8_t fileAccessMode = 0x00; // plain + uint32_t fileRights = 0xE000; // key 0 has God mode, everyone can read + + uint8_t data[7] = {0}; + data[0] = fileId; + data[1] = fileAccessMode; + data[2] = fileRights & 0xff; + data[3] = (fileRights >> 8) & 0xff; + Uint3byteToMemLe(&data[4], fileSize); + + // Create file + res = DesfireCreateFile(ctx, fileType, data, ARRAYLEN(data), false); + HF_GALLAGHER_RETURN_IF_ERROR(res); + + // Write file + res = DesfireWriteFile(ctx, fileId, fileId * 36, 36, entry); + HF_GALLAGHER_RETURN_IF_ERROR(res); + } else { + // Write file + res = DesfireWriteFile(ctx, fileId, entryNum * 6, 6, entry); + HF_GALLAGHER_RETURN_IF_ERROR(res); + } + + return PM3_SUCCESS; +} + static int CmdGallagherClone(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher clone", "clone a GALLAGHER card to a blank DESFire card.", - "hf gallagher clone --rc 1 --fc 22 --cn 3333 --il 4" + "hf gallagher clone --rc 1 --fc 22 --cn 3333 --il 4 --sitekey 00112233445566778899aabbccddeeff" ); void *argtable[] = { arg_param_begin, - arg_u64_1(NULL, "rc", "", "Region code. 4 bits max"), - arg_u64_1(NULL, "fc", "", "Facility code. 2 bytes max"), - arg_u64_1(NULL, "cn", "", "Card number. 3 bytes max"), - arg_u64_1(NULL, "il", "", "Issue level. 4 bits max"), + arg_lit0(NULL, "apdu", "show APDU requests and responses"), + arg_lit0("v", "verbose", "Verbose mode"), + arg_int0("n", "keyno", "", "Key number [default=0]"), + arg_str0("t", "algo", "", "Crypt algo: DES, 2TDEA, 3TDEA, AES"), + arg_str0("k", "key", "", "Key for authenticate (HEX 8(DES), 16(2TDEA or AES) or 24(3TDEA) bytes)"), + + arg_u64_1(NULL, "rc", "", "Region code. 4 bits max"), + arg_u64_1(NULL, "fc", "", "Facility code. 2 bytes max"), + arg_u64_1(NULL, "cn", "", "Card number. 3 bytes max"), + arg_u64_1(NULL, "il", "", "Issue level. 4 bits max"), + arg_str0(NULL, "aid", "", "Application ID to write (3 bytes) [default=2081F4]"), + arg_str1(NULL, "sitekey", "", "Master site key to compute diversified keys (16 bytes)"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); - uint64_t region_code = arg_get_u64(ctx, 1); // uint16, will be validated later - uint64_t facility_code = arg_get_u64(ctx, 2); // uint32, will be validated later - uint64_t card_number = arg_get_u64(ctx, 3); // uint64 - uint64_t issue_level = arg_get_u64(ctx, 4); // uint32, will be validated later + SetAPDULogging(arg_get_lit(ctx, 1)); + bool verbose = arg_get_lit(ctx, 2) || true; + int keyNum = arg_get_int_def(ctx, 3, 0); + + int algo = T_DES; + if (CLIGetOptionList(arg_get_str(ctx, 4), DesfireAlgoOpts, &algo)) return PM3_ESOFT; + + int keyLen = 0; + uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0}; + CLIGetHexWithReturn(ctx, 5, key, &keyLen); + if (keyLen && keyLen != desfire_get_key_length(algo)) { + PrintAndLogEx(ERR, "%s key must have %d bytes length instead of %d.", CLIGetOptionListStr(DesfireAlgoOpts, algo), desfire_get_key_length(algo), keyLen); + return PM3_EINVARG; + } + if (keyLen == 0) { + // Default to a key of all zeros + keyLen = desfire_get_key_length(algo); + } + + uint64_t region_code = arg_get_u64(ctx, 6); // uint16, will be validated later + uint64_t facility_code = arg_get_u64(ctx, 7); // uint32, will be validated later + uint64_t card_number = arg_get_u64(ctx, 8); // uint64 + uint64_t issue_level = arg_get_u64(ctx, 9); // uint32, will be validated later + + int aidLen = 0; + uint8_t aid[3] = "\x20\x81\xF4"; + CLIGetHexWithReturn(ctx, 10, aid, &aidLen); + if (aidLen > 0 && aidLen != 3) { + PrintAndLogEx(ERR, "--aid must be 3 bytes"); + return PM3_EINVARG; + } + reverseAid(aid); // PM3 displays AIDs backwards + + // Check that the AID is in the expected range + if (memcmp(aid, "\xF4\x81", 2) != 0 || aid[2] < 0x20 || aid[2] > 0x2B) { + PrintAndLogEx(WARNING, "Invalid Gallagher AID %06X, expected 2?81F4.", DesfireAIDByteToUint(aid)); + } + + int sitekeyLen = 0; + uint8_t sitekey[16] = {0}; + CLIGetHexWithReturn(ctx, 11, sitekey, &sitekeyLen); + if (sitekeyLen > 0 && sitekeyLen != 16) { + PrintAndLogEx(ERR, "--sitekey must be 16 bytes"); + return PM3_EINVARG; + } CLIParserFree(ctx); if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { return PM3_EINVARG; } + GallagherCredentials_t creds = { + .region_code = region_code, + .facility_code = facility_code, + .card_number = card_number, + .issue_level = issue_level, + }; - // TODO: create data + // Set up context + DropField(); + DesfireContext_t dctx = {0}; + DesfireClearContext(&dctx); - PrintAndLogEx(INFO, "Preparing to clone Gallagher from specified data."); + // Get card UID (for key diversification) + int res = DesfireGetCardUID(&dctx); + HF_GALLAGHER_FAIL_IF_ERROR(res, true, "Failed retrieving card UID."); - // TODO: write data + // Create application + DesfireSetKeyNoClear(&dctx, keyNum, algo, key); + DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); + res = createGallagherCredentialsApplication(&dctx, sitekey, aid, verbose); + HF_GALLAGHER_FAIL_IF_ERROR(res, true, "Failed creating Gallagher application."); + DropField(); + // Create credential files + // Don't need to set keys here, they're generated automatically + res = createGallagherCredentialsFile(&dctx, sitekey, aid, &creds, verbose); + HF_GALLAGHER_FAIL_IF_ERROR(res, true, "Failed creating Gallagher credential file."); + DropField(); + + // Update card application directory + DesfireSetKeyNoClear(&dctx, keyNum, algo, key); + DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); + res = updateGallagherCAD(&dctx, sitekey, aid, &creds, verbose); + HF_GALLAGHER_FAIL_IF_ERROR(res, true, "Failed updating Gallagher card application directory."); + DropField(); + + DropField(); PrintAndLogEx(SUCCESS, "Done"); PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf gallagher reader`") " to verify"); return PM3_ENOTIMPL; diff --git a/client/src/cmdhfgallagher.h b/client/src/cmdhfgallagher.h index ba1073fe2..0baef92f7 100644 --- a/client/src/cmdhfgallagher.h +++ b/client/src/cmdhfgallagher.h @@ -13,9 +13,24 @@ #define CMDHFGALLAGHER_H__ #include "common.h" +#include int CmdHFGallagher(const char *Cmd); +/** + * @brief Create Gallagher Application Master Key by diversifying + * the MIFARE Site Key with card UID, key number, and application ID. + * + * @param sitekey MIFARE Site Key (16 bytes). + * @param uid Card unique ID (4 or 7 bytes). + * @param uidLen Length of UID. + * @param keyNum Key number (0 <= keyNum <= 2). + * @param aid Application ID (0x2?81F4 where 0 <= ? <= B). + * @param keyOut Buffer to copy the diversified key into (must be 16 bytes). + * @return PM3_SUCCESS if successful, PM3_EINVARG if an argument is invalid. + */ +int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNum, uint32_t aid, uint8_t *keyOut); + #define HF_GALLAGHER_RETURN_IF_ERROR(res) if (res != PM3_SUCCESS) { return res; } #define HF_GALLAGHER_FAIL_IF_ERROR(res, verbose, reason) if (res != PM3_SUCCESS) { if (verbose) PrintAndLogEx(ERR, reason " Error code %d", res); DropField(); return res; } From 863cf1601556d8029779a16f4c17a37d2144138e Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Tue, 4 Jan 2022 16:59:59 +1300 Subject: [PATCH 08/26] Add comments and logging --- client/src/cmdhfgallagher.c | 371 +++++++++++++++++++++--------------- client/src/cmdhfgallagher.h | 9 +- 2 files changed, 224 insertions(+), 156 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 2365c2703..572e65e41 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -23,6 +23,9 @@ #include "cliparser.h" #include "ui.h" +/** + * @brief Reverses the bytes in aid. Used when encoding/decoding Card Application Directory entries. + */ static void reverseAid(uint8_t *aid) { uint8_t tmp = aid[0]; aid[0] = aid[2]; @@ -31,29 +34,37 @@ static void reverseAid(uint8_t *aid) { static int CmdHelp(const char *Cmd); +/** + * @brief Read Gallagher Card Application Directory from card. + * + * @param destBuf Buffer to copy Card Application Directory into. + * @param destBufLen Size of destBuf. Must be at least 108 bytes. + * @param numEntries Will be set to the number of entries in the Card Application Directory. + */ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, uint8_t destBufLen, uint8_t *numEntries, bool verbose) { - if (destBufLen != 3 * 36) { + if (destBufLen < 3 * 36) { PrintAndLogEx(ERR, "readCardApplicationDirectory destination buffer is incorrectly sized. " - "Received length %d, expected %d", destBufLen, 3 * 36); + "Received length %d, must be at least %d", destBufLen, 3 * 36); return PM3_EINVARG; } - DesfireSetCommMode(ctx, DCMPlain); - // Get card AIDs from Card Application Directory (which contains 1 to 3 files) - uint8_t cadAid[] = { 0xF4, 0x81, 0x2F }; - int res = DesfireSelectAID(ctx, cadAid, NULL); - HF_GALLAGHER_RETURN_IF_ERROR(res); + DesfireSetCommMode(ctx, DCMPlain); + int res = DesfireSelectAIDHex(ctx, 0x2F81F4, false, 0); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting Card Application Directory, does AID F4812F exist?"); // Read up to 3 files with 6x 6-byte entries each for (uint8_t i = 0; i < 3; i++) { size_t readLen; - DesfireReadFile(ctx, i, 0, 36, &destBuf[i * 36], &readLen); + res = DesfireReadFile(ctx, i, 0, 36, &destBuf[i * 36], &readLen); + if (res != PM3_SUCCESS) + PrintAndLogEx(WARNING, "Failed reading file %d in Card Application Directory (AID F4812F)", i); + // end if the last entry is NULL if (memcmp(&destBuf[36 * i + 30], "\0\0\0\0\0\0", 6) == 0) break; } - // Keep only valid entries + // Count number of entries (i.e. count until we hit a NULL entry) *numEntries = 0; for (uint8_t i = 0; i < destBufLen; i += 6) { if (memcmp(&destBuf[i], "\0\0\0\0\0\0", 6) == 0) break; @@ -64,49 +75,51 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, // Print what we found PrintAndLogEx(SUCCESS, "Card Application Directory contains:" NOLF); for (int i = 0; i < *numEntries; i++) - PrintAndLogEx(NORMAL, "%s %06x" NOLF, (i == 0) ? "" : ",", DesfireAIDByteToUint(&destBuf[i*6 + 3])); + PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", DesfireAIDByteToUint(&destBuf[i*6 + 3])); PrintAndLogEx(NORMAL, ""); } return PM3_SUCCESS; } -static int readCardApplicationCredentials(DesfireContext_t *ctx, uint8_t *aid, uint8_t *sitekey, GallagherCredentials_t *creds, bool verbose) { +/** + * @brief Read credentials from a single AID. + * + * @param aid Application ID to read. + * @param sitekey MIFARE site key. + * @param creds Decoded credentials will be stored in this structure. + */ +static int readCardApplicationCredentials(DesfireContext_t *ctx, uint32_t aid, uint8_t *sitekey, GallagherCredentials_t *creds, bool verbose) { // Check that card UID has been set - if (ctx->uidlen == 0) { - PrintAndLogEx(ERR, "Card UID must be set in DesfireContext (required for key diversification)"); - return PM3_EINVARG; - } + if (ctx->uidlen == 0) + HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext (required for key diversification)"); // Set up context DesfireSetKeyNoClear(ctx, 2, T_AES, sitekey); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); DesfireSetCommMode(ctx, DCMPlain); - DesfireSetCommandSet(ctx, DCCNativeISO); // Select and authenticate to AID - int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, DesfireAIDByteToUint(aid), false, verbose); - HF_GALLAGHER_RETURN_IF_ERROR(res); + int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, aid, false, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting/authenticating to AID %06X", aid); // Read file 0 (contains credentials) uint8_t buf[16] = {0}; size_t readLen = 0; DesfireSetCommMode(ctx, DCMEncrypted); res = DesfireReadFile(ctx, 0, 0, 16, buf, &readLen); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed reading file 0 in AID %06X", aid); // Check file contained 16 bytes of data if (readLen != 16) { - PrintAndLogEx(ERR, "Failed reading file 0 in %06x", DesfireAIDByteToUint(aid)); - return PM3_EFAILED; + HFGAL_RET_ERR(PM3_EFAILED, "Failed reading file 0 in AID %06X, expected 16 bytes but received %d bytes", aid, readLen); } // Check second half of file is the bitwise inverse of the first half for (uint8_t i = 8; i < 16; i++) buf[i] ^= 0xFF; if (memcmp(buf, &buf[8], 8) != 0) { - PrintAndLogEx(ERR, "Invalid cardholder data in file 0. Received %s", sprint_hex_inrow(buf, 16)); - return PM3_EFAILED; + HFGAL_RET_ERR(PM3_EFAILED, "Invalid cardholder data in file 0 in AID %06X. Received %s", sprint_hex_inrow(buf, 16)); } decodeCardholderCredentials(buf, creds); @@ -117,7 +130,14 @@ static int readCardApplicationCredentials(DesfireContext_t *ctx, uint8_t *aid, u return PM3_SUCCESS; } -static int readCard(uint8_t *aid, uint8_t *sitekey, bool verbose, bool continuousMode) { +/** + * @brief Read credentials from a Gallagher card. + * + * @param aid Application ID to read. If 0, then the Card Application Directory will be queried and all entries will be read. + * @param sitekey MIFARE site key. + * @param quiet Suppress error messages. Used when in continuous reader mode. + */ +static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { DropField(); clearCommandBuffer(); @@ -127,41 +147,42 @@ static int readCard(uint8_t *aid, uint8_t *sitekey, bool verbose, bool continuou // Get card UID (for key diversification) int res = DesfireGetCardUID(&dctx); - HF_GALLAGHER_FAIL_IF_ERROR(res, verbose || !continuousMode, "Failed retrieving card UID."); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed retrieving card UID."); // Find AIDs to process (from CLI args or the Card Application Directory) uint8_t cad[36 * 3] = {0}; uint8_t numEntries = 0; - if (aid != NULL) { - memcpy(&cad[3], aid, 3); + if (aid != 0) { + DesfireAIDUintToByte(aid, &cad[3]); reverseAid(&cad[3]); // CAD stores AIDs backwards numEntries = 1; } else { res = readCardApplicationDirectory(&dctx, cad, ARRAYLEN(cad), &numEntries, verbose); - HF_GALLAGHER_FAIL_IF_ERROR(res, verbose || !continuousMode, "Failed reading card application directory."); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application directory."); } // Loop through each application in the CAD for (uint8_t i = 0; i < numEntries * 6; i += 6) { - uint16_t region_code = cad[i + 0]; - uint16_t facility_code = (cad[i + 1] << 8) + cad[i + 2]; + uint16_t regionCode = cad[i + 0]; + uint16_t facilityCode = (cad[i + 1] << 8) + cad[i + 2]; // Copy AID out of CAD record - uint8_t currentAid[3]; - memcpy(currentAid, &cad[3], 3); - reverseAid(currentAid); // CAD stores AIDs backwards + uint8_t currentAidBuf[3]; + memcpy(currentAidBuf, &cad[3], 3); + reverseAid(currentAidBuf); // CAD stores AIDs backwards + uint32_t currentAid = DesfireAIDByteToUint(currentAidBuf); if (verbose) { - if (region_code > 0 || facility_code > 0) - PrintAndLogEx(INFO, "Reading AID: %06x, region: %u, facility: %u", DesfireAIDByteToUint(currentAid), region_code, facility_code); + if (regionCode > 0 || facilityCode > 0) + PrintAndLogEx(INFO, "Reading AID: %06X, region: %u, facility: %u", currentAid, regionCode, facilityCode); else - PrintAndLogEx(INFO, "Reading AID: %06x", DesfireAIDByteToUint(currentAid)); + PrintAndLogEx(INFO, "Reading AID: %06X", currentAid); } // Read & decode credentials GallagherCredentials_t creds = {0}; res = readCardApplicationCredentials(&dctx, currentAid, sitekey, &creds, verbose); - HF_GALLAGHER_FAIL_IF_ERROR(res, verbose || !continuousMode, "Failed reading card application credentials."); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application credentials."); PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); @@ -191,43 +212,43 @@ static int CmdGallagherReader(const char *Cmd) { CLIExecWithReturn(ctx, Cmd, argtable, true); int aidLen = 0; - uint8_t aid[3] = {0}; - CLIGetHexWithReturn(ctx, 1, aid, &aidLen); - if (aidLen > 0 && aidLen != 3) { - PrintAndLogEx(ERR, "--aid must be 3 bytes"); - return PM3_EINVARG; - } - reverseAid(aid); // PM3 displays AIDs backwards + uint8_t aidBuf[3] = {0}; + CLIGetHexWithReturn(ctx, 1, aidBuf, &aidLen); + if (aidLen > 0 && aidLen != 3) + HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); + + reverseAid(aidBuf); // PM3 displays AIDs backwards + uint32_t aid = DesfireAIDByteToUint(aidBuf); int sitekeyLen = 0; uint8_t sitekey[16] = {0}; CLIGetHexWithReturn(ctx, 2, sitekey, &sitekeyLen); - if (sitekeyLen > 0 && sitekeyLen != 16) { - PrintAndLogEx(ERR, "--sitekey must be 16 bytes"); - return PM3_EINVARG; - } + if (sitekeyLen > 0 && sitekeyLen != 16) + HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); SetAPDULogging(arg_get_lit(ctx, 3)); bool verbose = arg_get_lit(ctx, 4); bool continuousMode = arg_get_lit(ctx, 5); CLIParserFree(ctx); - if (continuousMode) - PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); + if (!continuousMode) { + // Read single card + return readCard(aid, sitekey, verbose, false); + } - int res; - do { - res = readCard(aidLen > 0 ? aid : NULL, sitekey, verbose, continuousMode); - } while (continuousMode && !kbd_enter_pressed()); - - return continuousMode ? PM3_SUCCESS : res; + // Loop until is pressed + PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); + while (!kbd_enter_pressed()) { + readCard(aid, sitekey, verbose, !verbose); + } + return PM3_SUCCESS; } int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNo, uint32_t aid, uint8_t *keyOut) { // Generate diversification input uint8_t kdfInputLen = 11; int res = mfdes_kdf_input_gallagher(uid, uidLen, keyNo, aid, keyOut, &kdfInputLen); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed generating Gallagher key diversification input."); // Make temporary DesfireContext DesfireContext_t dctx = {0}; @@ -240,11 +261,21 @@ int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_ return PM3_SUCCESS; } -static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t *sitekey, uint8_t *aid, bool verbose) { +/** + * @brief Create a new application to store Gallagher cardholder credentials. + * + * @param sitekey MIFARE site key. + * @param aid New application ID. Should be 0x2?81F4, where 0 <= ? <= 0xB. + */ +static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, bool verbose) { DesfireSetCommMode(ctx, DCMPlain); DesfireSetCommandSet(ctx, DCCNativeISO); int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, 0x000000, false, verbose); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR(res); + + // UID is required for key diversification + if (ctx->uidlen == 0) + HFGAL_RET_ERR(PM3_EINVARG, "UID is required for key diversification. Please fetch it before calling `createGallagherCredentialsApplication`."); // Create application DesfireCryptoAlgorithm dstalgo = T_AES; @@ -253,58 +284,67 @@ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t uint8_t ks2 = (DesfireKeyAlgoToType(dstalgo) << 6) | keycount;; uint8_t data[5] = {0}; - memcpy(&data[0], aid, 3); + DesfireAIDUintToByte(aid, &data[0]); data[3] = ks1; data[4] = ks2; DesfireSetCommMode(ctx, DCMMACed); res = DesfireCreateApplication(ctx, data, ARRAYLEN(data)); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating application %06X. Does it already exist?", aid); + + if (verbose) + PrintAndLogEx(INFO, "Created application %06X (current has empty contents & blank keys)", aid); // Select the new application DesfireSetCommMode(ctx, DCMPlain); - res = DesfireSelectEx(ctx, true, ISW6bAID, DesfireAIDByteToUint(aid), NULL); - HF_GALLAGHER_RETURN_IF_ERROR(res); - if (verbose) - PrintAndLogEx(INFO, "AID: %06x is " _GREEN_("selected"), DesfireAIDByteToUint(aid)); + res = DesfireSelectEx(ctx, true, ISW6bAID, aid, NULL); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting application %06X", aid); // Add key 2, then key 0 (we must authenticate with key 0 in order to make changes) for (int i = 2; i >= 0; i -= 2) { // Diversify key uint8_t buf[CRYPTO_AES128_KEY_SIZE] = {0}; - res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, i, DesfireAIDByteToUint(aid), buf); - HF_GALLAGHER_RETURN_IF_ERROR(res); + res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, i, aid, buf); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key %d for AID %06X", i, aid); - if (verbose) - PrintAndLogEx(INFO, " Diversified key %d: " _GREEN_("%s"), i, sprint_hex_inrow(buf, ARRAYLEN(buf))); + PrintAndLogEx(INFO, "Diversified key %d for AID %06X: " _GREEN_("%s"), i, aid, sprint_hex_inrow(buf, ARRAYLEN(buf))); // Authenticate - uint8_t blankKey[DESFIRE_MAX_KEY_SIZE] = {0}; + uint8_t blankKey[CRYPTO_AES128_KEY_SIZE] = {0}; DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); DesfireSetCommMode(ctx, DCMPlain); res = DesfireAuthenticate(ctx, DACEV1, verbose); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Desfire authenticate error. Result: [%d] %s", res, DesfireAuthErrorToStr(res)); // Change key DesfireSetCommMode(ctx, DCMEncryptedPlain); - res = DesfireChangeKey(ctx, false, i, dstalgo, 1, buf, dstalgo, blankKey, true); - HF_GALLAGHER_RETURN_IF_ERROR(res); + res = DesfireChangeKey(ctx, false, i, dstalgo, 1, buf, dstalgo, blankKey, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed setting key %d for AID %06X", i, aid); + if (verbose) - PrintAndLogEx(INFO, " Successfully set key %d", i); + PrintAndLogEx(INFO, "Successfully set key %d for AID %06X", i, aid); } + PrintAndLogEx(INFO, "Successfully created credentials application %06X", aid); return PM3_SUCCESS; } -static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *sitekey, uint8_t *aid, GallagherCredentials_t *creds, bool verbose) { +/** + * @brief Create a new file containing Gallagher cardholder credentials. + * + * @param sitekey MIFARE site key. + * @param aid Application ID to put the new file in. + * @param creds Gallagher cardholder credentials. + */ +static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, GallagherCredentials_t *creds, bool verbose) { // Set up context DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); DesfireSetCommMode(ctx, DCMPlain); // Select application - int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, DesfireAIDByteToUint(aid), false, verbose); - HF_GALLAGHER_RETURN_IF_ERROR(res); + int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, aid, false, verbose); + HFGAL_RET_IF_ERR(res); // Prepare create file command uint8_t fileType = 0; // standard data file @@ -322,7 +362,10 @@ static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *siteke // Create file res = DesfireCreateFile(ctx, fileType, data, ARRAYLEN(data), false); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file 0 in AID %06X", aid); + + if (verbose) + PrintAndLogEx(INFO, "Created file 0 in AID %06X (current has empty contents)", aid); // Create file contents (2nd half is the bitwise inverse of the encoded creds) uint8_t contents[16] = {0}; @@ -333,17 +376,28 @@ static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *siteke // Write file DesfireSetCommMode(ctx, DCMEncrypted); res = DesfireWriteFile(ctx, fileId, 0, ARRAYLEN(contents), contents); - HF_GALLAGHER_RETURN_IF_ERROR(res); - + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file 0 in AID %06X"); + + PrintAndLogEx(INFO, "Successfully wrote cardholder credentials to file 0 in AID %06X", aid); return PM3_SUCCESS; } +/** + * @brief Create the Gallagher Card Application Directory. + * + * @param sitekey MIFARE site key. + */ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verbose) { + // Check that card UID has been set + if (ctx->uidlen == 0) + HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext (required for key diversification)"); + DesfireClearSession(ctx); DesfireSetCommMode(ctx, DCMPlain); DesfireSetCommandSet(ctx, DCCNativeISO); + int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, 0x000000, false, verbose); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR(res); // Create application uint32_t aid = 0x2F81F4; @@ -359,61 +413,68 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb DesfireSetCommMode(ctx, DCMMACed); res = DesfireCreateApplication(ctx, data, ARRAYLEN(data)); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Card Application Directory. Does it already exist?", aid); - // Select the new application - DesfireSetCommMode(ctx, DCMPlain); - res = DesfireSelectEx(ctx, true, ISW6bAID, aid, NULL); - HF_GALLAGHER_RETURN_IF_ERROR(res); if (verbose) - PrintAndLogEx(INFO, "AID: %06x is " _GREEN_("selected"), aid); + PrintAndLogEx(INFO, "Created Card Application Directory (AID %06X, current has empty contents & blank keys)", aid); + + // Select & authenticate + uint8_t blankKey[DESFIRE_MAX_KEY_SIZE] = {0}; + DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); + DesfireSetCommMode(ctx, DCMPlain); + DesfireSetCommandSet(ctx, DCCNativeISO); + res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, aid, false, verbose); + HFGAL_RET_IF_ERR(res); // Diversify key uint8_t buf[CRYPTO_AES128_KEY_SIZE] = {0}; res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, 0, aid, buf); - HF_GALLAGHER_RETURN_IF_ERROR(res); - - if (verbose) - PrintAndLogEx(INFO, " Diversified key 0: " _GREEN_("%s"), sprint_hex_inrow(buf, ARRAYLEN(buf))); - - // Authenticate - uint8_t blankKey[DESFIRE_MAX_KEY_SIZE] = {0}; - DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); - DesfireSetCommMode(ctx, DCMPlain); - res = DesfireAuthenticate(ctx, DACEV1, verbose); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key 0 for AID %06X", aid); + + PrintAndLogEx(INFO, "Diversified key 0 for CAD (AID %06X): " _GREEN_("%s"), aid, sprint_hex_inrow(buf, ARRAYLEN(buf))); // Change key DesfireSetCommMode(ctx, DCMEncryptedPlain); - res = DesfireChangeKey(ctx, false, 0, dstalgo, 1, buf, dstalgo, blankKey, true); - HF_GALLAGHER_RETURN_IF_ERROR(res); - if (verbose) - PrintAndLogEx(INFO, " Successfully set key 0"); + res = DesfireChangeKey(ctx, false, 0, dstalgo, 1, buf, dstalgo, blankKey, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed setting key 0 for CAD"); + if (verbose) + PrintAndLogEx(INFO, "Successfully set key 0 for CAD"); + + PrintAndLogEx(INFO, "Successfully created Card Application Directory (AID %06X)", aid); return PM3_SUCCESS; } -static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint8_t *aid, GallagherCredentials_t *creds, bool verbose) { +/** + * @brief Update the Gallagher Card Application Directory with a new entry. + * + * @param sitekey MIFARE site key. + * @param aid Application ID to add to the CAD. + * @param creds Gallagher cardholder credentials (region_code & facility_code are required). + */ +static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, GallagherCredentials_t *creds, bool verbose) { uint32_t cadAid = 0x2F81F4; - // Check if CAD exists uint8_t cad[36 * 3] = {0}; uint8_t numEntries = 0; int res = DesfireSelectEx(ctx, true, ISW6bAID, cadAid, NULL); if (res == PM3_SUCCESS) { + if (verbose) + PrintAndLogEx(INFO, "Card Application Directory exists, reading entries..."); + res = readCardApplicationDirectory(ctx, cad, ARRAYLEN(cad), &numEntries, verbose); - HF_GALLAGHER_RETURN_IF_ERROR(res); - } else { - DesfireSetCommandSet(ctx, DCCNativeISO); - res = createGallagherCAD(ctx, sitekey, verbose); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR(res); // Check that there is space for the new entry - if (numEntries == 18) { - PrintAndLogEx(ERR, "Card application directory is full."); - return PM3_EFATAL; - } + if (numEntries >= 18) + HFGAL_RET_ERR(PM3_EFATAL, "Card application directory is full."); + } else { + if (verbose) + PrintAndLogEx(INFO, "Card Application Directory does not exist, creating it now..."); + + res = createGallagherCAD(ctx, sitekey, verbose); + HFGAL_RET_IF_ERR(res); } uint8_t fileId = numEntries / 6; // 6 entries per file @@ -424,20 +485,27 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint8_t * entry[0] = creds->region_code; entry[1] = (creds->facility_code >> 8) & 0xFF; entry[2] = creds->facility_code & 0xFF; - memcpy(&entry[3], aid, 3); + DesfireAIDUintToByte(aid, &entry[3]); reverseAid(&entry[3]); // CAD stores AIDs backwards + if (verbose) + PrintAndLogEx(INFO, "Adding entry to CAD (position %d in file %d): %s", entryNum, fileId, sprint_hex_inrow(entry, 6)); + // Set up context DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); DesfireSetCommMode(ctx, DCMPlain); + DesfireSetCommandSet(ctx, DCCNativeISO); // Select application res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, cadAid, false, verbose); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR(res); // Create file if necessary if (entryNum == 0) { + if (verbose) + PrintAndLogEx(INFO, "Creating new file in CAD"); + // Prepare create file command uint8_t fileType = 0; // standard data file uint8_t fileSize = 36; @@ -453,17 +521,20 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint8_t * // Create file res = DesfireCreateFile(ctx, fileType, data, ARRAYLEN(data), false); - HF_GALLAGHER_RETURN_IF_ERROR(res); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file %d in CAD (AID %06X)", fileId, cadAid); + + if (verbose) + PrintAndLogEx(INFO, "Created file %d in CAD (current has empty contents)", fileId); // Write file res = DesfireWriteFile(ctx, fileId, fileId * 36, 36, entry); - HF_GALLAGHER_RETURN_IF_ERROR(res); } else { // Write file res = DesfireWriteFile(ctx, fileId, entryNum * 6, 6, entry); - HF_GALLAGHER_RETURN_IF_ERROR(res); } - + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", fileId, cadAid); + + PrintAndLogEx(INFO, "Successfully added new entry for %06X to the Card Application Directory", aid); return PM3_SUCCESS; } @@ -503,8 +574,7 @@ static int CmdGallagherClone(const char *Cmd) { uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0}; CLIGetHexWithReturn(ctx, 5, key, &keyLen); if (keyLen && keyLen != desfire_get_key_length(algo)) { - PrintAndLogEx(ERR, "%s key must have %d bytes length instead of %d.", CLIGetOptionListStr(DesfireAlgoOpts, algo), desfire_get_key_length(algo), keyLen); - return PM3_EINVARG; + HFGAL_RET_ERR(PM3_EINVARG, "%s key must have %d bytes length instead of %d", CLIGetOptionListStr(DesfireAlgoOpts, algo), desfire_get_key_length(algo), keyLen); } if (keyLen == 0) { // Default to a key of all zeros @@ -517,31 +587,29 @@ static int CmdGallagherClone(const char *Cmd) { uint64_t issue_level = arg_get_u64(ctx, 9); // uint32, will be validated later int aidLen = 0; - uint8_t aid[3] = "\x20\x81\xF4"; - CLIGetHexWithReturn(ctx, 10, aid, &aidLen); + uint8_t aidBuf[3] = "\x20\x81\xF4"; + CLIGetHexWithReturn(ctx, 10, aidBuf, &aidLen); if (aidLen > 0 && aidLen != 3) { - PrintAndLogEx(ERR, "--aid must be 3 bytes"); - return PM3_EINVARG; + HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); } - reverseAid(aid); // PM3 displays AIDs backwards + reverseAid(aidBuf); // PM3 displays AIDs backwards + uint32_t aid = DesfireAIDByteToUint(aidBuf); // Check that the AID is in the expected range - if (memcmp(aid, "\xF4\x81", 2) != 0 || aid[2] < 0x20 || aid[2] > 0x2B) { - PrintAndLogEx(WARNING, "Invalid Gallagher AID %06X, expected 2?81F4.", DesfireAIDByteToUint(aid)); - } + if (memcmp(aidBuf, "\xF4\x81", 2) != 0 || aidBuf[2] < 0x20 || aidBuf[2] > 0x2B) + // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't + HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); int sitekeyLen = 0; uint8_t sitekey[16] = {0}; CLIGetHexWithReturn(ctx, 11, sitekey, &sitekeyLen); - if (sitekeyLen > 0 && sitekeyLen != 16) { - PrintAndLogEx(ERR, "--sitekey must be 16 bytes"); - return PM3_EINVARG; - } + if (sitekeyLen > 0 && sitekeyLen != 16) + HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); CLIParserFree(ctx); - if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { + if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) return PM3_EINVARG; - } + GallagherCredentials_t creds = { .region_code = region_code, .facility_code = facility_code, @@ -556,32 +624,28 @@ static int CmdGallagherClone(const char *Cmd) { // Get card UID (for key diversification) int res = DesfireGetCardUID(&dctx); - HF_GALLAGHER_FAIL_IF_ERROR(res, true, "Failed retrieving card UID."); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed retrieving card UID"); // Create application - DesfireSetKeyNoClear(&dctx, keyNum, algo, key); - DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); - res = createGallagherCredentialsApplication(&dctx, sitekey, aid, verbose); - HF_GALLAGHER_FAIL_IF_ERROR(res, true, "Failed creating Gallagher application."); - DropField(); + DesfireSetKeyNoClear(&dctx, keyNum, algo, key); + DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); + res = createGallagherCredentialsApplication(&dctx, sitekey, aid, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Gallagher application"); // Create credential files - // Don't need to set keys here, they're generated automatically - res = createGallagherCredentialsFile(&dctx, sitekey, aid, &creds, verbose); - HF_GALLAGHER_FAIL_IF_ERROR(res, true, "Failed creating Gallagher credential file."); - DropField(); + // Don't need to set keys here, they're generated automatically + res = createGallagherCredentialsFile(&dctx, sitekey, aid, &creds, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Gallagher credential file."); // Update card application directory - DesfireSetKeyNoClear(&dctx, keyNum, algo, key); - DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); - res = updateGallagherCAD(&dctx, sitekey, aid, &creds, verbose); - HF_GALLAGHER_FAIL_IF_ERROR(res, true, "Failed updating Gallagher card application directory."); - DropField(); + DesfireSetKeyNoClear(&dctx, keyNum, algo, key); + DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); + res = updateGallagherCAD(&dctx, sitekey, aid, &creds, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed updating Gallagher card application directory."); - DropField(); PrintAndLogEx(SUCCESS, "Done"); PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf gallagher reader`") " to verify"); - return PM3_ENOTIMPL; + return PM3_SUCCESS; } static int CmdGallagherSim(const char *Cmd) { @@ -608,9 +672,8 @@ static int CmdGallagherSim(const char *Cmd) { uint64_t issue_level = arg_get_u64(ctx, 4); // uint32, will be validated later CLIParserFree(ctx); - if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { + if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) return PM3_EINVARG; - } // TODO: create data diff --git a/client/src/cmdhfgallagher.h b/client/src/cmdhfgallagher.h index 0baef92f7..8d2509b00 100644 --- a/client/src/cmdhfgallagher.h +++ b/client/src/cmdhfgallagher.h @@ -31,7 +31,12 @@ int CmdHFGallagher(const char *Cmd); */ int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNum, uint32_t aid, uint8_t *keyOut); -#define HF_GALLAGHER_RETURN_IF_ERROR(res) if (res != PM3_SUCCESS) { return res; } -#define HF_GALLAGHER_FAIL_IF_ERROR(res, verbose, reason) if (res != PM3_SUCCESS) { if (verbose) PrintAndLogEx(ERR, reason " Error code %d", res); DropField(); return res; } +// Return error +#define HFGAL_RET_ERR(err, ...) { PrintAndLogEx(ERR, __VA_ARGS__); return err; } + +// HF GALlagher RETurn IF ERRor +#define HFGAL_RET_IF_ERR(res) if (res != PM3_SUCCESS) { return res; } +#define HFGAL_RET_IF_ERR_WITH_MSG(res, ...) if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, __VA_ARGS__); return res; } +#define HFGAL_RET_IF_ERR_MAYBE_MSG(res, verbose, ...) if (res != PM3_SUCCESS) { if (verbose) PrintAndLogEx(ERR, __VA_ARGS__); return res; } #endif From 1e3ed42f549a0dddcf37097bc62fd79d1decb757 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Tue, 4 Jan 2022 17:03:22 +1300 Subject: [PATCH 09/26] Extract CAD_AID to a constant --- client/src/cmdhfgallagher.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 572e65e41..728bf643e 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -23,6 +23,9 @@ #include "cliparser.h" #include "ui.h" +/** Application ID for the Gallagher Card Application Directory */ +static const uint32_t CAD_AID = 0x2F81F4; + /** * @brief Reverses the bytes in aid. Used when encoding/decoding Card Application Directory entries. */ @@ -50,7 +53,7 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, // Get card AIDs from Card Application Directory (which contains 1 to 3 files) DesfireSetCommMode(ctx, DCMPlain); - int res = DesfireSelectAIDHex(ctx, 0x2F81F4, false, 0); + int res = DesfireSelectAIDHex(ctx, CAD_AID, false, 0); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting Card Application Directory, does AID F4812F exist?"); // Read up to 3 files with 6x 6-byte entries each @@ -400,38 +403,37 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb HFGAL_RET_IF_ERR(res); // Create application - uint32_t aid = 0x2F81F4; DesfireCryptoAlgorithm dstalgo = T_AES; uint8_t keycount = 1; uint8_t ks1 = 0x0B; uint8_t ks2 = (DesfireKeyAlgoToType(dstalgo) << 6) | keycount;; uint8_t data[5] = {0}; - DesfireAIDUintToByte(aid, &data[0]); + DesfireAIDUintToByte(CAD_AID, &data[0]); data[3] = ks1; data[4] = ks2; DesfireSetCommMode(ctx, DCMMACed); res = DesfireCreateApplication(ctx, data, ARRAYLEN(data)); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Card Application Directory. Does it already exist?", aid); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Card Application Directory. Does it already exist?", CAD_AID); if (verbose) - PrintAndLogEx(INFO, "Created Card Application Directory (AID %06X, current has empty contents & blank keys)", aid); + PrintAndLogEx(INFO, "Created Card Application Directory (AID %06X, current has empty contents & blank keys)", CAD_AID); // Select & authenticate uint8_t blankKey[DESFIRE_MAX_KEY_SIZE] = {0}; DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); DesfireSetCommMode(ctx, DCMPlain); DesfireSetCommandSet(ctx, DCCNativeISO); - res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, aid, false, verbose); + res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, CAD_AID, false, verbose); HFGAL_RET_IF_ERR(res); // Diversify key uint8_t buf[CRYPTO_AES128_KEY_SIZE] = {0}; - res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, 0, aid, buf); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key 0 for AID %06X", aid); + res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, 0, CAD_AID, buf); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key 0 for AID %06X", CAD_AID); - PrintAndLogEx(INFO, "Diversified key 0 for CAD (AID %06X): " _GREEN_("%s"), aid, sprint_hex_inrow(buf, ARRAYLEN(buf))); + PrintAndLogEx(INFO, "Diversified key 0 for CAD (AID %06X): " _GREEN_("%s"), CAD_AID, sprint_hex_inrow(buf, ARRAYLEN(buf))); // Change key DesfireSetCommMode(ctx, DCMEncryptedPlain); @@ -441,7 +443,7 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb if (verbose) PrintAndLogEx(INFO, "Successfully set key 0 for CAD"); - PrintAndLogEx(INFO, "Successfully created Card Application Directory (AID %06X)", aid); + PrintAndLogEx(INFO, "Successfully created Card Application Directory (AID %06X)", CAD_AID); return PM3_SUCCESS; } @@ -453,12 +455,10 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb * @param creds Gallagher cardholder credentials (region_code & facility_code are required). */ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, GallagherCredentials_t *creds, bool verbose) { - uint32_t cadAid = 0x2F81F4; - // Check if CAD exists uint8_t cad[36 * 3] = {0}; uint8_t numEntries = 0; - int res = DesfireSelectEx(ctx, true, ISW6bAID, cadAid, NULL); + int res = DesfireSelectEx(ctx, true, ISW6bAID, CAD_AID, NULL); if (res == PM3_SUCCESS) { if (verbose) PrintAndLogEx(INFO, "Card Application Directory exists, reading entries..."); @@ -498,7 +498,7 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t DesfireSetCommandSet(ctx, DCCNativeISO); // Select application - res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, cadAid, false, verbose); + res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, CAD_AID, false, verbose); HFGAL_RET_IF_ERR(res); // Create file if necessary @@ -521,7 +521,7 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t // Create file res = DesfireCreateFile(ctx, fileType, data, ARRAYLEN(data), false); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file %d in CAD (AID %06X)", fileId, cadAid); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file %d in CAD (AID %06X)", fileId, CAD_AID); if (verbose) PrintAndLogEx(INFO, "Created file %d in CAD (current has empty contents)", fileId); @@ -532,7 +532,7 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t // Write file res = DesfireWriteFile(ctx, fileId, entryNum * 6, 6, entry); } - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", fileId, cadAid); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", fileId, CAD_AID); PrintAndLogEx(INFO, "Successfully added new entry for %06X to the Card Application Directory", aid); return PM3_SUCCESS; From 21b080e49a071632c58803293c87f43d9d85a65a Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Tue, 4 Jan 2022 17:42:05 +1300 Subject: [PATCH 10/26] Extract `selectAid` and `authenticate` commands --- client/src/cmdhfgallagher.c | 118 ++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 39 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 728bf643e..7067dcabc 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -27,7 +27,7 @@ static const uint32_t CAD_AID = 0x2F81F4; /** - * @brief Reverses the bytes in aid. Used when encoding/decoding Card Application Directory entries. + * @brief Reverses the bytes in AID. Used when encoding/decoding Card Application Directory entries. */ static void reverseAid(uint8_t *aid) { uint8_t tmp = aid[0]; @@ -35,7 +35,61 @@ static void reverseAid(uint8_t *aid) { aid[2] = tmp; }; -static int CmdHelp(const char *Cmd); +/** + * @brief Select application ID. + */ +static int selectAid(DesfireContext_t *ctx, uint32_t aid, bool verbose) { + // TODO: do these both need to be set? + DesfireSetCommMode(ctx, DCMPlain); + DesfireSetCommandSet(ctx, DCCNativeISO); + + if (verbose) + DesfirePrintContext(ctx); + + int res = DesfireSelectEx(ctx, true, ISW6bAID, aid, NULL); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Desfire AID %06X select " _RED_("error") ".", aid); + return 202; + } + + if (verbose) + PrintAndLogEx(INFO, "AID %06X is " _GREEN_("selected"), aid); + + return PM3_SUCCESS; +} + +/** + * @brief Authenticate to application. + */ +static int authenticate(DesfireContext_t *ctx, bool verbose) { + // TODO: do these both need to be set? + DesfireSetCommMode(ctx, DCMPlain); + DesfireSetCommandSet(ctx, DCCNativeISO); + + int res = DesfireAuthenticate(ctx, DACEV1, verbose); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Desfire authenticate " _RED_("error") ". Result: [%d] %s", res, DesfireAuthErrorToStr(res)); + return res; + } + + if (DesfireIsAuthenticated(ctx)) { + if (verbose) + PrintAndLogEx(INFO, "Desfire " _GREEN_("authenticated")); + } else + return 201; + + return PM3_SUCCESS; +} + +static int selectAidAndAuthenticate(DesfireContext_t *ctx, uint32_t aid, bool verbose) { + int res = selectAid(ctx, aid, verbose); + HFGAL_RET_IF_ERR(res); + + res = authenticate(ctx, verbose); + HFGAL_RET_IF_ERR(res); + + return PM3_SUCCESS; +} /** * @brief Read Gallagher Card Application Directory from card. @@ -52,16 +106,15 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, } // Get card AIDs from Card Application Directory (which contains 1 to 3 files) - DesfireSetCommMode(ctx, DCMPlain); - int res = DesfireSelectAIDHex(ctx, CAD_AID, false, 0); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting Card Application Directory, does AID F4812F exist?"); + int res = selectAid(ctx, CAD_AID, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting Card Application Directory, does AID %06X exist?", CAD_AID); // Read up to 3 files with 6x 6-byte entries each for (uint8_t i = 0; i < 3; i++) { size_t readLen; res = DesfireReadFile(ctx, i, 0, 36, &destBuf[i * 36], &readLen); if (res != PM3_SUCCESS) - PrintAndLogEx(WARNING, "Failed reading file %d in Card Application Directory (AID F4812F)", i); + PrintAndLogEx(WARNING, "Failed reading file %d in Card Application Directory (AID %06X)", i, CAD_AID); // end if the last entry is NULL if (memcmp(&destBuf[36 * i + 30], "\0\0\0\0\0\0", 6) == 0) break; @@ -78,6 +131,7 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, // Print what we found PrintAndLogEx(SUCCESS, "Card Application Directory contains:" NOLF); for (int i = 0; i < *numEntries; i++) + // TODO: check this prints correct byte order PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", DesfireAIDByteToUint(&destBuf[i*6 + 3])); PrintAndLogEx(NORMAL, ""); } @@ -97,13 +151,10 @@ static int readCardApplicationCredentials(DesfireContext_t *ctx, uint32_t aid, u if (ctx->uidlen == 0) HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext (required for key diversification)"); - // Set up context + // Select application & authenticate DesfireSetKeyNoClear(ctx, 2, T_AES, sitekey); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - DesfireSetCommMode(ctx, DCMPlain); - - // Select and authenticate to AID - int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, aid, false, verbose); + int res = selectAidAndAuthenticate(ctx, aid, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting/authenticating to AID %06X", aid); // Read file 0 (contains credentials) @@ -271,9 +322,8 @@ int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_ * @param aid New application ID. Should be 0x2?81F4, where 0 <= ? <= 0xB. */ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, bool verbose) { - DesfireSetCommMode(ctx, DCMPlain); - DesfireSetCommandSet(ctx, DCCNativeISO); - int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, 0x000000, false, verbose); + // Select application & authenticate + int res = selectAidAndAuthenticate(ctx, 0x000000, verbose); HFGAL_RET_IF_ERR(res); // UID is required for key diversification @@ -299,8 +349,7 @@ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t PrintAndLogEx(INFO, "Created application %06X (current has empty contents & blank keys)", aid); // Select the new application - DesfireSetCommMode(ctx, DCMPlain); - res = DesfireSelectEx(ctx, true, ISW6bAID, aid, NULL); + res = selectAid(ctx, aid, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting application %06X", aid); // Add key 2, then key 0 (we must authenticate with key 0 in order to make changes) @@ -315,8 +364,8 @@ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t // Authenticate uint8_t blankKey[CRYPTO_AES128_KEY_SIZE] = {0}; DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); - DesfireSetCommMode(ctx, DCMPlain); - res = DesfireAuthenticate(ctx, DACEV1, verbose); + DesfireSetKdf(ctx, MFDES_KDF_ALGO_NONE, NULL, 0); + res = authenticate(ctx, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Desfire authenticate error. Result: [%d] %s", res, DesfireAuthErrorToStr(res)); // Change key @@ -340,13 +389,10 @@ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t * @param creds Gallagher cardholder credentials. */ static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, GallagherCredentials_t *creds, bool verbose) { - // Set up context + // Select application & authenticate DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - DesfireSetCommMode(ctx, DCMPlain); - - // Select application - int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, aid, false, verbose); + int res = selectAidAndAuthenticate(ctx, aid, verbose); HFGAL_RET_IF_ERR(res); // Prepare create file command @@ -395,11 +441,8 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb if (ctx->uidlen == 0) HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext (required for key diversification)"); - DesfireClearSession(ctx); - DesfireSetCommMode(ctx, DCMPlain); - DesfireSetCommandSet(ctx, DCCNativeISO); - - int res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, 0x000000, false, verbose); + // Select application & authenticate + int res = selectAidAndAuthenticate(ctx, 0x000000, verbose); HFGAL_RET_IF_ERR(res); // Create application @@ -420,12 +463,11 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb if (verbose) PrintAndLogEx(INFO, "Created Card Application Directory (AID %06X, current has empty contents & blank keys)", CAD_AID); - // Select & authenticate + // Select application & authenticate uint8_t blankKey[DESFIRE_MAX_KEY_SIZE] = {0}; DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); - DesfireSetCommMode(ctx, DCMPlain); - DesfireSetCommandSet(ctx, DCCNativeISO); - res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, CAD_AID, false, verbose); + DesfireSetKdf(ctx, MFDES_KDF_ALGO_NONE, NULL, 0); + res = selectAidAndAuthenticate(ctx, CAD_AID, verbose); HFGAL_RET_IF_ERR(res); // Diversify key @@ -458,7 +500,7 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t // Check if CAD exists uint8_t cad[36 * 3] = {0}; uint8_t numEntries = 0; - int res = DesfireSelectEx(ctx, true, ISW6bAID, CAD_AID, NULL); + int res = selectAid(ctx, CAD_AID, verbose); if (res == PM3_SUCCESS) { if (verbose) PrintAndLogEx(INFO, "Card Application Directory exists, reading entries..."); @@ -491,14 +533,10 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t if (verbose) PrintAndLogEx(INFO, "Adding entry to CAD (position %d in file %d): %s", entryNum, fileId, sprint_hex_inrow(entry, 6)); - // Set up context + // Select application & authenticate DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - DesfireSetCommMode(ctx, DCMPlain); - DesfireSetCommandSet(ctx, DCCNativeISO); - - // Select application - res = DesfireSelectAndAuthenticateAppW(ctx, DACEV1, ISW6bAID, CAD_AID, false, verbose); + res = selectAidAndAuthenticate(ctx, CAD_AID, verbose); HFGAL_RET_IF_ERR(res); // Create file if necessary @@ -682,6 +720,8 @@ static int CmdGallagherSim(const char *Cmd) { return PM3_ENOTIMPL; } +static int CmdHelp(const char *Cmd); + static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"reader", CmdGallagherReader, IfPm3Iso14443, "attempt to read and extract tag data"}, From f395b2864318f8e228cc41b81d8923825743639a Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Tue, 4 Jan 2022 18:06:02 +1300 Subject: [PATCH 11/26] Extract `cadAidUintToByte` and `cadAidByteToUint` --- client/src/cmdhfgallagher.c | 47 +++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 7067dcabc..6426d0f18 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -27,13 +27,31 @@ static const uint32_t CAD_AID = 0x2F81F4; /** - * @brief Reverses the bytes in AID. Used when encoding/decoding Card Application Directory entries. + * @brief Reverses the bytes in AID. Used when parsing CLI args (because Proxmark displays AIDs in reverse byte order). */ static void reverseAid(uint8_t *aid) { uint8_t tmp = aid[0]; aid[0] = aid[2]; aid[2] = tmp; -}; +} + +/** + * @brief Converts a Card Application Directory format application ID to an integer. + * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDByteToUint(). + */ +static uint32_t cadAidByteToUint(uint8_t *data) { + return data[2] + (data[1] << 8) + (data[0] << 16); +} + +/** + * @brief Converts an integer application ID to Card Application Directory format. + * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDUintToByte(). + */ +static void cadAidUintToByte(uint32_t aid, uint8_t *data) { + data[2] = aid & 0xff; + data[1] = (aid >> 8) & 0xff; + data[0] = (aid >> 16) & 0xff; +} /** * @brief Select application ID. @@ -43,9 +61,6 @@ static int selectAid(DesfireContext_t *ctx, uint32_t aid, bool verbose) { DesfireSetCommMode(ctx, DCMPlain); DesfireSetCommandSet(ctx, DCCNativeISO); - if (verbose) - DesfirePrintContext(ctx); - int res = DesfireSelectEx(ctx, true, ISW6bAID, aid, NULL); if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, "Desfire AID %06X select " _RED_("error") ".", aid); @@ -53,7 +68,7 @@ static int selectAid(DesfireContext_t *ctx, uint32_t aid, bool verbose) { } if (verbose) - PrintAndLogEx(INFO, "AID %06X is " _GREEN_("selected"), aid); + PrintAndLogEx(INFO, "Selected AID %06X", aid); return PM3_SUCCESS; } @@ -66,7 +81,7 @@ static int authenticate(DesfireContext_t *ctx, bool verbose) { DesfireSetCommMode(ctx, DCMPlain); DesfireSetCommandSet(ctx, DCCNativeISO); - int res = DesfireAuthenticate(ctx, DACEV1, verbose); + int res = DesfireAuthenticate(ctx, DACEV1, false); if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, "Desfire authenticate " _RED_("error") ". Result: [%d] %s", res, DesfireAuthErrorToStr(res)); return res; @@ -74,7 +89,7 @@ static int authenticate(DesfireContext_t *ctx, bool verbose) { if (DesfireIsAuthenticated(ctx)) { if (verbose) - PrintAndLogEx(INFO, "Desfire " _GREEN_("authenticated")); + PrintAndLogEx(INFO, "Authenticated to AID %06X", ctx->selectedAID); } else return 201; @@ -131,8 +146,7 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, // Print what we found PrintAndLogEx(SUCCESS, "Card Application Directory contains:" NOLF); for (int i = 0; i < *numEntries; i++) - // TODO: check this prints correct byte order - PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", DesfireAIDByteToUint(&destBuf[i*6 + 3])); + PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", cadAidByteToUint(&destBuf[i*6 + 3])); PrintAndLogEx(NORMAL, ""); } @@ -207,8 +221,7 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { uint8_t cad[36 * 3] = {0}; uint8_t numEntries = 0; if (aid != 0) { - DesfireAIDUintToByte(aid, &cad[3]); - reverseAid(&cad[3]); // CAD stores AIDs backwards + cadAidUintToByte(aid, &cad[3]); numEntries = 1; } else { res = readCardApplicationDirectory(&dctx, cad, ARRAYLEN(cad), &numEntries, verbose); @@ -219,12 +232,7 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { for (uint8_t i = 0; i < numEntries * 6; i += 6) { uint16_t regionCode = cad[i + 0]; uint16_t facilityCode = (cad[i + 1] << 8) + cad[i + 2]; - - // Copy AID out of CAD record - uint8_t currentAidBuf[3]; - memcpy(currentAidBuf, &cad[3], 3); - reverseAid(currentAidBuf); // CAD stores AIDs backwards - uint32_t currentAid = DesfireAIDByteToUint(currentAidBuf); + uint32_t currentAid = cadAidByteToUint(&cad[i + 3]); if (verbose) { if (regionCode > 0 || facilityCode > 0) @@ -527,8 +535,7 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t entry[0] = creds->region_code; entry[1] = (creds->facility_code >> 8) & 0xFF; entry[2] = creds->facility_code & 0xFF; - DesfireAIDUintToByte(aid, &entry[3]); - reverseAid(&entry[3]); // CAD stores AIDs backwards + cadAidUintToByte(aid, &entry[3]); if (verbose) PrintAndLogEx(INFO, "Adding entry to CAD (position %d in file %d): %s", entryNum, fileId, sprint_hex_inrow(entry, 6)); From e129bee161be504200f0217d8f6d3747b731ae88 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Tue, 4 Jan 2022 18:06:20 +1300 Subject: [PATCH 12/26] Fix print level should be ERR, was FAILED --- client/src/mifare/gallaghercore.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/src/mifare/gallaghercore.c b/client/src/mifare/gallaghercore.c index adb72b65c..fb220eeb1 100644 --- a/client/src/mifare/gallaghercore.c +++ b/client/src/mifare/gallaghercore.c @@ -105,19 +105,19 @@ bool isValidGallagherCredentials(uint64_t region_code, uint64_t facility_code, u // validate input if (region_code > 0x0f) { - PrintAndLogEx(FAILED, "Region code must be 0 <= rc <= 15 (4 bits), received: %d", region_code); + PrintAndLogEx(ERR, "Region code must be 0 <= rc <= 15 (4 bits), received: %d", region_code); isValid = false; } if (facility_code > 0xffff) { - PrintAndLogEx(FAILED, "Facility code must be 0 <= fc <= 65535 (2 bytes), received: %d", facility_code); + PrintAndLogEx(ERR, "Facility code must be 0 <= fc <= 65535 (2 bytes), received: %d", facility_code); isValid = false; } if (card_number > 0xffffff) { - PrintAndLogEx(FAILED, "Card number must be 0 <= cn <= 16777215 (3 bytes), received: %d", card_number); + PrintAndLogEx(ERR, "Card number must be 0 <= cn <= 16777215 (3 bytes), received: %d", card_number); isValid = false; } if (issue_level > 0x0f) { - PrintAndLogEx(FAILED, "Issue level must be 0 <= il <= 15 (4 bits), received: %d", issue_level); + PrintAndLogEx(ERR, "Issue level must be 0 <= il <= 15 (4 bits), received: %d", issue_level); isValid = false; } return isValid; From 28844756d959ae721cc16e7066a658946973cc2b Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Tue, 4 Jan 2022 18:19:42 +1300 Subject: [PATCH 13/26] Add default MIFARE Site Key --- client/src/cmdhfgallagher.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 6426d0f18..d460cb253 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -26,6 +26,9 @@ /** Application ID for the Gallagher Card Application Directory */ static const uint32_t CAD_AID = 0x2F81F4; +/** Default MIFARE Site Key */ +static const uint8_t DEFAULT_SITE_KEY[] = { 0x31, 0x12, 0xB7, 0x38, 0xD8, 0x86, 0x2C, 0xCD, 0x34, 0x30, 0x2E, 0xB2, 0x99, 0xAA, 0xB4, 0x56 }; + /** * @brief Reverses the bytes in AID. Used when parsing CLI args (because Proxmark displays AIDs in reverse byte order). */ @@ -265,7 +268,7 @@ static int CmdGallagherReader(const char *Cmd) { void *argtable[] = { arg_param_begin, arg_str0(NULL, "aid", "", "Application ID to read (3 bytes)"), - arg_str1("k", "sitekey", "", "Master site key to compute diversified keys (16 bytes)"), + arg_str0("k", "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), arg_lit0(NULL, "apdu", "show APDU requests and responses"), arg_lit0("v", "verbose", "Verbose mode"), arg_lit0("@", "continuous", "Continuous reader mode"), @@ -284,6 +287,7 @@ static int CmdGallagherReader(const char *Cmd) { int sitekeyLen = 0; uint8_t sitekey[16] = {0}; + memcpy(sitekey, DEFAULT_SITE_KEY, ARRAYLEN(sitekey)); CLIGetHexWithReturn(ctx, 2, sitekey, &sitekeyLen); if (sitekeyLen > 0 && sitekeyLen != 16) HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); @@ -312,6 +316,12 @@ int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_ int res = mfdes_kdf_input_gallagher(uid, uidLen, keyNo, aid, keyOut, &kdfInputLen); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed generating Gallagher key diversification input."); + if (sitekey == NULL) { + PrintAndLogEx(INFO, "GallagherDiversifyKey is using default site key: %s", + sprint_hex_inrow(DEFAULT_SITE_KEY, ARRAYLEN(DEFAULT_SITE_KEY))); + sitekey = (uint8_t *) &DEFAULT_SITE_KEY; + } + // Make temporary DesfireContext DesfireContext_t dctx = {0}; DesfireSetKey(&dctx, 0, T_AES, sitekey); @@ -603,7 +613,7 @@ static int CmdGallagherClone(const char *Cmd) { arg_u64_1(NULL, "cn", "", "Card number. 3 bytes max"), arg_u64_1(NULL, "il", "", "Issue level. 4 bits max"), arg_str0(NULL, "aid", "", "Application ID to write (3 bytes) [default=2081F4]"), - arg_str1(NULL, "sitekey", "", "Master site key to compute diversified keys (16 bytes)"), + arg_str0(NULL, "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); @@ -647,6 +657,7 @@ static int CmdGallagherClone(const char *Cmd) { int sitekeyLen = 0; uint8_t sitekey[16] = {0}; + memcpy(sitekey, DEFAULT_SITE_KEY, ARRAYLEN(sitekey)); CLIGetHexWithReturn(ctx, 11, sitekey, &sitekeyLen); if (sitekeyLen > 0 && sitekeyLen != 16) HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); From d3da7985177d11612cbfe08d59c0a0f413728578 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Tue, 4 Jan 2022 21:14:18 +1300 Subject: [PATCH 14/26] Move `GallagherDiversifyKey` to top of file --- client/src/cmdhfgallagher.c | 52 +++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index d460cb253..ad87c9db2 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -56,6 +56,32 @@ static void cadAidUintToByte(uint32_t aid, uint8_t *data) { data[0] = (aid >> 16) & 0xff; } +/* + * See header file for description :) + */ +int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNo, uint32_t aid, uint8_t *keyOut) { + // Generate diversification input + uint8_t kdfInputLen = 11; + int res = mfdes_kdf_input_gallagher(uid, uidLen, keyNo, aid, keyOut, &kdfInputLen); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed generating Gallagher key diversification input."); + + if (sitekey == NULL) { + PrintAndLogEx(INFO, "GallagherDiversifyKey is using default site key: %s", + sprint_hex_inrow(DEFAULT_SITE_KEY, ARRAYLEN(DEFAULT_SITE_KEY))); + sitekey = (uint8_t *) &DEFAULT_SITE_KEY; + } + + // Make temporary DesfireContext + DesfireContext_t dctx = {0}; + DesfireSetKey(&dctx, 0, T_AES, sitekey); + + // Diversify input & copy to output buffer + MifareKdfAn10922(&dctx, DCOMasterKey, keyOut, kdfInputLen); + memcpy(keyOut, dctx.key, CRYPTO_AES128_KEY_SIZE); + + return PM3_SUCCESS; +} + /** * @brief Select application ID. */ @@ -99,6 +125,9 @@ static int authenticate(DesfireContext_t *ctx, bool verbose) { return PM3_SUCCESS; } +/** + * @brief Select application ID & authenticate. Uses existing authentication keys in context. + */ static int selectAidAndAuthenticate(DesfireContext_t *ctx, uint32_t aid, bool verbose) { int res = selectAid(ctx, aid, verbose); HFGAL_RET_IF_ERR(res); @@ -310,29 +339,6 @@ static int CmdGallagherReader(const char *Cmd) { return PM3_SUCCESS; } -int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNo, uint32_t aid, uint8_t *keyOut) { - // Generate diversification input - uint8_t kdfInputLen = 11; - int res = mfdes_kdf_input_gallagher(uid, uidLen, keyNo, aid, keyOut, &kdfInputLen); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed generating Gallagher key diversification input."); - - if (sitekey == NULL) { - PrintAndLogEx(INFO, "GallagherDiversifyKey is using default site key: %s", - sprint_hex_inrow(DEFAULT_SITE_KEY, ARRAYLEN(DEFAULT_SITE_KEY))); - sitekey = (uint8_t *) &DEFAULT_SITE_KEY; - } - - // Make temporary DesfireContext - DesfireContext_t dctx = {0}; - DesfireSetKey(&dctx, 0, T_AES, sitekey); - - // Diversify input & copy to output buffer - MifareKdfAn10922(&dctx, DCOMasterKey, keyOut, kdfInputLen); - memcpy(keyOut, dctx.key, CRYPTO_AES128_KEY_SIZE); - - return PM3_SUCCESS; -} - /** * @brief Create a new application to store Gallagher cardholder credentials. * From d7989caad00af61cb62a5f0ab43f5e05fb9b006b Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Tue, 4 Jan 2022 22:15:00 +1300 Subject: [PATCH 15/26] Automatically choose an new valid Gallagher AID --- client/src/cmdhfgallagher.c | 89 ++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 27 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index ad87c9db2..4e6789ced 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -138,6 +138,37 @@ static int selectAidAndAuthenticate(DesfireContext_t *ctx, uint32_t aid, bool ve return PM3_SUCCESS; } +/** + * @brief Returns true if the specified application exists, false otherwise. + */ +static bool aidExists(DesfireContext_t *ctx, uint32_t aid, bool verbose) { + // TODO: do these both need to be set? + DesfireSetCommMode(ctx, DCMPlain); + DesfireSetCommandSet(ctx, DCCNativeISO); + + int res = DesfireSelectAIDHex(ctx, aid, false, 0); + if (res != PM3_SUCCESS && res != PM3_EAPDU_FAIL) + HFGAL_RET_ERR(false, "Select failed with error %d, assuming AID %06X does not exist", res, aid); + + if (verbose) + PrintAndLogEx(INFO, "AID %06X %s", aid, res == PM3_SUCCESS ? "exists" : "does not exist"); + + return res == PM3_SUCCESS; +} + +/** + * @brief Returns the lowest available Gallagher application ID. + * @return 0 if no AID is available, or an AID in the range 0x2?81F4, where 0 <= ? <= 0xB. + */ +static uint32_t findAvailableGallagherAid(DesfireContext_t *ctx, bool verbose) { + for (uint8_t i = 0x0; i <= 0xB; i++) { + uint32_t aid = 0x2081F4 | (i << 16); + if (!aidExists(ctx, aid, verbose)) + return aid; + } + return 0; +} + /** * @brief Read Gallagher Card Application Directory from card. * @@ -278,8 +309,8 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { res = readCardApplicationCredentials(&dctx, currentAid, sitekey, &creds, verbose); HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application credentials."); - PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), - creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); + PrintAndLogEx(SUCCESS, "GALLAGHER (AID %06X) - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), + currentAid, creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); } return PM3_SUCCESS; @@ -326,16 +357,14 @@ static int CmdGallagherReader(const char *Cmd) { bool continuousMode = arg_get_lit(ctx, 5); CLIParserFree(ctx); - if (!continuousMode) { + if (!continuousMode) // Read single card return readCard(aid, sitekey, verbose, false); - } // Loop until is pressed PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); - while (!kbd_enter_pressed()) { + while (!kbd_enter_pressed()) readCard(aid, sitekey, verbose, !verbose); - } return PM3_SUCCESS; } @@ -524,12 +553,11 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t // Check if CAD exists uint8_t cad[36 * 3] = {0}; uint8_t numEntries = 0; - int res = selectAid(ctx, CAD_AID, verbose); - if (res == PM3_SUCCESS) { + if (aidExists(ctx, CAD_AID, verbose)) { if (verbose) PrintAndLogEx(INFO, "Card Application Directory exists, reading entries..."); - res = readCardApplicationDirectory(ctx, cad, ARRAYLEN(cad), &numEntries, verbose); + int res = readCardApplicationDirectory(ctx, cad, ARRAYLEN(cad), &numEntries, verbose); HFGAL_RET_IF_ERR(res); // Check that there is space for the new entry @@ -539,7 +567,7 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t if (verbose) PrintAndLogEx(INFO, "Card Application Directory does not exist, creating it now..."); - res = createGallagherCAD(ctx, sitekey, verbose); + int res = createGallagherCAD(ctx, sitekey, verbose); HFGAL_RET_IF_ERR(res); } @@ -559,7 +587,7 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t // Select application & authenticate DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - res = selectAidAndAuthenticate(ctx, CAD_AID, verbose); + int res = selectAidAndAuthenticate(ctx, CAD_AID, verbose); HFGAL_RET_IF_ERR(res); // Create file if necessary @@ -618,14 +646,14 @@ static int CmdGallagherClone(const char *Cmd) { arg_u64_1(NULL, "fc", "", "Facility code. 2 bytes max"), arg_u64_1(NULL, "cn", "", "Card number. 3 bytes max"), arg_u64_1(NULL, "il", "", "Issue level. 4 bits max"), - arg_str0(NULL, "aid", "", "Application ID to write (3 bytes) [default=2081F4]"), + arg_str0(NULL, "aid", "", "Application ID to write (3 bytes) [default finds lowest available in range 0x2?81F4, where 0 <= ? <= 0xB]"), arg_str0(NULL, "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); SetAPDULogging(arg_get_lit(ctx, 1)); - bool verbose = arg_get_lit(ctx, 2) || true; + bool verbose = arg_get_lit(ctx, 2); int keyNum = arg_get_int_def(ctx, 3, 0); int algo = T_DES; @@ -634,13 +662,11 @@ static int CmdGallagherClone(const char *Cmd) { int keyLen = 0; uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0}; CLIGetHexWithReturn(ctx, 5, key, &keyLen); - if (keyLen && keyLen != desfire_get_key_length(algo)) { + if (keyLen && keyLen != desfire_get_key_length(algo)) HFGAL_RET_ERR(PM3_EINVARG, "%s key must have %d bytes length instead of %d", CLIGetOptionListStr(DesfireAlgoOpts, algo), desfire_get_key_length(algo), keyLen); - } - if (keyLen == 0) { + if (keyLen == 0) // Default to a key of all zeros keyLen = desfire_get_key_length(algo); - } uint64_t region_code = arg_get_u64(ctx, 6); // uint16, will be validated later uint64_t facility_code = arg_get_u64(ctx, 7); // uint32, will be validated later @@ -648,18 +674,20 @@ static int CmdGallagherClone(const char *Cmd) { uint64_t issue_level = arg_get_u64(ctx, 9); // uint32, will be validated later int aidLen = 0; - uint8_t aidBuf[3] = "\x20\x81\xF4"; + uint8_t aidBuf[3] = {0}; + uint32_t aid = 0; CLIGetHexWithReturn(ctx, 10, aidBuf, &aidLen); - if (aidLen > 0 && aidLen != 3) { - HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); - } - reverseAid(aidBuf); // PM3 displays AIDs backwards - uint32_t aid = DesfireAIDByteToUint(aidBuf); + if (aidLen > 0) { + if (aidLen != 3) + HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); + reverseAid(aidBuf); // PM3 displays AIDs backwards + aid = DesfireAIDByteToUint(aidBuf); - // Check that the AID is in the expected range - if (memcmp(aidBuf, "\xF4\x81", 2) != 0 || aidBuf[2] < 0x20 || aidBuf[2] > 0x2B) - // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't - HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); + // Check that the AID is in the expected range + if (memcmp(aidBuf, "\xF4\x81", 2) != 0 || aidBuf[2] < 0x20 || aidBuf[2] > 0x2B) + // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't + HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); + } int sitekeyLen = 0; uint8_t sitekey[16] = {0}; @@ -688,6 +716,13 @@ static int CmdGallagherClone(const char *Cmd) { int res = DesfireGetCardUID(&dctx); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed retrieving card UID"); + // Find available Gallagher AID if the user did not specify one + if (aidLen == 0) { + aid = findAvailableGallagherAid(&dctx, verbose); + if (aid == 0) + HFGAL_RET_ERR(PM3_EFATAL, "Could not find an available AID, card is full"); + } + // Create application DesfireSetKeyNoClear(&dctx, keyNum, algo, key); DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); From 28437f018bc54d9374c2a28cabbea043e8f87625 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Tue, 4 Jan 2022 22:38:30 +1300 Subject: [PATCH 16/26] Check if facility already exists in CAD Disallow duplicate credentials for the same facility (because readers won't handle it properly - I assume they'll just use the first entry?) --- client/src/cmdhfgallagher.c | 76 ++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 4e6789ced..d314f3c5f 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -56,6 +56,13 @@ static void cadAidUintToByte(uint32_t aid, uint8_t *data) { data[0] = (aid >> 16) & 0xff; } +/** + * @brief Returns true if the Card Application Directory entry is for the specified region & facility, false otherwise. + */ +static bool cadFacilityMatch(uint8_t *entry, uint8_t regionCode, uint16_t facilityCode) { + return entry[0] == regionCode && (entry[1] << 8) + entry[2] == facilityCode; +} + /* * See header file for description :) */ @@ -63,7 +70,7 @@ int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_ // Generate diversification input uint8_t kdfInputLen = 11; int res = mfdes_kdf_input_gallagher(uid, uidLen, keyNo, aid, keyOut, &kdfInputLen); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed generating Gallagher key diversification input."); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed generating Gallagher key diversification input"); if (sitekey == NULL) { PrintAndLogEx(INFO, "GallagherDiversifyKey is using default site key: %s", @@ -92,7 +99,7 @@ static int selectAid(DesfireContext_t *ctx, uint32_t aid, bool verbose) { int res = DesfireSelectEx(ctx, true, ISW6bAID, aid, NULL); if (res != PM3_SUCCESS) { - PrintAndLogEx(ERR, "Desfire AID %06X select " _RED_("error") ".", aid); + PrintAndLogEx(ERR, "Desfire AID %06X select " _RED_("error"), aid); return 202; } @@ -191,8 +198,8 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, for (uint8_t i = 0; i < 3; i++) { size_t readLen; res = DesfireReadFile(ctx, i, 0, 36, &destBuf[i * 36], &readLen); - if (res != PM3_SUCCESS) - PrintAndLogEx(WARNING, "Failed reading file %d in Card Application Directory (AID %06X)", i, CAD_AID); + if (res != PM3_SUCCESS && res != PM3_EAPDU_FAIL) + HFGAL_RET_ERR(res, "Failed reading file %d in Card Application Directory (AID %06X)", i, CAD_AID); // end if the last entry is NULL if (memcmp(&destBuf[36 * i + 30], "\0\0\0\0\0\0", 6) == 0) break; @@ -278,7 +285,7 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { // Get card UID (for key diversification) int res = DesfireGetCardUID(&dctx); - HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed retrieving card UID."); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed retrieving card UID"); // Find AIDs to process (from CLI args or the Card Application Directory) uint8_t cad[36 * 3] = {0}; @@ -288,7 +295,7 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { numEntries = 1; } else { res = readCardApplicationDirectory(&dctx, cad, ARRAYLEN(cad), &numEntries, verbose); - HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application directory."); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application directory"); } // Loop through each application in the CAD @@ -307,7 +314,7 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { // Read & decode credentials GallagherCredentials_t creds = {0}; res = readCardApplicationCredentials(&dctx, currentAid, sitekey, &creds, verbose); - HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application credentials."); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application credentials"); PrintAndLogEx(SUCCESS, "GALLAGHER (AID %06X) - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), currentAid, creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); @@ -381,7 +388,7 @@ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t // UID is required for key diversification if (ctx->uidlen == 0) - HFGAL_RET_ERR(PM3_EINVARG, "UID is required for key diversification. Please fetch it before calling `createGallagherCredentialsApplication`."); + HFGAL_RET_ERR(PM3_EINVARG, "UID is required for key diversification. Please fetch it before calling `createGallagherCredentialsApplication`"); // Create application DesfireCryptoAlgorithm dstalgo = T_AES; @@ -399,7 +406,7 @@ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating application %06X. Does it already exist?", aid); if (verbose) - PrintAndLogEx(INFO, "Created application %06X (current has empty contents & blank keys)", aid); + PrintAndLogEx(INFO, "Created application %06X (currently has empty contents & blank keys)", aid); // Select the new application res = selectAid(ctx, aid, verbose); @@ -467,7 +474,7 @@ static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *siteke HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file 0 in AID %06X", aid); if (verbose) - PrintAndLogEx(INFO, "Created file 0 in AID %06X (current has empty contents)", aid); + PrintAndLogEx(INFO, "Created file 0 in AID %06X (currently has empty contents)", aid); // Create file contents (2nd half is the bitwise inverse of the encoded creds) uint8_t contents[16] = {0}; @@ -514,7 +521,7 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Card Application Directory. Does it already exist?", CAD_AID); if (verbose) - PrintAndLogEx(INFO, "Created Card Application Directory (AID %06X, current has empty contents & blank keys)", CAD_AID); + PrintAndLogEx(INFO, "Created Card Application Directory (AID %06X, currently has empty contents & blank keys)", CAD_AID); // Select application & authenticate uint8_t blankKey[DESFIRE_MAX_KEY_SIZE] = {0}; @@ -553,7 +560,7 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t // Check if CAD exists uint8_t cad[36 * 3] = {0}; uint8_t numEntries = 0; - if (aidExists(ctx, CAD_AID, verbose)) { + if (aidExists(ctx, CAD_AID, false)) { if (verbose) PrintAndLogEx(INFO, "Card Application Directory exists, reading entries..."); @@ -562,8 +569,9 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t // Check that there is space for the new entry if (numEntries >= 18) - HFGAL_RET_ERR(PM3_EFATAL, "Card application directory is full."); + HFGAL_RET_ERR(PM3_EFATAL, "Card application directory is full"); } else { + // CAD doesn't exist, we need to create it. if (verbose) PrintAndLogEx(INFO, "Card Application Directory does not exist, creating it now..."); @@ -574,6 +582,12 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t uint8_t fileId = numEntries / 6; // 6 entries per file uint8_t entryNum = numEntries % 6; + // Check if facility already exists in CAD. + for (uint8_t i = 0; i < ARRAYLEN(cad); i += 6) { + if (cadFacilityMatch(&cad[i], creds->region_code, creds->facility_code)) + HFGAL_RET_ERR(PM3_EFATAL, "Facility already exists in CAD, delete or update AID %06X instead", cadAidByteToUint(&cad[i + 3])); + } + // Create entry uint8_t *entry = &cad[numEntries * 6]; entry[0] = creds->region_code; @@ -613,10 +627,10 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file %d in CAD (AID %06X)", fileId, CAD_AID); if (verbose) - PrintAndLogEx(INFO, "Created file %d in CAD (current has empty contents)", fileId); + PrintAndLogEx(INFO, "Created file %d in CAD (currently has empty contents)", fileId); // Write file - res = DesfireWriteFile(ctx, fileId, fileId * 36, 36, entry); + res = DesfireWriteFile(ctx, fileId, 0, 36, entry); } else { // Write file res = DesfireWriteFile(ctx, fileId, entryNum * 6, 6, entry); @@ -630,7 +644,7 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t static int CmdGallagherClone(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher clone", - "clone a GALLAGHER card to a blank DESFire card.", + "clone a GALLAGHER card to a blank DESFire card", "hf gallagher clone --rc 1 --fc 22 --cn 3333 --il 4 --sitekey 00112233445566778899aabbccddeeff" ); @@ -668,10 +682,10 @@ static int CmdGallagherClone(const char *Cmd) { // Default to a key of all zeros keyLen = desfire_get_key_length(algo); - uint64_t region_code = arg_get_u64(ctx, 6); // uint16, will be validated later - uint64_t facility_code = arg_get_u64(ctx, 7); // uint32, will be validated later - uint64_t card_number = arg_get_u64(ctx, 8); // uint64 - uint64_t issue_level = arg_get_u64(ctx, 9); // uint32, will be validated later + uint64_t region_code = arg_get_u64(ctx, 6); // uint4, input will be validated later + uint64_t facility_code = arg_get_u64(ctx, 7); // uint16 + uint64_t card_number = arg_get_u64(ctx, 8); // uint24 + uint64_t issue_level = arg_get_u64(ctx, 9); // uint4 int aidLen = 0; uint8_t aidBuf[3] = {0}; @@ -723,6 +737,12 @@ static int CmdGallagherClone(const char *Cmd) { HFGAL_RET_ERR(PM3_EFATAL, "Could not find an available AID, card is full"); } + // Update card application directory + DesfireSetKeyNoClear(&dctx, keyNum, algo, key); + DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); + res = updateGallagherCAD(&dctx, sitekey, aid, &creds, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed updating Gallagher card application directory"); + // Create application DesfireSetKeyNoClear(&dctx, keyNum, algo, key); DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); @@ -732,13 +752,7 @@ static int CmdGallagherClone(const char *Cmd) { // Create credential files // Don't need to set keys here, they're generated automatically res = createGallagherCredentialsFile(&dctx, sitekey, aid, &creds, verbose); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Gallagher credential file."); - - // Update card application directory - DesfireSetKeyNoClear(&dctx, keyNum, algo, key); - DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); - res = updateGallagherCAD(&dctx, sitekey, aid, &creds, verbose); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed updating Gallagher card application directory."); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Gallagher credential file"); PrintAndLogEx(SUCCESS, "Done"); PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf gallagher reader`") " to verify"); @@ -763,10 +777,10 @@ static int CmdGallagherSim(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, false); - uint64_t region_code = arg_get_u64(ctx, 1); // uint16, will be validated later - uint64_t facility_code = arg_get_u64(ctx, 2); // uint32, will be validated later - uint64_t card_number = arg_get_u64(ctx, 3); // uint64 - uint64_t issue_level = arg_get_u64(ctx, 4); // uint32, will be validated later + uint64_t region_code = arg_get_u64(ctx, 1); // uint4, input will be validated later + uint64_t facility_code = arg_get_u64(ctx, 2); // uint16 + uint64_t card_number = arg_get_u64(ctx, 3); // uint24 + uint64_t issue_level = arg_get_u64(ctx, 4); // uint4 CLIParserFree(ctx); if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) From 81da8a131789c7293f665a3fdcdcf83df3ebb31f Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Wed, 5 Jan 2022 00:22:34 +1300 Subject: [PATCH 17/26] Add `hf gallagher delete` command --- client/src/cmdhfgallagher.c | 178 ++++++++++++++++++++++++++++++++++-- 1 file changed, 169 insertions(+), 9 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index d314f3c5f..a29ca6b05 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -116,6 +116,7 @@ static int authenticate(DesfireContext_t *ctx, bool verbose) { // TODO: do these both need to be set? DesfireSetCommMode(ctx, DCMPlain); DesfireSetCommandSet(ctx, DCCNativeISO); + DesfireClearSession(ctx); int res = DesfireAuthenticate(ctx, DACEV1, false); if (res != PM3_SUCCESS) { @@ -295,7 +296,7 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { numEntries = 1; } else { res = readCardApplicationDirectory(&dctx, cad, ARRAYLEN(cad), &numEntries, verbose); - HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application directory"); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading Card Application Directory"); } // Loop through each application in the CAD @@ -375,6 +376,28 @@ static int CmdGallagherReader(const char *Cmd) { return PM3_SUCCESS; } +/** + * @brief Delete the CAD or an application that contains cardholder credentials. + * + * @param sitekey MIFARE site key. + * @param aid Application ID to remove. + */ +static int deleteGallagherApplication(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, bool verbose) { + // Select application & authenticate + DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); + DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); + int res = selectAidAndAuthenticate(ctx, aid, verbose); + HFGAL_RET_IF_ERR(res); + + // Delete application + DesfireSetCommMode(ctx, DCMMACed); + res = DesfireDeleteApplication(ctx, aid); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting AID %06X", aid); + + PrintAndLogEx(INFO, "Successfully deleted AID %06X", aid); + return PM3_SUCCESS; +} + /** * @brief Create a new application to store Gallagher cardholder credentials. * @@ -556,7 +579,7 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb * @param aid Application ID to add to the CAD. * @param creds Gallagher cardholder credentials (region_code & facility_code are required). */ -static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, GallagherCredentials_t *creds, bool verbose) { +static int addToGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, GallagherCredentials_t *creds, bool verbose) { // Check if CAD exists uint8_t cad[36 * 3] = {0}; uint8_t numEntries = 0; @@ -630,17 +653,87 @@ static int updateGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t PrintAndLogEx(INFO, "Created file %d in CAD (currently has empty contents)", fileId); // Write file - res = DesfireWriteFile(ctx, fileId, 0, 36, entry); - } else { + res = DesfireWriteFile(ctx, fileId, 0, 36, &cad[fileId * 36]); + } else // Write file res = DesfireWriteFile(ctx, fileId, entryNum * 6, 6, entry); - } HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", fileId, CAD_AID); PrintAndLogEx(INFO, "Successfully added new entry for %06X to the Card Application Directory", aid); return PM3_SUCCESS; } +/** + * @brief Remove an entry from the Gallagher Card Application Directory. + * + * @param sitekey MIFARE site key. + * @param aid Application ID to add to the CAD. + */ +static int removeFromGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, bool verbose) { + // Check if CAD exists + uint8_t cad[36 * 3] = {0}; + uint8_t numEntries = 0; + + int res = readCardApplicationDirectory(ctx, cad, ARRAYLEN(cad), &numEntries, verbose); + HFGAL_RET_IF_ERR(res); + + // Check if facility already exists in CAD + uint8_t entryNum = 0; + for (; entryNum < numEntries; entryNum++) { + if (aid > 0 && aid == cadAidByteToUint(&cad[entryNum * 6 + 3])) + break; + } + if (entryNum >= numEntries) + HFGAL_RET_ERR(PM3_EINVARG, "Specified facility or AID does not exist in the Card Application Directory"); + + // Remove entry (shift all entries left, then clear the last entry) + memmove(&cad[entryNum * 6], &cad[(entryNum + 1) * 6], ARRAYLEN(cad) - (entryNum + 1) * 6); + memset(&cad[ARRAYLEN(cad) - 6], 0, 6); + + // Select application & authenticate + DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); + DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); + res = selectAidAndAuthenticate(ctx, CAD_AID, verbose); + HFGAL_RET_IF_ERR(res); + + // Determine what files we need to update + uint8_t fileIdStart = (entryNum - 1) / 6; + uint8_t fileIdStop = (numEntries - 1) / 6; + + for (uint8_t fileId = fileIdStart; fileId <= fileIdStop; fileId++) { + // Write file + res = DesfireWriteFile(ctx, fileId, 0, 36, &cad[fileId * 36]); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", fileId, CAD_AID); + + if (verbose) + PrintAndLogEx(INFO, "Updated file %d in CAD", fileId); + } + + // Delete empty files if necessary + if (fileIdStart != fileIdStop) { + uint8_t fileId = fileIdStop; + + DesfireSetCommMode(ctx, DCMMACed); + res = DesfireDeleteFile(ctx, fileId); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting file %d from CAD (AID %06X)", fileId, CAD_AID); + + if (verbose) + PrintAndLogEx(INFO, "Deleted unnecessary file %d from CAD (AID %06X)", fileId, CAD_AID); + + // Delete the Card Application Directory if necessary (if we just deleted the last file in it) + if (fileId == 0) { + res = deleteGallagherApplication(ctx, sitekey, CAD_AID, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting file %d from CAD (AID %06X)", fileId, CAD_AID); + + if (verbose) + PrintAndLogEx(INFO, "Removed CAD because it was empty"); + } + } + + PrintAndLogEx(INFO, "Successfully removed %06X from the Card Application Directory", aid); + return PM3_SUCCESS; +} + static int CmdGallagherClone(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher clone", @@ -737,11 +830,11 @@ static int CmdGallagherClone(const char *Cmd) { HFGAL_RET_ERR(PM3_EFATAL, "Could not find an available AID, card is full"); } - // Update card application directory + // Update Card Application Directory DesfireSetKeyNoClear(&dctx, keyNum, algo, key); DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); - res = updateGallagherCAD(&dctx, sitekey, aid, &creds, verbose); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed updating Gallagher card application directory"); + res = addToGallagherCAD(&dctx, sitekey, aid, &creds, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed updating Gallagher Card Application Directory"); // Create application DesfireSetKeyNoClear(&dctx, keyNum, algo, key); @@ -759,6 +852,72 @@ static int CmdGallagherClone(const char *Cmd) { return PM3_SUCCESS; } +static int CmdGallagherDelete(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf gallagher delete", + "delete Gallagher application from a DESFire card", + "hf gallagher delete --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0(NULL, "apdu", "show APDU requests and responses"), + arg_lit0("v", "verbose", "Verbose mode"), + + arg_str1(NULL, "aid", "", "Application ID to delete (3 bytes)"), + arg_str0(NULL, "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + SetAPDULogging(arg_get_lit(ctx, 1)); + bool verbose = arg_get_lit(ctx, 2); + + int aidLen = 0; + uint8_t aidBuf[3] = {0}; + uint32_t aid = 0; + CLIGetHexWithReturn(ctx, 3, aidBuf, &aidLen); + + if (aidLen != 3) + HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); + reverseAid(aidBuf); // PM3 displays AIDs backwards + aid = DesfireAIDByteToUint(aidBuf); + + // Check that the AID is in the expected range + if (memcmp(aidBuf, "\xF4\x81", 2) != 0 || aidBuf[2] < 0x20 || aidBuf[2] > 0x2B) + // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't + HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); + + int sitekeyLen = 0; + uint8_t sitekey[16] = {0}; + memcpy(sitekey, DEFAULT_SITE_KEY, ARRAYLEN(sitekey)); + CLIGetHexWithReturn(ctx, 4, sitekey, &sitekeyLen); + if (sitekeyLen > 0 && sitekeyLen != 16) + HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); + CLIParserFree(ctx); + + // Set up context + DropField(); + DesfireContext_t dctx = {0}; + DesfireClearContext(&dctx); + + // Get card UID (for key diversification) + int res = DesfireGetCardUID(&dctx); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed retrieving card UID"); + + // Update Card Application Directory + res = removeFromGallagherCAD(&dctx, sitekey, aid, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed removing %06X from the Card Application Directory"); + + // Delete application + res = deleteGallagherApplication(&dctx, sitekey, aid, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting Gallagher application"); + + PrintAndLogEx(SUCCESS, "Done"); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf gallagher reader`") " to verify"); + return PM3_SUCCESS; +} + static int CmdGallagherSim(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher sim", @@ -798,7 +957,8 @@ static int CmdHelp(const char *Cmd); static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"reader", CmdGallagherReader, IfPm3Iso14443, "attempt to read and extract tag data"}, - {"clone", CmdGallagherClone, IfPm3Iso14443, "clone GALLAGHER tag to a blank DESFire card"}, + {"clone", CmdGallagherClone, IfPm3Iso14443, "add Gallagher credentials to a DESFire card"}, + {"delete", CmdGallagherDelete, IfPm3Iso14443, "delete Gallagher application from a DESFire card"}, {"sim", CmdGallagherSim, IfPm3Iso14443, "simulate GALLAGHER tag"}, {NULL, NULL, NULL, NULL} }; From fad30294aaf377e7dea6621a7729f2a3b9b6575a Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Wed, 5 Jan 2022 23:08:10 +1300 Subject: [PATCH 18/26] Format styles --- client/src/cmdhfgallagher.c | 177 +++++++++++++++++------------------- client/src/cmdhfgallagher.h | 2 +- client/src/cmdhfmfdes.c | 2 +- client/src/cmdlfgallagher.c | 2 +- client/src/rl_vocabulory.h | 4 + doc/commands.json | 63 ++++++++++++- doc/commands.md | 12 +++ 7 files changed, 163 insertions(+), 99 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index a29ca6b05..8e089e23c 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -27,10 +27,14 @@ static const uint32_t CAD_AID = 0x2F81F4; /** Default MIFARE Site Key */ -static const uint8_t DEFAULT_SITE_KEY[] = { 0x31, 0x12, 0xB7, 0x38, 0xD8, 0x86, 0x2C, 0xCD, 0x34, 0x30, 0x2E, 0xB2, 0x99, 0xAA, 0xB4, 0x56 }; +static const uint8_t DEFAULT_SITE_KEY[] = { + 0x31, 0x12, 0xB7, 0x38, 0xD8, 0x86, 0x2C, 0xCD, + 0x34, 0x30, 0x2E, 0xB2, 0x99, 0xAA, 0xB4, 0x56, +}; /** - * @brief Reverses the bytes in AID. Used when parsing CLI args (because Proxmark displays AIDs in reverse byte order). + * @brief Reverses the bytes in AID. Used when parsing CLI args + * (because Proxmark displays AIDs in reverse byte order). */ static void reverseAid(uint8_t *aid) { uint8_t tmp = aid[0]; @@ -57,16 +61,27 @@ static void cadAidUintToByte(uint32_t aid, uint8_t *data) { } /** - * @brief Returns true if the Card Application Directory entry is for the specified region & facility, false otherwise. + * @brief Returns true if the Card Application Directory entry + * is for the specified region & facility, false otherwise. */ static bool cadFacilityMatch(uint8_t *entry, uint8_t regionCode, uint16_t facilityCode) { return entry[0] == regionCode && (entry[1] << 8) + entry[2] == facilityCode; } -/* - * See header file for description :) +/** + * @brief Create Gallagher Application Master Key by diversifying + * the MIFARE Site Key with card UID, key number, and application ID. + * + * @param sitekey MIFARE Site Key (16 bytes). + * @param uid Card unique ID (4 or 7 bytes). + * @param uidLen Length of UID. + * @param keyNum Key number (0 <= keyNum <= 2). + * @param aid Application ID (0x2?81F4 where 0 <= ? <= B). + * @param keyOut Buffer to copy the diversified key into (must be 16 bytes). + * @return PM3_SUCCESS if successful, PM3_EINVARG if an argument is invalid. */ -int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNo, uint32_t aid, uint8_t *keyOut) { +int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, + uint8_t keyNo, uint32_t aid, uint8_t *keyOut) { // Generate diversification input uint8_t kdfInputLen = 11; int res = mfdes_kdf_input_gallagher(uid, uidLen, keyNo, aid, keyOut, &kdfInputLen); @@ -74,14 +89,14 @@ int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_ if (sitekey == NULL) { PrintAndLogEx(INFO, "GallagherDiversifyKey is using default site key: %s", - sprint_hex_inrow(DEFAULT_SITE_KEY, ARRAYLEN(DEFAULT_SITE_KEY))); + sprint_hex_inrow(DEFAULT_SITE_KEY, ARRAYLEN(DEFAULT_SITE_KEY))); sitekey = (uint8_t *) &DEFAULT_SITE_KEY; } // Make temporary DesfireContext DesfireContext_t dctx = {0}; DesfireSetKey(&dctx, 0, T_AES, sitekey); - + // Diversify input & copy to output buffer MifareKdfAn10922(&dctx, DCOMasterKey, keyOut, kdfInputLen); memcpy(keyOut, dctx.key, CRYPTO_AES128_KEY_SIZE); @@ -120,7 +135,8 @@ static int authenticate(DesfireContext_t *ctx, bool verbose) { int res = DesfireAuthenticate(ctx, DACEV1, false); if (res != PM3_SUCCESS) { - PrintAndLogEx(ERR, "Desfire authenticate " _RED_("error") ". Result: [%d] %s", res, DesfireAuthErrorToStr(res)); + PrintAndLogEx(ERR, "Desfire authenticate " _RED_("error") + ". Result: [%d] %s", res, DesfireAuthErrorToStr(res)); return res; } @@ -134,7 +150,8 @@ static int authenticate(DesfireContext_t *ctx, bool verbose) { } /** - * @brief Select application ID & authenticate. Uses existing authentication keys in context. + * @brief Select application ID & authenticate. + * Uses existing authentication keys in context. */ static int selectAidAndAuthenticate(DesfireContext_t *ctx, uint32_t aid, bool verbose) { int res = selectAid(ctx, aid, verbose); @@ -165,7 +182,7 @@ static bool aidExists(DesfireContext_t *ctx, uint32_t aid, bool verbose) { } /** - * @brief Returns the lowest available Gallagher application ID. + * @brief Returns the lowest available Gallagher application ID. * @return 0 if no AID is available, or an AID in the range 0x2?81F4, where 0 <= ? <= 0xB. */ static uint32_t findAvailableGallagherAid(DesfireContext_t *ctx, bool verbose) { @@ -179,7 +196,7 @@ static uint32_t findAvailableGallagherAid(DesfireContext_t *ctx, bool verbose) { /** * @brief Read Gallagher Card Application Directory from card. - * + * * @param destBuf Buffer to copy Card Application Directory into. * @param destBufLen Size of destBuf. Must be at least 108 bytes. * @param numEntries Will be set to the number of entries in the Card Application Directory. @@ -187,7 +204,7 @@ static uint32_t findAvailableGallagherAid(DesfireContext_t *ctx, bool verbose) { static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, uint8_t destBufLen, uint8_t *numEntries, bool verbose) { if (destBufLen < 3 * 36) { PrintAndLogEx(ERR, "readCardApplicationDirectory destination buffer is incorrectly sized. " - "Received length %d, must be at least %d", destBufLen, 3 * 36); + "Received length %d, must be at least %d", destBufLen, 3 * 36); return PM3_EINVARG; } @@ -217,7 +234,7 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, // Print what we found PrintAndLogEx(SUCCESS, "Card Application Directory contains:" NOLF); for (int i = 0; i < *numEntries; i++) - PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", cadAidByteToUint(&destBuf[i*6 + 3])); + PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", cadAidByteToUint(&destBuf[i * 6 + 3])); PrintAndLogEx(NORMAL, ""); } @@ -226,7 +243,7 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, /** * @brief Read credentials from a single AID. - * + * * @param aid Application ID to read. * @param sitekey MIFARE site key. * @param creds Decoded credentials will be stored in this structure. @@ -260,7 +277,7 @@ static int readCardApplicationCredentials(DesfireContext_t *ctx, uint32_t aid, u if (memcmp(buf, &buf[8], 8) != 0) { HFGAL_RET_ERR(PM3_EFAILED, "Invalid cardholder data in file 0 in AID %06X. Received %s", sprint_hex_inrow(buf, 16)); } - + decodeCardholderCredentials(buf, creds); // TODO: read MIFARE Enhanced Security file @@ -271,7 +288,7 @@ static int readCardApplicationCredentials(DesfireContext_t *ctx, uint32_t aid, u /** * @brief Read credentials from a Gallagher card. - * + * * @param aid Application ID to read. If 0, then the Card Application Directory will be queried and all entries will be read. * @param sitekey MIFARE site key. * @param quiet Suppress error messages. Used when in continuous reader mode. @@ -317,8 +334,9 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { res = readCardApplicationCredentials(&dctx, currentAid, sitekey, &creds, verbose); HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application credentials"); - PrintAndLogEx(SUCCESS, "GALLAGHER (AID %06X) - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), - currentAid, creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); + PrintAndLogEx(SUCCESS, "GALLAGHER (AID %06X) - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") + ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), currentAid, + creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); } return PM3_SUCCESS; @@ -327,17 +345,17 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { static int CmdGallagherReader(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher reader", - "read a GALLAGHER tag", - "hf gallagher reader --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" - " -> act as a reader that doesn't skips the Card Application Directory and uses a non-default site key\n" - "hf gallagher reader -@ -> continuous reader mode" - ); + "Read a GALLAGHER tag", + "hf gallagher reader --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" + " -> act as a reader that skips reading the Card Application Directory and uses a non-default site key\n" + "hf gallagher reader -@ -> continuous reader mode" + ); void *argtable[] = { arg_param_begin, arg_str0(NULL, "aid", "", "Application ID to read (3 bytes)"), arg_str0("k", "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), - arg_lit0(NULL, "apdu", "show APDU requests and responses"), + arg_lit0(NULL, "apdu", "Show APDU requests and responses"), arg_lit0("v", "verbose", "Verbose mode"), arg_lit0("@", "continuous", "Continuous reader mode"), arg_param_end @@ -352,7 +370,7 @@ static int CmdGallagherReader(const char *Cmd) { reverseAid(aidBuf); // PM3 displays AIDs backwards uint32_t aid = DesfireAIDByteToUint(aidBuf); - + int sitekeyLen = 0; uint8_t sitekey[16] = {0}; memcpy(sitekey, DEFAULT_SITE_KEY, ARRAYLEN(sitekey)); @@ -378,7 +396,7 @@ static int CmdGallagherReader(const char *Cmd) { /** * @brief Delete the CAD or an application that contains cardholder credentials. - * + * * @param sitekey MIFARE site key. * @param aid Application ID to remove. */ @@ -393,14 +411,14 @@ static int deleteGallagherApplication(DesfireContext_t *ctx, uint8_t *sitekey, u DesfireSetCommMode(ctx, DCMMACed); res = DesfireDeleteApplication(ctx, aid); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting AID %06X", aid); - + PrintAndLogEx(INFO, "Successfully deleted AID %06X", aid); return PM3_SUCCESS; } /** * @brief Create a new application to store Gallagher cardholder credentials. - * + * * @param sitekey MIFARE site key. * @param aid New application ID. Should be 0x2?81F4, where 0 <= ? <= 0xB. */ @@ -466,7 +484,7 @@ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t /** * @brief Create a new file containing Gallagher cardholder credentials. - * + * * @param sitekey MIFARE site key. * @param aid Application ID to put the new file in. * @param creds Gallagher cardholder credentials. @@ -509,14 +527,14 @@ static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *siteke DesfireSetCommMode(ctx, DCMEncrypted); res = DesfireWriteFile(ctx, fileId, 0, ARRAYLEN(contents), contents); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file 0 in AID %06X"); - + PrintAndLogEx(INFO, "Successfully wrote cardholder credentials to file 0 in AID %06X", aid); return PM3_SUCCESS; } /** * @brief Create the Gallagher Card Application Directory. - * + * * @param sitekey MIFARE site key. */ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verbose) { @@ -557,7 +575,7 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb uint8_t buf[CRYPTO_AES128_KEY_SIZE] = {0}; res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, 0, CAD_AID, buf); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key 0 for AID %06X", CAD_AID); - + PrintAndLogEx(INFO, "Diversified key 0 for CAD (AID %06X): " _GREEN_("%s"), CAD_AID, sprint_hex_inrow(buf, ARRAYLEN(buf))); // Change key @@ -574,7 +592,7 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb /** * @brief Update the Gallagher Card Application Directory with a new entry. - * + * * @param sitekey MIFARE site key. * @param aid Application ID to add to the CAD. * @param creds Gallagher cardholder credentials (region_code & facility_code are required). @@ -587,7 +605,8 @@ static int addToGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t a if (verbose) PrintAndLogEx(INFO, "Card Application Directory exists, reading entries..."); - int res = readCardApplicationDirectory(ctx, cad, ARRAYLEN(cad), &numEntries, verbose); + int res = readCardApplicationDirectory( + ctx, cad, ARRAYLEN(cad), &numEntries, verbose); HFGAL_RET_IF_ERR(res); // Check that there is space for the new entry @@ -608,7 +627,8 @@ static int addToGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t a // Check if facility already exists in CAD. for (uint8_t i = 0; i < ARRAYLEN(cad); i += 6) { if (cadFacilityMatch(&cad[i], creds->region_code, creds->facility_code)) - HFGAL_RET_ERR(PM3_EFATAL, "Facility already exists in CAD, delete or update AID %06X instead", cadAidByteToUint(&cad[i + 3])); + HFGAL_RET_ERR(PM3_EFATAL, "Facility already exists in CAD, delete or " + "update AID %06X instead", cadAidByteToUint(&cad[i + 3])); } // Create entry @@ -658,14 +678,14 @@ static int addToGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t a // Write file res = DesfireWriteFile(ctx, fileId, entryNum * 6, 6, entry); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", fileId, CAD_AID); - + PrintAndLogEx(INFO, "Successfully added new entry for %06X to the Card Application Directory", aid); return PM3_SUCCESS; } /** * @brief Remove an entry from the Gallagher Card Application Directory. - * + * * @param sitekey MIFARE site key. * @param aid Application ID to add to the CAD. */ @@ -673,8 +693,9 @@ static int removeFromGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint3 // Check if CAD exists uint8_t cad[36 * 3] = {0}; uint8_t numEntries = 0; - - int res = readCardApplicationDirectory(ctx, cad, ARRAYLEN(cad), &numEntries, verbose); + + int res = readCardApplicationDirectory( + ctx, cad, ARRAYLEN(cad), &numEntries, verbose); HFGAL_RET_IF_ERR(res); // Check if facility already exists in CAD @@ -687,7 +708,11 @@ static int removeFromGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint3 HFGAL_RET_ERR(PM3_EINVARG, "Specified facility or AID does not exist in the Card Application Directory"); // Remove entry (shift all entries left, then clear the last entry) - memmove(&cad[entryNum * 6], &cad[(entryNum + 1) * 6], ARRAYLEN(cad) - (entryNum + 1) * 6); + memmove( + &cad[entryNum * 6], + &cad[(entryNum + 1) * 6], + ARRAYLEN(cad) - (entryNum + 1) * 6 + ); memset(&cad[ARRAYLEN(cad) - 6], 0, 6); // Select application & authenticate @@ -720,7 +745,8 @@ static int removeFromGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint3 if (verbose) PrintAndLogEx(INFO, "Deleted unnecessary file %d from CAD (AID %06X)", fileId, CAD_AID); - // Delete the Card Application Directory if necessary (if we just deleted the last file in it) + // Delete the Card Application Directory if necessary + // (if we just deleted the last file in it) if (fileId == 0) { res = deleteGallagherApplication(ctx, sitekey, CAD_AID, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting file %d from CAD (AID %06X)", fileId, CAD_AID); @@ -729,7 +755,7 @@ static int removeFromGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint3 PrintAndLogEx(INFO, "Removed CAD because it was empty"); } } - + PrintAndLogEx(INFO, "Successfully removed %06X from the Card Application Directory", aid); return PM3_SUCCESS; } @@ -737,9 +763,9 @@ static int removeFromGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint3 static int CmdGallagherClone(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher clone", - "clone a GALLAGHER card to a blank DESFire card", - "hf gallagher clone --rc 1 --fc 22 --cn 3333 --il 4 --sitekey 00112233445566778899aabbccddeeff" - ); + "Clone a GALLAGHER card to a blank DESFire card", + "hf gallagher clone --rc 1 --fc 22 --cn 3333 --il 4 --sitekey 00112233445566778899aabbccddeeff" + ); void *argtable[] = { arg_param_begin, @@ -762,7 +788,7 @@ static int CmdGallagherClone(const char *Cmd) { SetAPDULogging(arg_get_lit(ctx, 1)); bool verbose = arg_get_lit(ctx, 2); int keyNum = arg_get_int_def(ctx, 3, 0); - + int algo = T_DES; if (CLIGetOptionList(arg_get_str(ctx, 4), DesfireAlgoOpts, &algo)) return PM3_ESOFT; @@ -795,7 +821,7 @@ static int CmdGallagherClone(const char *Cmd) { // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); } - + int sitekeyLen = 0; uint8_t sitekey[16] = {0}; memcpy(sitekey, DEFAULT_SITE_KEY, ARRAYLEN(sitekey)); @@ -855,17 +881,17 @@ static int CmdGallagherClone(const char *Cmd) { static int CmdGallagherDelete(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher delete", - "delete Gallagher application from a DESFire card", - "hf gallagher delete --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" - ); + "Delete Gallagher application from a DESFire card", + "hf gallagher delete --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" + ); void *argtable[] = { arg_param_begin, - arg_lit0(NULL, "apdu", "show APDU requests and responses"), + arg_lit0(NULL, "apdu", "Show APDU requests and responses"), arg_lit0("v", "verbose", "Verbose mode"), arg_str1(NULL, "aid", "", "Application ID to delete (3 bytes)"), - arg_str0(NULL, "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), + arg_str0(NULL, "sitekey", "", "MIFARE site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); @@ -887,7 +913,7 @@ static int CmdGallagherDelete(const char *Cmd) { if (memcmp(aidBuf, "\xF4\x81", 2) != 0 || aidBuf[2] < 0x20 || aidBuf[2] > 0x2B) // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); - + int sitekeyLen = 0; uint8_t sitekey[16] = {0}; memcpy(sitekey, DEFAULT_SITE_KEY, ARRAYLEN(sitekey)); @@ -904,7 +930,7 @@ static int CmdGallagherDelete(const char *Cmd) { // Get card UID (for key diversification) int res = DesfireGetCardUID(&dctx); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed retrieving card UID"); - + // Update Card Application Directory res = removeFromGallagherCAD(&dctx, sitekey, aid, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed removing %06X from the Card Application Directory"); @@ -918,48 +944,13 @@ static int CmdGallagherDelete(const char *Cmd) { return PM3_SUCCESS; } -static int CmdGallagherSim(const char *Cmd) { - CLIParserContext *ctx; - CLIParserInit(&ctx, "hf gallagher sim", - "Enables simulation of GALLAGHER card with specified card number.\n" - "Simulation runs until the button is pressed or another USB command is issued.\n", - "hf gallagher sim --rc 1 --fc 22 --cn 3333 --il 4" - ); - - void *argtable[] = { - arg_param_begin, - arg_u64_1(NULL, "rc", "", "Region code. 4 bits max"), - arg_u64_1(NULL, "fc", "", "Facility code. 2 bytes max"), - arg_u64_1(NULL, "cn", "", "Card number. 3 bytes max"), - arg_u64_1(NULL, "il", "", "Issue level. 4 bits max"), - arg_param_end - }; - CLIExecWithReturn(ctx, Cmd, argtable, false); - - uint64_t region_code = arg_get_u64(ctx, 1); // uint4, input will be validated later - uint64_t facility_code = arg_get_u64(ctx, 2); // uint16 - uint64_t card_number = arg_get_u64(ctx, 3); // uint24 - uint64_t issue_level = arg_get_u64(ctx, 4); // uint4 - CLIParserFree(ctx); - - if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) - return PM3_EINVARG; - - // TODO: create data - - // TODO: simulate - - return PM3_ENOTIMPL; -} - static int CmdHelp(const char *Cmd); static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"reader", CmdGallagherReader, IfPm3Iso14443, "attempt to read and extract tag data"}, - {"clone", CmdGallagherClone, IfPm3Iso14443, "add Gallagher credentials to a DESFire card"}, - {"delete", CmdGallagherDelete, IfPm3Iso14443, "delete Gallagher application from a DESFire card"}, - {"sim", CmdGallagherSim, IfPm3Iso14443, "simulate GALLAGHER tag"}, + {"reader", CmdGallagherReader, IfPm3Iso14443, "Attempt to read and extract tag data"}, + {"clone", CmdGallagherClone, IfPm3Iso14443, "Add Gallagher credentials to a DESFire card"}, + {"delete", CmdGallagherDelete, IfPm3Iso14443, "Delete Gallagher application from a DESFire card"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/cmdhfgallagher.h b/client/src/cmdhfgallagher.h index 8d2509b00..08d5d2150 100644 --- a/client/src/cmdhfgallagher.h +++ b/client/src/cmdhfgallagher.h @@ -20,7 +20,7 @@ int CmdHFGallagher(const char *Cmd); /** * @brief Create Gallagher Application Master Key by diversifying * the MIFARE Site Key with card UID, key number, and application ID. - * + * * @param sitekey MIFARE Site Key (16 bytes). * @param uid Card unique ID (4 or 7 bytes). * @param uidLen Length of UID. diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 3ecbfe843..1e5297e15 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -3078,7 +3078,7 @@ static int CmdHF14ADesGetAIDs(const char *Cmd) { if (buflen >= 3) { PrintAndLogEx(INFO, "---- " _CYAN_("AID list") " ----"); for (int i = 0; i < buflen; i += 3) { - const char* commentStr = getAidCommentStr(&buf[i]); + const char *commentStr = getAidCommentStr(&buf[i]); if ((void *) commentStr == &noCommentStr) PrintAndLogEx(INFO, "AID: %06x", DesfireAIDByteToUint(&buf[i])); else diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index ed46c8143..b09f93b60 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -79,7 +79,7 @@ int demodGallagher(bool verbose) { decodeCardholderCredentials(arr, &creds); PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") " Facility: " _GREEN_("%u") " Card No.: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"), - creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); + creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); PrintAndLogEx(SUCCESS, " Displayed: " _GREEN_("%C%u"), creds.region_code + 'A', creds.facility_code); PrintAndLogEx(SUCCESS, " Raw: %08X%08X%08X", raw1, raw2, raw3); PrintAndLogEx(SUCCESS, " CRC: %02X - %02X (%s)", crc, calc_crc, (crc == calc_crc) ? "ok" : "fail"); diff --git a/client/src/rl_vocabulory.h b/client/src/rl_vocabulory.h index 685c9eb8f..69f389a5d 100644 --- a/client/src/rl_vocabulory.h +++ b/client/src/rl_vocabulory.h @@ -216,6 +216,10 @@ const static vocabulory_t vocabulory[] = { { 0, "hf fido auth" }, { 0, "hf fido make" }, { 0, "hf fido assert" }, + { 1, "hf gallagher help" }, + { 0, "hf gallagher reader" }, + { 0, "hf gallagher clone" }, + { 0, "hf gallagher delete" }, { 1, "hf ksx6924 help" }, { 0, "hf ksx6924 balance" }, { 0, "hf ksx6924 info" }, diff --git a/doc/commands.json b/doc/commands.json index 299a10884..7ac247c3e 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -2315,9 +2315,66 @@ ], "usage": "hf fido reg [-havt] [-f ] [--cp ] [--ap ] [--cpx ] [--apx ]" }, + "hf gallagher clone": { + "command": "hf gallagher clone", + "description": "clone a gallagher card to a blank desfire card", + "notes": [ + "hf gallagher clone --rc 1 --fc 22 --cn 3333 --il 4 --sitekey 00112233445566778899aabbccddeeff" + ], + "offline": false, + "options": [ + "-h, --help this help", + "--apdu show apdu requests and responses", + "-v, --verbose verbose mode", + "-n, --keyno key number [default=0]", + "-t, --algo crypt algo: des, 2tdea, 3tdea, aes", + "-k, --key key for authenticate (hex 8(des), 16(2tdea or aes) or 24(3tdea) bytes)", + "--rc region code. 4 bits max", + "--fc facility code. 2 bytes max", + "--cn card number. 3 bytes max", + "--il issue level. 4 bits max", + "--aid application id to write (3 bytes) [default finds lowest available in range 0x2?81f4, where 0 <= ? <= 0xb]", + "--sitekey master site key to compute diversified keys (16 bytes) [default=3112b738d8862ccd34302eb299aab456]" + ], + "usage": "hf gallagher clone [-hv] [--apdu] [-n ] [-t ] [-k ] --rc --fc --cn --il [--aid ] [--sitekey ]" + }, + "hf gallagher delete": { + "command": "hf gallagher delete", + "description": "delete gallagher application from a desfire card", + "notes": [ + "hf gallagher delete --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" + ], + "offline": false, + "options": [ + "-h, --help this help", + "--apdu show apdu requests and responses", + "-v, --verbose verbose mode", + "--aid application id to delete (3 bytes)", + "--sitekey mifare site key to compute diversified keys (16 bytes) [default=3112b738d8862ccd34302eb299aab456]" + ], + "usage": "hf gallagher delete [-hv] [--apdu] --aid [--sitekey ]" + }, + "hf gallagher help": { + "command": "hf gallagher help", + "description": "help this help --------------------------------------------------------------------------------------- hf gallagher reader available offline: no read a gallagher tag", + "notes": [ + "hf gallagher reader --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff -> act as a reader that skips reading the card application directory and uses a non-default site key", + "hf gallagher reader -@ -> continuous reader mode" + ], + "offline": true, + "options": [ + "-h, --help this help", + "--aid application id to read (3 bytes)", + "-k, --sitekey master site key to compute diversified keys (16 bytes) [default=3112b738d8862ccd34302eb299aab456]", + "--apdu show apdu requests and responses", + "-v, --verbose verbose mode", + "-@, --continuous continuous reader mode" + ], + "usage": "hf gallagher reader [-hv@] [--aid ] [-k ] [--apdu]" + }, "hf help": { "command": "hf help", - "description": "-------- ----------------------- high frequency ----------------------- 14a { iso14443a rfids... } 14b { iso14443b rfids... } 15 { iso15693 rfids... } cipurse { cipurse transport cards... } epa { german identification card... } emrtd { machine readable travel document... } felica { iso18092 / felica rfids... } fido { fido and fido2 authenticators... } ksx6924 { ks x 6924 (t-money, snapper+) rfids } jooki { jooki rfids... } iclass { iclass rfids... } legic { legic rfids... } lto { lto cartridge memory rfids... } mf { mifare rfids... } mfp { mifare plus rfids... } mfu { mifare ultralight rfids... } mfdes { mifare desfire rfids... } seos { seos rfids... } st25ta { st25ta rfids... } thinfilm { thinfilm rfids... } topaz { topaz (nfc type 1) rfids... } waveshare { waveshare nfc epaper... } ----------- --------------------- general --------------------- help this help list list protocol data in trace buffer search search for known hf tags --------------------------------------------------------------------------------------- hf list available offline: yes alias of `trace list -t raw` with selected protocol data to annotate trace buffer you can load a trace from file (see `trace load -h`) or it be downloaded from device by default it accepts all other arguments of `trace list`. note that some might not be relevant for this specific protocol", + "description": "-------- ----------------------- high frequency ----------------------- 14a { iso14443a rfids... } 14b { iso14443b rfids... } 15 { iso15693 rfids... } cipurse { cipurse transport cards... } epa { german identification card... } emrtd { machine readable travel document... } felica { iso18092 / felica rfids... } fido { fido and fido2 authenticators... } gallagher { gallagher desfire rfids... } ksx6924 { ks x 6924 (t-money, snapper+) rfids } jooki { jooki rfids... } iclass { iclass rfids... } legic { legic rfids... } lto { lto cartridge memory rfids... } mf { mifare rfids... } mfp { mifare plus rfids... } mfu { mifare ultralight rfids... } mfdes { mifare desfire rfids... } seos { seos rfids... } st25ta { st25ta rfids... } thinfilm { thinfilm rfids... } topaz { topaz (nfc type 1) rfids... } waveshare { waveshare nfc epaper... } ----------- --------------------- general --------------------- help this help list list protocol data in trace buffer search search for known hf tags --------------------------------------------------------------------------------------- hf list available offline: yes alias of `trace list -t raw` with selected protocol data to annotate trace buffer you can load a trace from file (see `trace load -h`) or it be downloaded from device by default it accepts all other arguments of `trace list`. note that some might not be relevant for this specific protocol", "notes": [ "hf list -f -> show frame delay times", "hf list -1 -> use trace buffer" @@ -10149,8 +10206,8 @@ } }, "metadata": { - "commands_extracted": 597, + "commands_extracted": 600, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2021-12-27T18:30:34" + "extracted_on": "2022-01-05T09:45:02" } } \ No newline at end of file diff --git a/doc/commands.md b/doc/commands.md index c9abff59f..3237a4c9d 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -317,6 +317,18 @@ Check column "offline" for their availability. |`hf fido assert `|N |`FIDO2 GetAssertion command.` +### hf gallagher + + { Gallagher DESFire RFIDs... } + +|command |offline |description +|------- |------- |----------- +|`hf gallagher help `|Y |`This help` +|`hf gallagher reader `|N |`Attempt to read and extract tag data` +|`hf gallagher clone `|N |`Add Gallagher credentials to a DESFire card` +|`hf gallagher delete `|N |`Delete Gallagher application from a DESFire card` + + ### hf ksx6924 { KS X 6924 (T-Money, Snapper+) RFIDs } From 8ecfc4af343285ab277d71e5b7c25153ae6b2236 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Wed, 5 Jan 2022 23:53:03 +1300 Subject: [PATCH 19/26] Make variables & function names snake_case --- client/src/cmdhfgallagher.c | 502 +++++++++++++++--------------- client/src/cmdhfgallagher.h | 2 +- client/src/cmdlfgallagher.c | 8 +- client/src/mifare/gallaghercore.c | 18 +- client/src/mifare/gallaghercore.h | 6 +- doc/commands.md | 4 +- 6 files changed, 272 insertions(+), 268 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 8e089e23c..e8ff0554d 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -36,7 +36,7 @@ static const uint8_t DEFAULT_SITE_KEY[] = { * @brief Reverses the bytes in AID. Used when parsing CLI args * (because Proxmark displays AIDs in reverse byte order). */ -static void reverseAid(uint8_t *aid) { +static void reverse_aid(uint8_t *aid) { uint8_t tmp = aid[0]; aid[0] = aid[2]; aid[2] = tmp; @@ -46,7 +46,7 @@ static void reverseAid(uint8_t *aid) { * @brief Converts a Card Application Directory format application ID to an integer. * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDByteToUint(). */ -static uint32_t cadAidByteToUint(uint8_t *data) { +static uint32_t cad_aid_byte_to_uint(uint8_t *data) { return data[2] + (data[1] << 8) + (data[0] << 16); } @@ -54,7 +54,7 @@ static uint32_t cadAidByteToUint(uint8_t *data) { * @brief Converts an integer application ID to Card Application Directory format. * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDUintToByte(). */ -static void cadAidUintToByte(uint32_t aid, uint8_t *data) { +static void cad_aid_uint_to_byte(uint32_t aid, uint8_t *data) { data[2] = aid & 0xff; data[1] = (aid >> 8) & 0xff; data[0] = (aid >> 16) & 0xff; @@ -64,42 +64,42 @@ static void cadAidUintToByte(uint32_t aid, uint8_t *data) { * @brief Returns true if the Card Application Directory entry * is for the specified region & facility, false otherwise. */ -static bool cadFacilityMatch(uint8_t *entry, uint8_t regionCode, uint16_t facilityCode) { - return entry[0] == regionCode && (entry[1] << 8) + entry[2] == facilityCode; +static bool cad_facility_match(uint8_t *entry, uint8_t region_code, uint16_t facility_code) { + return entry[0] == region_code && (entry[1] << 8) + entry[2] == facility_code; } /** * @brief Create Gallagher Application Master Key by diversifying * the MIFARE Site Key with card UID, key number, and application ID. * - * @param sitekey MIFARE Site Key (16 bytes). + * @param site_key MIFARE Site Key (16 bytes). * @param uid Card unique ID (4 or 7 bytes). - * @param uidLen Length of UID. - * @param keyNum Key number (0 <= keyNum <= 2). - * @param aid Application ID (0x2?81F4 where 0 <= ? <= B). - * @param keyOut Buffer to copy the diversified key into (must be 16 bytes). + * @param uid_len Length of UID. + * @param key_num Key number (0 <= key_num <= 2). + * @param aid Application ID (0x2?81F4 where 0 <= ? <= 0xB). + * @param key_output Buffer to copy the diversified key into (must be 16 bytes). * @return PM3_SUCCESS if successful, PM3_EINVARG if an argument is invalid. */ -int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, - uint8_t keyNo, uint32_t aid, uint8_t *keyOut) { +int hfgal_diversify_key(uint8_t *site_key, uint8_t *uid, uint8_t uid_len, + uint8_t key_num, uint32_t aid, uint8_t *key_output) { // Generate diversification input - uint8_t kdfInputLen = 11; - int res = mfdes_kdf_input_gallagher(uid, uidLen, keyNo, aid, keyOut, &kdfInputLen); + uint8_t kdf_input_len = 11; + int res = mfdes_kdf_input_gallagher(uid, uid_len, key_num, aid, key_output, &kdf_input_len); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed generating Gallagher key diversification input"); - if (sitekey == NULL) { - PrintAndLogEx(INFO, "GallagherDiversifyKey is using default site key: %s", + if (site_key == NULL) { + PrintAndLogEx(INFO, "hfgal_diversify_key is using default site key: %s", sprint_hex_inrow(DEFAULT_SITE_KEY, ARRAYLEN(DEFAULT_SITE_KEY))); - sitekey = (uint8_t *) &DEFAULT_SITE_KEY; + site_key = (uint8_t *) &DEFAULT_SITE_KEY; } // Make temporary DesfireContext DesfireContext_t dctx = {0}; - DesfireSetKey(&dctx, 0, T_AES, sitekey); + DesfireSetKey(&dctx, 0, T_AES, site_key); // Diversify input & copy to output buffer - MifareKdfAn10922(&dctx, DCOMasterKey, keyOut, kdfInputLen); - memcpy(keyOut, dctx.key, CRYPTO_AES128_KEY_SIZE); + MifareKdfAn10922(&dctx, DCOMasterKey, key_output, kdf_input_len); + memcpy(key_output, dctx.key, CRYPTO_AES128_KEY_SIZE); return PM3_SUCCESS; } @@ -107,7 +107,7 @@ int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, /** * @brief Select application ID. */ -static int selectAid(DesfireContext_t *ctx, uint32_t aid, bool verbose) { +static int select_aid(DesfireContext_t *ctx, uint32_t aid, bool verbose) { // TODO: do these both need to be set? DesfireSetCommMode(ctx, DCMPlain); DesfireSetCommandSet(ctx, DCCNativeISO); @@ -125,7 +125,7 @@ static int selectAid(DesfireContext_t *ctx, uint32_t aid, bool verbose) { } /** - * @brief Authenticate to application. + * @brief Authenticate to application. Uses existing authentication keys in context. */ static int authenticate(DesfireContext_t *ctx, bool verbose) { // TODO: do these both need to be set? @@ -153,8 +153,8 @@ static int authenticate(DesfireContext_t *ctx, bool verbose) { * @brief Select application ID & authenticate. * Uses existing authentication keys in context. */ -static int selectAidAndAuthenticate(DesfireContext_t *ctx, uint32_t aid, bool verbose) { - int res = selectAid(ctx, aid, verbose); +static int select_aid_and_authenticate(DesfireContext_t *ctx, uint32_t aid, bool verbose) { + int res = select_aid(ctx, aid, verbose); HFGAL_RET_IF_ERR(res); res = authenticate(ctx, verbose); @@ -166,7 +166,7 @@ static int selectAidAndAuthenticate(DesfireContext_t *ctx, uint32_t aid, bool ve /** * @brief Returns true if the specified application exists, false otherwise. */ -static bool aidExists(DesfireContext_t *ctx, uint32_t aid, bool verbose) { +static bool aid_exists(DesfireContext_t *ctx, uint32_t aid, bool verbose) { // TODO: do these both need to be set? DesfireSetCommMode(ctx, DCMPlain); DesfireSetCommandSet(ctx, DCCNativeISO); @@ -185,10 +185,10 @@ static bool aidExists(DesfireContext_t *ctx, uint32_t aid, bool verbose) { * @brief Returns the lowest available Gallagher application ID. * @return 0 if no AID is available, or an AID in the range 0x2?81F4, where 0 <= ? <= 0xB. */ -static uint32_t findAvailableGallagherAid(DesfireContext_t *ctx, bool verbose) { +static uint32_t find_available_gallagher_aid(DesfireContext_t *ctx, bool verbose) { for (uint8_t i = 0x0; i <= 0xB; i++) { uint32_t aid = 0x2081F4 | (i << 16); - if (!aidExists(ctx, aid, verbose)) + if (!aid_exists(ctx, aid, verbose)) return aid; } return 0; @@ -197,44 +197,46 @@ static uint32_t findAvailableGallagherAid(DesfireContext_t *ctx, bool verbose) { /** * @brief Read Gallagher Card Application Directory from card. * - * @param destBuf Buffer to copy Card Application Directory into. - * @param destBufLen Size of destBuf. Must be at least 108 bytes. - * @param numEntries Will be set to the number of entries in the Card Application Directory. + * @param dest_buf Buffer to copy Card Application Directory into. + * @param dest_buf_len Size of dest_buf. Must be at least 108 bytes. + * @param num_entries Will be set to the number of entries in the Card Application Directory. */ -static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, uint8_t destBufLen, uint8_t *numEntries, bool verbose) { - if (destBufLen < 3 * 36) { - PrintAndLogEx(ERR, "readCardApplicationDirectory destination buffer is incorrectly sized. " - "Received length %d, must be at least %d", destBufLen, 3 * 36); +static int hfgal_read_cad(DesfireContext_t *ctx, uint8_t *dest_buf, + uint8_t dest_buf_len, uint8_t *num_entries, bool verbose) { + if (dest_buf_len < 3 * 36) { + PrintAndLogEx(ERR, "hfgal_read_cad destination buffer is incorrectly sized. " + "Received length %d, must be at least %d", dest_buf_len, 3 * 36); return PM3_EINVARG; } // Get card AIDs from Card Application Directory (which contains 1 to 3 files) - int res = selectAid(ctx, CAD_AID, verbose); + int res = select_aid(ctx, CAD_AID, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting Card Application Directory, does AID %06X exist?", CAD_AID); // Read up to 3 files with 6x 6-byte entries each for (uint8_t i = 0; i < 3; i++) { - size_t readLen; - res = DesfireReadFile(ctx, i, 0, 36, &destBuf[i * 36], &readLen); + size_t read_len; + res = DesfireReadFile(ctx, i, 0, 36, &dest_buf[i * 36], &read_len); if (res != PM3_SUCCESS && res != PM3_EAPDU_FAIL) HFGAL_RET_ERR(res, "Failed reading file %d in Card Application Directory (AID %06X)", i, CAD_AID); // end if the last entry is NULL - if (memcmp(&destBuf[36 * i + 30], "\0\0\0\0\0\0", 6) == 0) break; + if (memcmp(&dest_buf[36 * i + 30], "\0\0\0\0\0\0", 6) == 0) break; } // Count number of entries (i.e. count until we hit a NULL entry) - *numEntries = 0; - for (uint8_t i = 0; i < destBufLen; i += 6) { - if (memcmp(&destBuf[i], "\0\0\0\0\0\0", 6) == 0) break; - *numEntries += 1; + *num_entries = 0; + for (uint8_t i = 0; i < dest_buf_len; i += 6) { + if (memcmp(&dest_buf[i], "\0\0\0\0\0\0", 6) == 0) break; + *num_entries += 1; } if (verbose) { // Print what we found PrintAndLogEx(SUCCESS, "Card Application Directory contains:" NOLF); - for (int i = 0; i < *numEntries; i++) - PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", cadAidByteToUint(&destBuf[i * 6 + 3])); + for (int i = 0; i < *num_entries; i++) + PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", + cad_aid_byte_to_uint(&dest_buf[i * 6 + 3])); PrintAndLogEx(NORMAL, ""); } @@ -245,40 +247,39 @@ static int readCardApplicationDirectory(DesfireContext_t *ctx, uint8_t *destBuf, * @brief Read credentials from a single AID. * * @param aid Application ID to read. - * @param sitekey MIFARE site key. + * @param site_key MIFARE site key. * @param creds Decoded credentials will be stored in this structure. */ -static int readCardApplicationCredentials(DesfireContext_t *ctx, uint32_t aid, uint8_t *sitekey, GallagherCredentials_t *creds, bool verbose) { +static int hfgal_read_app_creds(DesfireContext_t *ctx, uint32_t aid, uint8_t *site_key, + GallagherCredentials_t *creds, bool verbose) { // Check that card UID has been set if (ctx->uidlen == 0) HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext (required for key diversification)"); // Select application & authenticate - DesfireSetKeyNoClear(ctx, 2, T_AES, sitekey); + DesfireSetKeyNoClear(ctx, 2, T_AES, site_key); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - int res = selectAidAndAuthenticate(ctx, aid, verbose); + int res = select_aid_and_authenticate(ctx, aid, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting/authenticating to AID %06X", aid); // Read file 0 (contains credentials) uint8_t buf[16] = {0}; - size_t readLen = 0; + size_t read_len = 0; DesfireSetCommMode(ctx, DCMEncrypted); - res = DesfireReadFile(ctx, 0, 0, 16, buf, &readLen); + res = DesfireReadFile(ctx, 0, 0, 16, buf, &read_len); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed reading file 0 in AID %06X", aid); // Check file contained 16 bytes of data - if (readLen != 16) { - HFGAL_RET_ERR(PM3_EFAILED, "Failed reading file 0 in AID %06X, expected 16 bytes but received %d bytes", aid, readLen); - } + if (read_len != 16) + HFGAL_RET_ERR(PM3_EFAILED, "Failed reading file 0 in AID %06X, expected 16 bytes but received %d bytes", aid, read_len); // Check second half of file is the bitwise inverse of the first half for (uint8_t i = 8; i < 16; i++) buf[i] ^= 0xFF; - if (memcmp(buf, &buf[8], 8) != 0) { + if (memcmp(buf, &buf[8], 8) != 0) HFGAL_RET_ERR(PM3_EFAILED, "Invalid cardholder data in file 0 in AID %06X. Received %s", sprint_hex_inrow(buf, 16)); - } - decodeCardholderCredentials(buf, creds); + gallagher_decode_creds(buf, creds); // TODO: read MIFARE Enhanced Security file // https://github.com/megabug/gallagher-research/blob/master/formats/mes.md @@ -290,10 +291,10 @@ static int readCardApplicationCredentials(DesfireContext_t *ctx, uint32_t aid, u * @brief Read credentials from a Gallagher card. * * @param aid Application ID to read. If 0, then the Card Application Directory will be queried and all entries will be read. - * @param sitekey MIFARE site key. + * @param site_key MIFARE site key. * @param quiet Suppress error messages. Used when in continuous reader mode. */ -static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { +static int hfgal_read_card(uint32_t aid, uint8_t *site_key, bool verbose, bool quiet) { DropField(); clearCommandBuffer(); @@ -307,42 +308,42 @@ static int readCard(uint32_t aid, uint8_t *sitekey, bool verbose, bool quiet) { // Find AIDs to process (from CLI args or the Card Application Directory) uint8_t cad[36 * 3] = {0}; - uint8_t numEntries = 0; + uint8_t num_entries = 0; if (aid != 0) { - cadAidUintToByte(aid, &cad[3]); - numEntries = 1; + cad_aid_uint_to_byte(aid, &cad[3]); + num_entries = 1; } else { - res = readCardApplicationDirectory(&dctx, cad, ARRAYLEN(cad), &numEntries, verbose); + res = hfgal_read_cad(&dctx, cad, ARRAYLEN(cad), &num_entries, verbose); HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading Card Application Directory"); } // Loop through each application in the CAD - for (uint8_t i = 0; i < numEntries * 6; i += 6) { - uint16_t regionCode = cad[i + 0]; - uint16_t facilityCode = (cad[i + 1] << 8) + cad[i + 2]; - uint32_t currentAid = cadAidByteToUint(&cad[i + 3]); + for (uint8_t i = 0; i < num_entries * 6; i += 6) { + uint16_t region_code = cad[i + 0]; + uint16_t facility_code = (cad[i + 1] << 8) + cad[i + 2]; + uint32_t current_aid = cad_aid_byte_to_uint(&cad[i + 3]); if (verbose) { - if (regionCode > 0 || facilityCode > 0) - PrintAndLogEx(INFO, "Reading AID: %06X, region: %u, facility: %u", currentAid, regionCode, facilityCode); + if (region_code > 0 || facility_code > 0) + PrintAndLogEx(INFO, "Reading AID: %06X, region: %u, facility: %u", current_aid, region_code, facility_code); else - PrintAndLogEx(INFO, "Reading AID: %06X", currentAid); + PrintAndLogEx(INFO, "Reading AID: %06X", current_aid); } // Read & decode credentials GallagherCredentials_t creds = {0}; - res = readCardApplicationCredentials(&dctx, currentAid, sitekey, &creds, verbose); + res = hfgal_read_app_creds(&dctx, current_aid, site_key, &creds, verbose); HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application credentials"); PrintAndLogEx(SUCCESS, "GALLAGHER (AID %06X) - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") - ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), currentAid, + ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), current_aid, creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); } return PM3_SUCCESS; } -static int CmdGallagherReader(const char *Cmd) { +static int CmdGallagherReader(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher reader", "Read a GALLAGHER tag", @@ -360,51 +361,52 @@ static int CmdGallagherReader(const char *Cmd) { arg_lit0("@", "continuous", "Continuous reader mode"), arg_param_end }; - CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIExecWithReturn(ctx, cmd, argtable, true); - int aidLen = 0; - uint8_t aidBuf[3] = {0}; - CLIGetHexWithReturn(ctx, 1, aidBuf, &aidLen); - if (aidLen > 0 && aidLen != 3) + int aid_len = 0; + uint8_t aid_buf[3] = {0}; + CLIGetHexWithReturn(ctx, 1, aid_buf, &aid_len); + if (aid_len > 0 && aid_len != 3) HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); - reverseAid(aidBuf); // PM3 displays AIDs backwards - uint32_t aid = DesfireAIDByteToUint(aidBuf); + reverse_aid(aid_buf); // PM3 displays AIDs backwards + uint32_t aid = DesfireAIDByteToUint(aid_buf); - int sitekeyLen = 0; - uint8_t sitekey[16] = {0}; - memcpy(sitekey, DEFAULT_SITE_KEY, ARRAYLEN(sitekey)); - CLIGetHexWithReturn(ctx, 2, sitekey, &sitekeyLen); - if (sitekeyLen > 0 && sitekeyLen != 16) + int site_key_len = 0; + uint8_t site_key[16] = {0}; + memcpy(site_key, DEFAULT_SITE_KEY, ARRAYLEN(site_key)); + CLIGetHexWithReturn(ctx, 2, site_key, &site_key_len); + if (site_key_len > 0 && site_key_len != 16) HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); SetAPDULogging(arg_get_lit(ctx, 3)); bool verbose = arg_get_lit(ctx, 4); - bool continuousMode = arg_get_lit(ctx, 5); + bool continuous_mode = arg_get_lit(ctx, 5); CLIParserFree(ctx); - if (!continuousMode) + if (!continuous_mode) // Read single card - return readCard(aid, sitekey, verbose, false); + return hfgal_read_card(aid, site_key, verbose, false); // Loop until is pressed PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); while (!kbd_enter_pressed()) - readCard(aid, sitekey, verbose, !verbose); + hfgal_read_card(aid, site_key, verbose, !verbose); return PM3_SUCCESS; } /** * @brief Delete the CAD or an application that contains cardholder credentials. * - * @param sitekey MIFARE site key. + * @param site_key MIFARE site key. * @param aid Application ID to remove. */ -static int deleteGallagherApplication(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, bool verbose) { +static int hfgal_delete_app(DesfireContext_t *ctx, uint8_t *site_key, + uint32_t aid, bool verbose) { // Select application & authenticate - DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); + DesfireSetKeyNoClear(ctx, 0, T_AES, site_key); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - int res = selectAidAndAuthenticate(ctx, aid, verbose); + int res = select_aid_and_authenticate(ctx, aid, verbose); HFGAL_RET_IF_ERR(res); // Delete application @@ -419,23 +421,23 @@ static int deleteGallagherApplication(DesfireContext_t *ctx, uint8_t *sitekey, u /** * @brief Create a new application to store Gallagher cardholder credentials. * - * @param sitekey MIFARE site key. + * @param site_key MIFARE site key. * @param aid New application ID. Should be 0x2?81F4, where 0 <= ? <= 0xB. */ -static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, bool verbose) { +static int hfgal_create_creds_app(DesfireContext_t *ctx, uint8_t *site_key, uint32_t aid, bool verbose) { // Select application & authenticate - int res = selectAidAndAuthenticate(ctx, 0x000000, verbose); + int res = select_aid_and_authenticate(ctx, 0x000000, verbose); HFGAL_RET_IF_ERR(res); // UID is required for key diversification if (ctx->uidlen == 0) - HFGAL_RET_ERR(PM3_EINVARG, "UID is required for key diversification. Please fetch it before calling `createGallagherCredentialsApplication`"); + HFGAL_RET_ERR(PM3_EINVARG, "UID is required for key diversification. Please fetch it before calling `hfgal_create_creds_app`"); // Create application - DesfireCryptoAlgorithm dstalgo = T_AES; - uint8_t keycount = 3; + DesfireCryptoAlgorithm app_algo = T_AES; + uint8_t num_keys = 3; uint8_t ks1 = 0x0B; - uint8_t ks2 = (DesfireKeyAlgoToType(dstalgo) << 6) | keycount;; + uint8_t ks2 = (DesfireKeyAlgoToType(app_algo) << 6) | num_keys;; uint8_t data[5] = {0}; DesfireAIDUintToByte(aid, &data[0]); @@ -450,28 +452,28 @@ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t PrintAndLogEx(INFO, "Created application %06X (currently has empty contents & blank keys)", aid); // Select the new application - res = selectAid(ctx, aid, verbose); + res = select_aid(ctx, aid, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting application %06X", aid); // Add key 2, then key 0 (we must authenticate with key 0 in order to make changes) for (int i = 2; i >= 0; i -= 2) { // Diversify key uint8_t buf[CRYPTO_AES128_KEY_SIZE] = {0}; - res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, i, aid, buf); + res = hfgal_diversify_key(site_key, ctx->uid, ctx->uidlen, i, aid, buf); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key %d for AID %06X", i, aid); PrintAndLogEx(INFO, "Diversified key %d for AID %06X: " _GREEN_("%s"), i, aid, sprint_hex_inrow(buf, ARRAYLEN(buf))); // Authenticate - uint8_t blankKey[CRYPTO_AES128_KEY_SIZE] = {0}; - DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); + uint8_t blank_key[CRYPTO_AES128_KEY_SIZE] = {0}; + DesfireSetKeyNoClear(ctx, 0, T_AES, blank_key); DesfireSetKdf(ctx, MFDES_KDF_ALGO_NONE, NULL, 0); res = authenticate(ctx, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Desfire authenticate error. Result: [%d] %s", res, DesfireAuthErrorToStr(res)); // Change key DesfireSetCommMode(ctx, DCMEncryptedPlain); - res = DesfireChangeKey(ctx, false, i, dstalgo, 1, buf, dstalgo, blankKey, verbose); + res = DesfireChangeKey(ctx, false, i, app_algo, 1, buf, app_algo, blank_key, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed setting key %d for AID %06X", i, aid); if (verbose) @@ -485,33 +487,34 @@ static int createGallagherCredentialsApplication(DesfireContext_t *ctx, uint8_t /** * @brief Create a new file containing Gallagher cardholder credentials. * - * @param sitekey MIFARE site key. + * @param site_key MIFARE site key. * @param aid Application ID to put the new file in. * @param creds Gallagher cardholder credentials. */ -static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, GallagherCredentials_t *creds, bool verbose) { +static int hfgal_create_creds_file(DesfireContext_t *ctx, uint8_t *site_key, uint32_t aid, + GallagherCredentials_t *creds, bool verbose) { // Select application & authenticate - DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); + DesfireSetKeyNoClear(ctx, 0, T_AES, site_key); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - int res = selectAidAndAuthenticate(ctx, aid, verbose); + int res = select_aid_and_authenticate(ctx, aid, verbose); HFGAL_RET_IF_ERR(res); // Prepare create file command - uint8_t fileType = 0; // standard data file - uint8_t fileId = 0x00; - uint8_t fileSize = 16; - uint8_t fileAccessMode = 0x03; // encrypted - uint32_t fileRights = 0x2000; // key 0 has God mode, key 2 can read + uint8_t file_type = 0; // standard data file + uint8_t file_id = 0x00; + uint8_t file_size = 16; + uint8_t file_access_mode = 0x03; // encrypted + uint32_t file_rights = 0x2000; // key 0 has God mode, key 2 can read uint8_t data[7] = {0}; - data[0] = fileId; - data[1] = fileAccessMode; - data[2] = fileRights & 0xff; - data[3] = (fileRights >> 8) & 0xff; - Uint3byteToMemLe(&data[4], fileSize); + data[0] = file_id; + data[1] = file_access_mode; + data[2] = file_rights & 0xff; + data[3] = (file_rights >> 8) & 0xff; + Uint3byteToMemLe(&data[4], file_size); // Create file - res = DesfireCreateFile(ctx, fileType, data, ARRAYLEN(data), false); + res = DesfireCreateFile(ctx, file_type, data, ARRAYLEN(data), false); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file 0 in AID %06X", aid); if (verbose) @@ -519,13 +522,13 @@ static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *siteke // Create file contents (2nd half is the bitwise inverse of the encoded creds) uint8_t contents[16] = {0}; - encodeCardholderCredentials(contents, creds); + gallagher_encode_creds(contents, creds); for (int i = 0; i < 8; i++) contents[i + 8] = contents[i] ^ 0xFF; // Write file DesfireSetCommMode(ctx, DCMEncrypted); - res = DesfireWriteFile(ctx, fileId, 0, ARRAYLEN(contents), contents); + res = DesfireWriteFile(ctx, file_id, 0, ARRAYLEN(contents), contents); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file 0 in AID %06X"); PrintAndLogEx(INFO, "Successfully wrote cardholder credentials to file 0 in AID %06X", aid); @@ -535,22 +538,22 @@ static int createGallagherCredentialsFile(DesfireContext_t *ctx, uint8_t *siteke /** * @brief Create the Gallagher Card Application Directory. * - * @param sitekey MIFARE site key. + * @param site_key MIFARE site key. */ -static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verbose) { +static int hfgal_create_cad(DesfireContext_t *ctx, uint8_t *site_key, bool verbose) { // Check that card UID has been set if (ctx->uidlen == 0) HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext (required for key diversification)"); // Select application & authenticate - int res = selectAidAndAuthenticate(ctx, 0x000000, verbose); + int res = select_aid_and_authenticate(ctx, 0x000000, verbose); HFGAL_RET_IF_ERR(res); // Create application - DesfireCryptoAlgorithm dstalgo = T_AES; - uint8_t keycount = 1; + DesfireCryptoAlgorithm app_algo = T_AES; + uint8_t num_keys = 1; uint8_t ks1 = 0x0B; - uint8_t ks2 = (DesfireKeyAlgoToType(dstalgo) << 6) | keycount;; + uint8_t ks2 = (DesfireKeyAlgoToType(app_algo) << 6) | num_keys;; uint8_t data[5] = {0}; DesfireAIDUintToByte(CAD_AID, &data[0]); @@ -565,22 +568,22 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb PrintAndLogEx(INFO, "Created Card Application Directory (AID %06X, currently has empty contents & blank keys)", CAD_AID); // Select application & authenticate - uint8_t blankKey[DESFIRE_MAX_KEY_SIZE] = {0}; - DesfireSetKeyNoClear(ctx, 0, T_AES, blankKey); + uint8_t blank_key[DESFIRE_MAX_KEY_SIZE] = {0}; + DesfireSetKeyNoClear(ctx, 0, T_AES, blank_key); DesfireSetKdf(ctx, MFDES_KDF_ALGO_NONE, NULL, 0); - res = selectAidAndAuthenticate(ctx, CAD_AID, verbose); + res = select_aid_and_authenticate(ctx, CAD_AID, verbose); HFGAL_RET_IF_ERR(res); // Diversify key uint8_t buf[CRYPTO_AES128_KEY_SIZE] = {0}; - res = GallagherDiversifyKey(sitekey, ctx->uid, ctx->uidlen, 0, CAD_AID, buf); + res = hfgal_diversify_key(site_key, ctx->uid, ctx->uidlen, 0, CAD_AID, buf); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key 0 for AID %06X", CAD_AID); PrintAndLogEx(INFO, "Diversified key 0 for CAD (AID %06X): " _GREEN_("%s"), CAD_AID, sprint_hex_inrow(buf, ARRAYLEN(buf))); // Change key DesfireSetCommMode(ctx, DCMEncryptedPlain); - res = DesfireChangeKey(ctx, false, 0, dstalgo, 1, buf, dstalgo, blankKey, verbose); + res = DesfireChangeKey(ctx, false, 0, app_algo, 1, buf, app_algo, blank_key, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed setting key 0 for CAD"); if (verbose) @@ -593,91 +596,91 @@ static int createGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, bool verb /** * @brief Update the Gallagher Card Application Directory with a new entry. * - * @param sitekey MIFARE site key. + * @param site_key MIFARE site key. * @param aid Application ID to add to the CAD. * @param creds Gallagher cardholder credentials (region_code & facility_code are required). */ -static int addToGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, GallagherCredentials_t *creds, bool verbose) { +static int hfgal_add_aid_to_cad(DesfireContext_t *ctx, uint8_t *site_key, uint32_t aid, + GallagherCredentials_t *creds, bool verbose) { // Check if CAD exists uint8_t cad[36 * 3] = {0}; - uint8_t numEntries = 0; - if (aidExists(ctx, CAD_AID, false)) { + uint8_t num_entries = 0; + if (aid_exists(ctx, CAD_AID, false)) { if (verbose) PrintAndLogEx(INFO, "Card Application Directory exists, reading entries..."); - int res = readCardApplicationDirectory( - ctx, cad, ARRAYLEN(cad), &numEntries, verbose); + int res = hfgal_read_cad(ctx, cad, ARRAYLEN(cad), &num_entries, verbose); HFGAL_RET_IF_ERR(res); // Check that there is space for the new entry - if (numEntries >= 18) + if (num_entries >= 18) HFGAL_RET_ERR(PM3_EFATAL, "Card application directory is full"); } else { - // CAD doesn't exist, we need to create it. + // CAD doesn't exist, we need to create it if (verbose) PrintAndLogEx(INFO, "Card Application Directory does not exist, creating it now..."); - int res = createGallagherCAD(ctx, sitekey, verbose); + int res = hfgal_create_cad(ctx, site_key, verbose); HFGAL_RET_IF_ERR(res); } - uint8_t fileId = numEntries / 6; // 6 entries per file - uint8_t entryNum = numEntries % 6; + uint8_t file_id = num_entries / 6; // 6 entries per file + uint8_t entry_num = num_entries % 6; // Check if facility already exists in CAD. for (uint8_t i = 0; i < ARRAYLEN(cad); i += 6) { - if (cadFacilityMatch(&cad[i], creds->region_code, creds->facility_code)) + if (cad_facility_match(&cad[i], creds->region_code, creds->facility_code)) HFGAL_RET_ERR(PM3_EFATAL, "Facility already exists in CAD, delete or " - "update AID %06X instead", cadAidByteToUint(&cad[i + 3])); + "update AID %06X instead", cad_aid_byte_to_uint(&cad[i + 3])); } // Create entry - uint8_t *entry = &cad[numEntries * 6]; + uint8_t *entry = &cad[num_entries * 6]; entry[0] = creds->region_code; entry[1] = (creds->facility_code >> 8) & 0xFF; entry[2] = creds->facility_code & 0xFF; - cadAidUintToByte(aid, &entry[3]); + cad_aid_uint_to_byte(aid, &entry[3]); if (verbose) - PrintAndLogEx(INFO, "Adding entry to CAD (position %d in file %d): %s", entryNum, fileId, sprint_hex_inrow(entry, 6)); + PrintAndLogEx(INFO, "Adding entry to CAD (position %d in file %d): %s", entry_num, file_id, sprint_hex_inrow(entry, 6)); // Select application & authenticate - DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); + DesfireSetKeyNoClear(ctx, 0, T_AES, site_key); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - int res = selectAidAndAuthenticate(ctx, CAD_AID, verbose); + int res = select_aid_and_authenticate(ctx, CAD_AID, verbose); HFGAL_RET_IF_ERR(res); // Create file if necessary - if (entryNum == 0) { + if (entry_num == 0) { if (verbose) PrintAndLogEx(INFO, "Creating new file in CAD"); // Prepare create file command - uint8_t fileType = 0; // standard data file - uint8_t fileSize = 36; - uint8_t fileAccessMode = 0x00; // plain - uint32_t fileRights = 0xE000; // key 0 has God mode, everyone can read + uint8_t file_type = 0; // standard data file + uint8_t file_size = 36; + uint8_t file_access_mode = 0x00; // plain + uint32_t file_rights = 0xE000; // key 0 has God mode, everyone can read uint8_t data[7] = {0}; - data[0] = fileId; - data[1] = fileAccessMode; - data[2] = fileRights & 0xff; - data[3] = (fileRights >> 8) & 0xff; - Uint3byteToMemLe(&data[4], fileSize); + data[0] = file_id; + data[1] = file_access_mode; + data[2] = file_rights & 0xff; + data[3] = (file_rights >> 8) & 0xff; + Uint3byteToMemLe(&data[4], file_size); // Create file - res = DesfireCreateFile(ctx, fileType, data, ARRAYLEN(data), false); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file %d in CAD (AID %06X)", fileId, CAD_AID); + res = DesfireCreateFile(ctx, file_type, data, ARRAYLEN(data), false); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file %d in CAD (AID %06X)", file_id, CAD_AID); if (verbose) - PrintAndLogEx(INFO, "Created file %d in CAD (currently has empty contents)", fileId); + PrintAndLogEx(INFO, "Created file %d in CAD (currently has empty contents)", file_id); // Write file - res = DesfireWriteFile(ctx, fileId, 0, 36, &cad[fileId * 36]); + res = DesfireWriteFile(ctx, file_id, 0, 36, &cad[file_id * 36]); } else // Write file - res = DesfireWriteFile(ctx, fileId, entryNum * 6, 6, entry); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", fileId, CAD_AID); + res = DesfireWriteFile(ctx, file_id, entry_num * 6, 6, entry); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", file_id, CAD_AID); PrintAndLogEx(INFO, "Successfully added new entry for %06X to the Card Application Directory", aid); return PM3_SUCCESS; @@ -686,70 +689,71 @@ static int addToGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t a /** * @brief Remove an entry from the Gallagher Card Application Directory. * - * @param sitekey MIFARE site key. + * @param site_key MIFARE site key. * @param aid Application ID to add to the CAD. */ -static int removeFromGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint32_t aid, bool verbose) { +static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, + uint32_t aid, bool verbose) { // Check if CAD exists uint8_t cad[36 * 3] = {0}; - uint8_t numEntries = 0; + uint8_t num_entries = 0; - int res = readCardApplicationDirectory( - ctx, cad, ARRAYLEN(cad), &numEntries, verbose); + int res = hfgal_read_cad( + ctx, cad, ARRAYLEN(cad), &num_entries, verbose); HFGAL_RET_IF_ERR(res); // Check if facility already exists in CAD - uint8_t entryNum = 0; - for (; entryNum < numEntries; entryNum++) { - if (aid > 0 && aid == cadAidByteToUint(&cad[entryNum * 6 + 3])) + uint8_t entry_num = 0; + for (; entry_num < num_entries; entry_num++) { + if (aid > 0 && aid == cad_aid_byte_to_uint(&cad[entry_num * 6 + 3])) break; } - if (entryNum >= numEntries) + if (entry_num >= num_entries) HFGAL_RET_ERR(PM3_EINVARG, "Specified facility or AID does not exist in the Card Application Directory"); // Remove entry (shift all entries left, then clear the last entry) memmove( - &cad[entryNum * 6], - &cad[(entryNum + 1) * 6], - ARRAYLEN(cad) - (entryNum + 1) * 6 + &cad[entry_num * 6], + &cad[(entry_num + 1) * 6], + ARRAYLEN(cad) - (entry_num + 1) * 6 ); memset(&cad[ARRAYLEN(cad) - 6], 0, 6); // Select application & authenticate - DesfireSetKeyNoClear(ctx, 0, T_AES, sitekey); + DesfireSetKeyNoClear(ctx, 0, T_AES, site_key); DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - res = selectAidAndAuthenticate(ctx, CAD_AID, verbose); + res = select_aid_and_authenticate(ctx, CAD_AID, verbose); HFGAL_RET_IF_ERR(res); // Determine what files we need to update - uint8_t fileIdStart = (entryNum - 1) / 6; - uint8_t fileIdStop = (numEntries - 1) / 6; + uint8_t file_id_start = (entry_num - 1) / 6; + uint8_t file_id_stop = (num_entries - 1) / 6; - for (uint8_t fileId = fileIdStart; fileId <= fileIdStop; fileId++) { + for (uint8_t file_id = file_id_start; file_id <= file_id_stop; file_id++) { // Write file - res = DesfireWriteFile(ctx, fileId, 0, 36, &cad[fileId * 36]); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", fileId, CAD_AID); + res = DesfireWriteFile(ctx, file_id, 0, 36, &cad[file_id * 36]); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", file_id, CAD_AID); if (verbose) - PrintAndLogEx(INFO, "Updated file %d in CAD", fileId); + PrintAndLogEx(INFO, "Updated file %d in CAD", file_id); } // Delete empty files if necessary - if (fileIdStart != fileIdStop) { - uint8_t fileId = fileIdStop; + if (file_id_start != file_id_stop) { + uint8_t file_id = file_id_stop; DesfireSetCommMode(ctx, DCMMACed); - res = DesfireDeleteFile(ctx, fileId); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting file %d from CAD (AID %06X)", fileId, CAD_AID); + res = DesfireDeleteFile(ctx, file_id); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting file %d from CAD (AID %06X)", file_id, CAD_AID); if (verbose) - PrintAndLogEx(INFO, "Deleted unnecessary file %d from CAD (AID %06X)", fileId, CAD_AID); + PrintAndLogEx(INFO, "Deleted unnecessary file %d from CAD (AID %06X)", file_id, CAD_AID); // Delete the Card Application Directory if necessary // (if we just deleted the last file in it) - if (fileId == 0) { - res = deleteGallagherApplication(ctx, sitekey, CAD_AID, verbose); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting file %d from CAD (AID %06X)", fileId, CAD_AID); + if (file_id == 0) { + res = hfgal_delete_app(ctx, site_key, CAD_AID, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting file %d from CAD (AID %06X)", file_id, CAD_AID); if (verbose) PrintAndLogEx(INFO, "Removed CAD because it was empty"); @@ -760,7 +764,7 @@ static int removeFromGallagherCAD(DesfireContext_t *ctx, uint8_t *sitekey, uint3 return PM3_SUCCESS; } -static int CmdGallagherClone(const char *Cmd) { +static int CmdGallagherClone(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher clone", "Clone a GALLAGHER card to a blank DESFire card", @@ -783,54 +787,54 @@ static int CmdGallagherClone(const char *Cmd) { arg_str0(NULL, "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), arg_param_end }; - CLIExecWithReturn(ctx, Cmd, argtable, false); + CLIExecWithReturn(ctx, cmd, argtable, false); SetAPDULogging(arg_get_lit(ctx, 1)); bool verbose = arg_get_lit(ctx, 2); - int keyNum = arg_get_int_def(ctx, 3, 0); + int key_num = arg_get_int_def(ctx, 3, 0); - int algo = T_DES; - if (CLIGetOptionList(arg_get_str(ctx, 4), DesfireAlgoOpts, &algo)) return PM3_ESOFT; + int key_algo = T_DES; + if (CLIGetOptionList(arg_get_str(ctx, 4), DesfireAlgoOpts, &key_algo)) return PM3_ESOFT; - int keyLen = 0; + int key_len = 0; uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0}; - CLIGetHexWithReturn(ctx, 5, key, &keyLen); - if (keyLen && keyLen != desfire_get_key_length(algo)) - HFGAL_RET_ERR(PM3_EINVARG, "%s key must have %d bytes length instead of %d", CLIGetOptionListStr(DesfireAlgoOpts, algo), desfire_get_key_length(algo), keyLen); - if (keyLen == 0) + CLIGetHexWithReturn(ctx, 5, key, &key_len); + if (key_len && key_len != desfire_get_key_length(key_algo)) + HFGAL_RET_ERR(PM3_EINVARG, "%s key must have %d bytes length instead of %d", CLIGetOptionListStr(DesfireAlgoOpts, key_algo), desfire_get_key_length(key_algo), key_len); + if (key_len == 0) // Default to a key of all zeros - keyLen = desfire_get_key_length(algo); + key_len = desfire_get_key_length(key_algo); uint64_t region_code = arg_get_u64(ctx, 6); // uint4, input will be validated later uint64_t facility_code = arg_get_u64(ctx, 7); // uint16 uint64_t card_number = arg_get_u64(ctx, 8); // uint24 uint64_t issue_level = arg_get_u64(ctx, 9); // uint4 - int aidLen = 0; - uint8_t aidBuf[3] = {0}; + int aid_len = 0; + uint8_t aid_buf[3] = {0}; uint32_t aid = 0; - CLIGetHexWithReturn(ctx, 10, aidBuf, &aidLen); - if (aidLen > 0) { - if (aidLen != 3) + CLIGetHexWithReturn(ctx, 10, aid_buf, &aid_len); + if (aid_len > 0) { + if (aid_len != 3) HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); - reverseAid(aidBuf); // PM3 displays AIDs backwards - aid = DesfireAIDByteToUint(aidBuf); + reverse_aid(aid_buf); // PM3 displays AIDs backwards + aid = DesfireAIDByteToUint(aid_buf); // Check that the AID is in the expected range - if (memcmp(aidBuf, "\xF4\x81", 2) != 0 || aidBuf[2] < 0x20 || aidBuf[2] > 0x2B) + if (memcmp(aid_buf, "\xF4\x81", 2) != 0 || aid_buf[2] < 0x20 || aid_buf[2] > 0x2B) // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); } - int sitekeyLen = 0; - uint8_t sitekey[16] = {0}; - memcpy(sitekey, DEFAULT_SITE_KEY, ARRAYLEN(sitekey)); - CLIGetHexWithReturn(ctx, 11, sitekey, &sitekeyLen); - if (sitekeyLen > 0 && sitekeyLen != 16) + int site_key_len = 0; + uint8_t site_key[16] = {0}; + memcpy(site_key, DEFAULT_SITE_KEY, ARRAYLEN(site_key)); + CLIGetHexWithReturn(ctx, 11, site_key, &site_key_len); + if (site_key_len > 0 && site_key_len != 16) HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); CLIParserFree(ctx); - if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) + if (!gallagher_is_valid_creds(region_code, facility_code, card_number, issue_level)) return PM3_EINVARG; GallagherCredentials_t creds = { @@ -850,27 +854,27 @@ static int CmdGallagherClone(const char *Cmd) { HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed retrieving card UID"); // Find available Gallagher AID if the user did not specify one - if (aidLen == 0) { - aid = findAvailableGallagherAid(&dctx, verbose); + if (aid_len == 0) { + aid = find_available_gallagher_aid(&dctx, verbose); if (aid == 0) HFGAL_RET_ERR(PM3_EFATAL, "Could not find an available AID, card is full"); } // Update Card Application Directory - DesfireSetKeyNoClear(&dctx, keyNum, algo, key); + DesfireSetKeyNoClear(&dctx, key_num, key_algo, key); DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); - res = addToGallagherCAD(&dctx, sitekey, aid, &creds, verbose); + res = hfgal_add_aid_to_cad(&dctx, site_key, aid, &creds, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed updating Gallagher Card Application Directory"); // Create application - DesfireSetKeyNoClear(&dctx, keyNum, algo, key); + DesfireSetKeyNoClear(&dctx, key_num, key_algo, key); DesfireSetKdf(&dctx, MFDES_KDF_ALGO_NONE, NULL, 0); - res = createGallagherCredentialsApplication(&dctx, sitekey, aid, verbose); + res = hfgal_create_creds_app(&dctx, site_key, aid, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Gallagher application"); // Create credential files // Don't need to set keys here, they're generated automatically - res = createGallagherCredentialsFile(&dctx, sitekey, aid, &creds, verbose); + res = hfgal_create_creds_file(&dctx, site_key, aid, &creds, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Gallagher credential file"); PrintAndLogEx(SUCCESS, "Done"); @@ -878,7 +882,7 @@ static int CmdGallagherClone(const char *Cmd) { return PM3_SUCCESS; } -static int CmdGallagherDelete(const char *Cmd) { +static int CmdGallagherDelete(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher delete", "Delete Gallagher application from a DESFire card", @@ -894,31 +898,31 @@ static int CmdGallagherDelete(const char *Cmd) { arg_str0(NULL, "sitekey", "", "MIFARE site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), arg_param_end }; - CLIExecWithReturn(ctx, Cmd, argtable, false); + CLIExecWithReturn(ctx, cmd, argtable, false); SetAPDULogging(arg_get_lit(ctx, 1)); bool verbose = arg_get_lit(ctx, 2); - int aidLen = 0; - uint8_t aidBuf[3] = {0}; + int aid_len = 0; + uint8_t aid_buf[3] = {0}; uint32_t aid = 0; - CLIGetHexWithReturn(ctx, 3, aidBuf, &aidLen); + CLIGetHexWithReturn(ctx, 3, aid_buf, &aid_len); - if (aidLen != 3) + if (aid_len != 3) HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); - reverseAid(aidBuf); // PM3 displays AIDs backwards - aid = DesfireAIDByteToUint(aidBuf); + reverse_aid(aid_buf); // PM3 displays AIDs backwards + aid = DesfireAIDByteToUint(aid_buf); // Check that the AID is in the expected range - if (memcmp(aidBuf, "\xF4\x81", 2) != 0 || aidBuf[2] < 0x20 || aidBuf[2] > 0x2B) + if (memcmp(aid_buf, "\xF4\x81", 2) != 0 || aid_buf[2] < 0x20 || aid_buf[2] > 0x2B) // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); - int sitekeyLen = 0; - uint8_t sitekey[16] = {0}; - memcpy(sitekey, DEFAULT_SITE_KEY, ARRAYLEN(sitekey)); - CLIGetHexWithReturn(ctx, 4, sitekey, &sitekeyLen); - if (sitekeyLen > 0 && sitekeyLen != 16) + int site_key_len = 0; + uint8_t site_key[16] = {0}; + memcpy(site_key, DEFAULT_SITE_KEY, ARRAYLEN(site_key)); + CLIGetHexWithReturn(ctx, 4, site_key, &site_key_len); + if (site_key_len > 0 && site_key_len != 16) HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); CLIParserFree(ctx); @@ -932,11 +936,11 @@ static int CmdGallagherDelete(const char *Cmd) { HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed retrieving card UID"); // Update Card Application Directory - res = removeFromGallagherCAD(&dctx, sitekey, aid, verbose); + res = hfgal_remove_aid_from_cad(&dctx, site_key, aid, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed removing %06X from the Card Application Directory"); // Delete application - res = deleteGallagherApplication(&dctx, sitekey, aid, verbose); + res = hfgal_delete_app(&dctx, site_key, aid, verbose); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting Gallagher application"); PrintAndLogEx(SUCCESS, "Done"); @@ -944,23 +948,23 @@ static int CmdGallagherDelete(const char *Cmd) { return PM3_SUCCESS; } -static int CmdHelp(const char *Cmd); +static int CmdHelp(const char *cmd); static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"reader", CmdGallagherReader, IfPm3Iso14443, "Attempt to read and extract tag data"}, + {"reader", CmdGallagherReader, IfPm3Iso14443, "Read & decode all Gallagher credentials on the DESFire card"}, {"clone", CmdGallagherClone, IfPm3Iso14443, "Add Gallagher credentials to a DESFire card"}, - {"delete", CmdGallagherDelete, IfPm3Iso14443, "Delete Gallagher application from a DESFire card"}, + {"delete", CmdGallagherDelete, IfPm3Iso14443, "Delete Gallagher credentials from a DESFire card"}, {NULL, NULL, NULL, NULL} }; -static int CmdHelp(const char *Cmd) { - (void) Cmd; // Cmd is not used so far +static int CmdHelp(const char *cmd) { + (void) cmd; // cmd is not used so far CmdsHelp(CommandTable); return PM3_SUCCESS; } -int CmdHFGallagher(const char *Cmd) { +int CmdHFGallagher(const char *cmd) { clearCommandBuffer(); - return CmdsParse(CommandTable, Cmd); + return CmdsParse(CommandTable, cmd); } diff --git a/client/src/cmdhfgallagher.h b/client/src/cmdhfgallagher.h index 08d5d2150..3c4024114 100644 --- a/client/src/cmdhfgallagher.h +++ b/client/src/cmdhfgallagher.h @@ -29,7 +29,7 @@ int CmdHFGallagher(const char *Cmd); * @param keyOut Buffer to copy the diversified key into (must be 16 bytes). * @return PM3_SUCCESS if successful, PM3_EINVARG if an argument is invalid. */ -int GallagherDiversifyKey(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNum, uint32_t aid, uint8_t *keyOut); +int hfgal_diversify_key(uint8_t *sitekey, uint8_t *uid, uint8_t uidLen, uint8_t keyNum, uint32_t aid, uint8_t *keyOut); // Return error #define HFGAL_RET_ERR(err, ...) { PrintAndLogEx(ERR, __VA_ARGS__); return err; } diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index b09f93b60..e88175f89 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -76,7 +76,7 @@ int demodGallagher(bool verbose) { uint8_t calc_crc = CRC8Cardx(arr, ARRAYLEN(arr)); GallagherCredentials_t creds = {0}; - decodeCardholderCredentials(arr, &creds); + gallagher_decode_creds(arr, &creds); PrintAndLogEx(SUCCESS, "GALLAGHER - Region: " _GREEN_("%u") " Facility: " _GREEN_("%u") " Card No.: " _GREEN_("%u") " Issue Level: " _GREEN_("%u"), creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); @@ -142,7 +142,7 @@ static void setBitsInBlocks(uint32_t *blocks, uint8_t *pos, uint32_t data, uint8 static void createBlocks(uint32_t *blocks, GallagherCredentials_t *creds) { // put data into the correct places (Gallagher obfuscation) uint8_t arr[8] = {0}; - encodeCardholderCredentials(arr, creds); + gallagher_encode_creds(arr, creds); blocks[0] = blocks[1] = blocks[2] = 0; uint8_t pos = 0; @@ -222,7 +222,7 @@ static int CmdGallagherClone(const char *Cmd) { PrintAndLogEx(FAILED, "Can't specify both raw and rc/fc/cn/il at the same time"); return PM3_EINVARG; } - if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { + if (!gallagher_is_valid_creds(region_code, facility_code, card_number, issue_level)) { return PM3_EINVARG; } } @@ -322,7 +322,7 @@ static int CmdGallagherSim(const char *Cmd) { PrintAndLogEx(FAILED, "Can't specify both raw and rc/fc/cn/il at the same time"); return PM3_EINVARG; } - if (!isValidGallagherCredentials(region_code, facility_code, card_number, issue_level)) { + if (!gallagher_is_valid_creds(region_code, facility_code, card_number, issue_level)) { return PM3_EINVARG; } } diff --git a/client/src/mifare/gallaghercore.c b/client/src/mifare/gallaghercore.c index fb220eeb1..6bff623f8 100644 --- a/client/src/mifare/gallaghercore.c +++ b/client/src/mifare/gallaghercore.c @@ -62,7 +62,7 @@ static void descramble(uint8_t *arr, uint8_t len) { } } -void decodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds) { +void gallagher_decode_creds(uint8_t *eight_bytes, GallagherCredentials_t *creds) { uint8_t *arr = eight_bytes; descramble(arr, 8); @@ -80,7 +80,7 @@ void decodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *c creds->issue_level = arr[7] & 0x0F; } -void encodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds) { +void gallagher_encode_creds(uint8_t *eight_bytes, GallagherCredentials_t *creds) { uint8_t rc = creds->region_code; uint16_t fc = creds->facility_code; uint32_t cn = creds->card_number; @@ -100,25 +100,25 @@ void encodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *c scramble(eight_bytes, 8); } -bool isValidGallagherCredentials(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level) { - bool isValid = true; +bool gallagher_is_valid_creds(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level) { + bool is_valid = true; // validate input if (region_code > 0x0f) { PrintAndLogEx(ERR, "Region code must be 0 <= rc <= 15 (4 bits), received: %d", region_code); - isValid = false; + is_valid = false; } if (facility_code > 0xffff) { PrintAndLogEx(ERR, "Facility code must be 0 <= fc <= 65535 (2 bytes), received: %d", facility_code); - isValid = false; + is_valid = false; } if (card_number > 0xffffff) { PrintAndLogEx(ERR, "Card number must be 0 <= cn <= 16777215 (3 bytes), received: %d", card_number); - isValid = false; + is_valid = false; } if (issue_level > 0x0f) { PrintAndLogEx(ERR, "Issue level must be 0 <= il <= 15 (4 bits), received: %d", issue_level); - isValid = false; + is_valid = false; } - return isValid; + return is_valid; } diff --git a/client/src/mifare/gallaghercore.h b/client/src/mifare/gallaghercore.h index 37164f92e..bc9ee0c67 100644 --- a/client/src/mifare/gallaghercore.h +++ b/client/src/mifare/gallaghercore.h @@ -21,10 +21,10 @@ typedef struct { uint8_t issue_level; } GallagherCredentials_t; -void encodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds); +void gallagher_encode_creds(uint8_t *eight_bytes, GallagherCredentials_t *creds); -void decodeCardholderCredentials(uint8_t *eight_bytes, GallagherCredentials_t *creds); +void gallagher_decode_creds(uint8_t *eight_bytes, GallagherCredentials_t *creds); -bool isValidGallagherCredentials(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level); +bool gallagher_is_valid_creds(uint64_t region_code, uint64_t facility_code, uint64_t card_number, uint64_t issue_level); #endif diff --git a/doc/commands.md b/doc/commands.md index 3237a4c9d..ec92dcf2c 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -324,9 +324,9 @@ Check column "offline" for their availability. |command |offline |description |------- |------- |----------- |`hf gallagher help `|Y |`This help` -|`hf gallagher reader `|N |`Attempt to read and extract tag data` +|`hf gallagher reader `|N |`Read & decode all Gallagher credentials on the DESFire card` |`hf gallagher clone `|N |`Add Gallagher credentials to a DESFire card` -|`hf gallagher delete `|N |`Delete Gallagher application from a DESFire card` +|`hf gallagher delete `|N |`Delete Gallagher credentials from a DESFire card` ### hf ksx6924 From caebfdca622670e0558dad2cb28bec093dfa6c94 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Wed, 5 Jan 2022 23:54:18 +1300 Subject: [PATCH 20/26] Update license from LGPL to GPL --- client/src/cmdhfgallagher.c | 2 +- client/src/cmdhfgallagher.h | 2 +- client/src/mifare/gallaghercore.c | 2 +- client/src/mifare/gallaghercore.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index e8ff0554d..27c814237 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -2,7 +2,7 @@ * Matt Moran (@DarkMatterMatt), 2021 * ----------------------------------------------------------------------------- * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the + * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * ----------------------------------------------------------------------------- diff --git a/client/src/cmdhfgallagher.h b/client/src/cmdhfgallagher.h index 3c4024114..22aee9c2f 100644 --- a/client/src/cmdhfgallagher.h +++ b/client/src/cmdhfgallagher.h @@ -2,7 +2,7 @@ * Matt Moran (@DarkMatterMatt), 2021 * ----------------------------------------------------------------------------- * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the + * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * ----------------------------------------------------------------------------- diff --git a/client/src/mifare/gallaghercore.c b/client/src/mifare/gallaghercore.c index 6bff623f8..71e235286 100644 --- a/client/src/mifare/gallaghercore.c +++ b/client/src/mifare/gallaghercore.c @@ -2,7 +2,7 @@ * Matt Moran (@DarkMatterMatt), 2021 * ----------------------------------------------------------------------------- * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the + * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * ----------------------------------------------------------------------------- diff --git a/client/src/mifare/gallaghercore.h b/client/src/mifare/gallaghercore.h index bc9ee0c67..9137073bb 100644 --- a/client/src/mifare/gallaghercore.h +++ b/client/src/mifare/gallaghercore.h @@ -2,7 +2,7 @@ * Matt Moran (@DarkMatterMatt), 2021 * ----------------------------------------------------------------------------- * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the + * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * ----------------------------------------------------------------------------- From 02e5fb6b1c4ca40993ed42adbe04d26b50b4cf38 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Thu, 6 Jan 2022 00:00:04 +1300 Subject: [PATCH 21/26] Fix incorrect comments --- client/src/cmdlfgallagher.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index e88175f89..35e38d735 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -164,7 +164,6 @@ static void createBlocks(uint32_t *blocks, GallagherCredentials_t *creds) { } static int CmdGallagherClone(const char *Cmd) { - CLIParserContext *ctx; CLIParserInit(&ctx, "lf gallagher clone", "clone a GALLAGHER tag to a T55x7, Q5/T5555 or EM4305/4469 tag.", @@ -198,10 +197,10 @@ static int CmdGallagherClone(const char *Cmd) { bool q5 = arg_get_lit(ctx, 2); bool em = arg_get_lit(ctx, 3); - uint64_t region_code = arg_get_u64_def(ctx, 4, -1); // uint16, will be validated later - uint64_t facility_code = arg_get_u64_def(ctx, 5, -1); // uint32, will be validated later - uint64_t card_number = arg_get_u64_def(ctx, 6, -1); // uint64 - uint64_t issue_level = arg_get_u64_def(ctx, 7, -1); // uint32, will be validated later + uint64_t region_code = arg_get_u64_def(ctx, 4, -1); // uint4, input will be validated later + uint64_t facility_code = arg_get_u64_def(ctx, 5, -1); // uint16 + uint64_t card_number = arg_get_u64_def(ctx, 6, -1); // uint24 + uint64_t issue_level = arg_get_u64_def(ctx, 7, -1); // uint4 CLIParserFree(ctx); bool use_raw = raw_len > 0; @@ -303,10 +302,10 @@ static int CmdGallagherSim(const char *Cmd) { return PM3_EINVARG; } - uint64_t region_code = arg_get_u64_def(ctx, 2, -1); // uint16, will be validated later - uint64_t facility_code = arg_get_u64_def(ctx, 3, -1); // uint32, will be validated later - uint64_t card_number = arg_get_u64_def(ctx, 4, -1); // uint64 - uint64_t issue_level = arg_get_u64_def(ctx, 5, -1); // uint32, will be validated later + uint64_t region_code = arg_get_u64_def(ctx, 2, -1); // uint4, input will be validated later + uint64_t facility_code = arg_get_u64_def(ctx, 3, -1); // uint16 + uint64_t card_number = arg_get_u64_def(ctx, 4, -1); // uint24 + uint64_t issue_level = arg_get_u64_def(ctx, 5, -1); // uint4 CLIParserFree(ctx); bool use_raw = raw_len > 0; From 82cd44e99fc8fb7aeb5f4caff9f4b34ea045d6c7 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Thu, 6 Jan 2022 00:11:30 +1300 Subject: [PATCH 22/26] Reorder function definitions Order is roughly: - exported helpers - helpers - read -> create -> delete - exported commands --- client/src/cmdhfgallagher.c | 421 ++++++++++++++++++------------------ 1 file changed, 210 insertions(+), 211 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 27c814237..e5ef0401b 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -32,42 +32,6 @@ static const uint8_t DEFAULT_SITE_KEY[] = { 0x34, 0x30, 0x2E, 0xB2, 0x99, 0xAA, 0xB4, 0x56, }; -/** - * @brief Reverses the bytes in AID. Used when parsing CLI args - * (because Proxmark displays AIDs in reverse byte order). - */ -static void reverse_aid(uint8_t *aid) { - uint8_t tmp = aid[0]; - aid[0] = aid[2]; - aid[2] = tmp; -} - -/** - * @brief Converts a Card Application Directory format application ID to an integer. - * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDByteToUint(). - */ -static uint32_t cad_aid_byte_to_uint(uint8_t *data) { - return data[2] + (data[1] << 8) + (data[0] << 16); -} - -/** - * @brief Converts an integer application ID to Card Application Directory format. - * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDUintToByte(). - */ -static void cad_aid_uint_to_byte(uint32_t aid, uint8_t *data) { - data[2] = aid & 0xff; - data[1] = (aid >> 8) & 0xff; - data[0] = (aid >> 16) & 0xff; -} - -/** - * @brief Returns true if the Card Application Directory entry - * is for the specified region & facility, false otherwise. - */ -static bool cad_facility_match(uint8_t *entry, uint8_t region_code, uint16_t facility_code) { - return entry[0] == region_code && (entry[1] << 8) + entry[2] == facility_code; -} - /** * @brief Create Gallagher Application Master Key by diversifying * the MIFARE Site Key with card UID, key number, and application ID. @@ -104,6 +68,42 @@ int hfgal_diversify_key(uint8_t *site_key, uint8_t *uid, uint8_t uid_len, return PM3_SUCCESS; } +/** + * @brief Reverses the bytes in AID. Used when parsing CLI args + * (because Proxmark displays AIDs in reverse byte order). + */ +static void reverse_aid(uint8_t *aid) { + uint8_t tmp = aid[0]; + aid[0] = aid[2]; + aid[2] = tmp; +} + +/** + * @brief Converts a Card Application Directory format application ID to an integer. + * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDByteToUint(). + */ +static uint32_t cad_aid_byte_to_uint(uint8_t *data) { + return data[2] + (data[1] << 8) + (data[0] << 16); +} + +/** + * @brief Converts an integer application ID to Card Application Directory format. + * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDUintToByte(). + */ +static void cad_aid_uint_to_byte(uint32_t aid, uint8_t *data) { + data[2] = aid & 0xff; + data[1] = (aid >> 8) & 0xff; + data[0] = (aid >> 16) & 0xff; +} + +/** + * @brief Returns true if the Card Application Directory entry + * is for the specified region & facility, false otherwise. + */ +static bool cad_facility_match(uint8_t *entry, uint8_t region_code, uint16_t facility_code) { + return entry[0] == region_code && (entry[1] << 8) + entry[2] == facility_code; +} + /** * @brief Select application ID. */ @@ -195,51 +195,25 @@ static uint32_t find_available_gallagher_aid(DesfireContext_t *ctx, bool verbose } /** - * @brief Read Gallagher Card Application Directory from card. + * @brief Delete the CAD or an application that contains cardholder credentials. * - * @param dest_buf Buffer to copy Card Application Directory into. - * @param dest_buf_len Size of dest_buf. Must be at least 108 bytes. - * @param num_entries Will be set to the number of entries in the Card Application Directory. + * @param site_key MIFARE site key. + * @param aid Application ID to remove. */ -static int hfgal_read_cad(DesfireContext_t *ctx, uint8_t *dest_buf, - uint8_t dest_buf_len, uint8_t *num_entries, bool verbose) { - if (dest_buf_len < 3 * 36) { - PrintAndLogEx(ERR, "hfgal_read_cad destination buffer is incorrectly sized. " - "Received length %d, must be at least %d", dest_buf_len, 3 * 36); - return PM3_EINVARG; - } +static int hfgal_delete_app(DesfireContext_t *ctx, uint8_t *site_key, + uint32_t aid, bool verbose) { + // Select application & authenticate + DesfireSetKeyNoClear(ctx, 0, T_AES, site_key); + DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); + int res = select_aid_and_authenticate(ctx, aid, verbose); + HFGAL_RET_IF_ERR(res); - // Get card AIDs from Card Application Directory (which contains 1 to 3 files) - int res = select_aid(ctx, CAD_AID, verbose); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting Card Application Directory, does AID %06X exist?", CAD_AID); - - // Read up to 3 files with 6x 6-byte entries each - for (uint8_t i = 0; i < 3; i++) { - size_t read_len; - res = DesfireReadFile(ctx, i, 0, 36, &dest_buf[i * 36], &read_len); - if (res != PM3_SUCCESS && res != PM3_EAPDU_FAIL) - HFGAL_RET_ERR(res, "Failed reading file %d in Card Application Directory (AID %06X)", i, CAD_AID); - - // end if the last entry is NULL - if (memcmp(&dest_buf[36 * i + 30], "\0\0\0\0\0\0", 6) == 0) break; - } - - // Count number of entries (i.e. count until we hit a NULL entry) - *num_entries = 0; - for (uint8_t i = 0; i < dest_buf_len; i += 6) { - if (memcmp(&dest_buf[i], "\0\0\0\0\0\0", 6) == 0) break; - *num_entries += 1; - } - - if (verbose) { - // Print what we found - PrintAndLogEx(SUCCESS, "Card Application Directory contains:" NOLF); - for (int i = 0; i < *num_entries; i++) - PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", - cad_aid_byte_to_uint(&dest_buf[i * 6 + 3])); - PrintAndLogEx(NORMAL, ""); - } + // Delete application + DesfireSetCommMode(ctx, DCMMACed); + res = DesfireDeleteApplication(ctx, aid); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting AID %06X", aid); + PrintAndLogEx(INFO, "Successfully deleted AID %06X", aid); return PM3_SUCCESS; } @@ -250,7 +224,7 @@ static int hfgal_read_cad(DesfireContext_t *ctx, uint8_t *dest_buf, * @param site_key MIFARE site key. * @param creds Decoded credentials will be stored in this structure. */ -static int hfgal_read_app_creds(DesfireContext_t *ctx, uint32_t aid, uint8_t *site_key, +static int hfgal_read_creds_app(DesfireContext_t *ctx, uint32_t aid, uint8_t *site_key, GallagherCredentials_t *creds, bool verbose) { // Check that card UID has been set if (ctx->uidlen == 0) @@ -287,137 +261,6 @@ static int hfgal_read_app_creds(DesfireContext_t *ctx, uint32_t aid, uint8_t *si return PM3_SUCCESS; } -/** - * @brief Read credentials from a Gallagher card. - * - * @param aid Application ID to read. If 0, then the Card Application Directory will be queried and all entries will be read. - * @param site_key MIFARE site key. - * @param quiet Suppress error messages. Used when in continuous reader mode. - */ -static int hfgal_read_card(uint32_t aid, uint8_t *site_key, bool verbose, bool quiet) { - DropField(); - clearCommandBuffer(); - - // Set up context - DesfireContext_t dctx = {0}; - DesfireClearContext(&dctx); - - // Get card UID (for key diversification) - int res = DesfireGetCardUID(&dctx); - HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed retrieving card UID"); - - // Find AIDs to process (from CLI args or the Card Application Directory) - uint8_t cad[36 * 3] = {0}; - uint8_t num_entries = 0; - if (aid != 0) { - cad_aid_uint_to_byte(aid, &cad[3]); - num_entries = 1; - } else { - res = hfgal_read_cad(&dctx, cad, ARRAYLEN(cad), &num_entries, verbose); - HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading Card Application Directory"); - } - - // Loop through each application in the CAD - for (uint8_t i = 0; i < num_entries * 6; i += 6) { - uint16_t region_code = cad[i + 0]; - uint16_t facility_code = (cad[i + 1] << 8) + cad[i + 2]; - uint32_t current_aid = cad_aid_byte_to_uint(&cad[i + 3]); - - if (verbose) { - if (region_code > 0 || facility_code > 0) - PrintAndLogEx(INFO, "Reading AID: %06X, region: %u, facility: %u", current_aid, region_code, facility_code); - else - PrintAndLogEx(INFO, "Reading AID: %06X", current_aid); - } - - // Read & decode credentials - GallagherCredentials_t creds = {0}; - res = hfgal_read_app_creds(&dctx, current_aid, site_key, &creds, verbose); - HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application credentials"); - - PrintAndLogEx(SUCCESS, "GALLAGHER (AID %06X) - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") - ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), current_aid, - creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); - } - - return PM3_SUCCESS; -} - -static int CmdGallagherReader(const char *cmd) { - CLIParserContext *ctx; - CLIParserInit(&ctx, "hf gallagher reader", - "Read a GALLAGHER tag", - "hf gallagher reader --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" - " -> act as a reader that skips reading the Card Application Directory and uses a non-default site key\n" - "hf gallagher reader -@ -> continuous reader mode" - ); - - void *argtable[] = { - arg_param_begin, - arg_str0(NULL, "aid", "", "Application ID to read (3 bytes)"), - arg_str0("k", "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), - arg_lit0(NULL, "apdu", "Show APDU requests and responses"), - arg_lit0("v", "verbose", "Verbose mode"), - arg_lit0("@", "continuous", "Continuous reader mode"), - arg_param_end - }; - CLIExecWithReturn(ctx, cmd, argtable, true); - - int aid_len = 0; - uint8_t aid_buf[3] = {0}; - CLIGetHexWithReturn(ctx, 1, aid_buf, &aid_len); - if (aid_len > 0 && aid_len != 3) - HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); - - reverse_aid(aid_buf); // PM3 displays AIDs backwards - uint32_t aid = DesfireAIDByteToUint(aid_buf); - - int site_key_len = 0; - uint8_t site_key[16] = {0}; - memcpy(site_key, DEFAULT_SITE_KEY, ARRAYLEN(site_key)); - CLIGetHexWithReturn(ctx, 2, site_key, &site_key_len); - if (site_key_len > 0 && site_key_len != 16) - HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); - - SetAPDULogging(arg_get_lit(ctx, 3)); - bool verbose = arg_get_lit(ctx, 4); - bool continuous_mode = arg_get_lit(ctx, 5); - CLIParserFree(ctx); - - if (!continuous_mode) - // Read single card - return hfgal_read_card(aid, site_key, verbose, false); - - // Loop until is pressed - PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); - while (!kbd_enter_pressed()) - hfgal_read_card(aid, site_key, verbose, !verbose); - return PM3_SUCCESS; -} - -/** - * @brief Delete the CAD or an application that contains cardholder credentials. - * - * @param site_key MIFARE site key. - * @param aid Application ID to remove. - */ -static int hfgal_delete_app(DesfireContext_t *ctx, uint8_t *site_key, - uint32_t aid, bool verbose) { - // Select application & authenticate - DesfireSetKeyNoClear(ctx, 0, T_AES, site_key); - DesfireSetKdf(ctx, MFDES_KDF_ALGO_GALLAGHER, NULL, 0); - int res = select_aid_and_authenticate(ctx, aid, verbose); - HFGAL_RET_IF_ERR(res); - - // Delete application - DesfireSetCommMode(ctx, DCMMACed); - res = DesfireDeleteApplication(ctx, aid); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting AID %06X", aid); - - PrintAndLogEx(INFO, "Successfully deleted AID %06X", aid); - return PM3_SUCCESS; -} - /** * @brief Create a new application to store Gallagher cardholder credentials. * @@ -535,6 +378,55 @@ static int hfgal_create_creds_file(DesfireContext_t *ctx, uint8_t *site_key, uin return PM3_SUCCESS; } +/** + * @brief Read Gallagher Card Application Directory from card. + * + * @param dest_buf Buffer to copy Card Application Directory into. + * @param dest_buf_len Size of dest_buf. Must be at least 108 bytes. + * @param num_entries Will be set to the number of entries in the Card Application Directory. + */ +static int hfgal_read_cad(DesfireContext_t *ctx, uint8_t *dest_buf, + uint8_t dest_buf_len, uint8_t *num_entries, bool verbose) { + if (dest_buf_len < 3 * 36) { + PrintAndLogEx(ERR, "hfgal_read_cad destination buffer is incorrectly sized. " + "Received length %d, must be at least %d", dest_buf_len, 3 * 36); + return PM3_EINVARG; + } + + // Get card AIDs from Card Application Directory (which contains 1 to 3 files) + int res = select_aid(ctx, CAD_AID, verbose); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting Card Application Directory, does AID %06X exist?", CAD_AID); + + // Read up to 3 files with 6x 6-byte entries each + for (uint8_t i = 0; i < 3; i++) { + size_t read_len; + res = DesfireReadFile(ctx, i, 0, 36, &dest_buf[i * 36], &read_len); + if (res != PM3_SUCCESS && res != PM3_EAPDU_FAIL) + HFGAL_RET_ERR(res, "Failed reading file %d in Card Application Directory (AID %06X)", i, CAD_AID); + + // end if the last entry is NULL + if (memcmp(&dest_buf[36 * i + 30], "\0\0\0\0\0\0", 6) == 0) break; + } + + // Count number of entries (i.e. count until we hit a NULL entry) + *num_entries = 0; + for (uint8_t i = 0; i < dest_buf_len; i += 6) { + if (memcmp(&dest_buf[i], "\0\0\0\0\0\0", 6) == 0) break; + *num_entries += 1; + } + + if (verbose) { + // Print what we found + PrintAndLogEx(SUCCESS, "Card Application Directory contains:" NOLF); + for (int i = 0; i < *num_entries; i++) + PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", + cad_aid_byte_to_uint(&dest_buf[i * 6 + 3])); + PrintAndLogEx(NORMAL, ""); + } + + return PM3_SUCCESS; +} + /** * @brief Create the Gallagher Card Application Directory. * @@ -698,8 +590,7 @@ static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, uint8_t cad[36 * 3] = {0}; uint8_t num_entries = 0; - int res = hfgal_read_cad( - ctx, cad, ARRAYLEN(cad), &num_entries, verbose); + int res = hfgal_read_cad(ctx, cad, ARRAYLEN(cad), &num_entries, verbose); HFGAL_RET_IF_ERR(res); // Check if facility already exists in CAD @@ -764,6 +655,114 @@ static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, return PM3_SUCCESS; } +/** + * @brief Read credentials from a Gallagher card. + * + * @param aid Application ID to read. If 0, then the Card Application Directory will be queried and all entries will be read. + * @param site_key MIFARE site key. + * @param quiet Suppress error messages. Used when in continuous reader mode. + */ +static int hfgal_read_card(uint32_t aid, uint8_t *site_key, bool verbose, bool quiet) { + DropField(); + clearCommandBuffer(); + + // Set up context + DesfireContext_t dctx = {0}; + DesfireClearContext(&dctx); + + // Get card UID (for key diversification) + int res = DesfireGetCardUID(&dctx); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed retrieving card UID"); + + // Find AIDs to process (from CLI args or the Card Application Directory) + uint8_t cad[36 * 3] = {0}; + uint8_t num_entries = 0; + if (aid != 0) { + cad_aid_uint_to_byte(aid, &cad[3]); + num_entries = 1; + } else { + res = hfgal_read_cad(&dctx, cad, ARRAYLEN(cad), &num_entries, verbose); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading Card Application Directory"); + } + + // Loop through each application in the CAD + for (uint8_t i = 0; i < num_entries * 6; i += 6) { + uint16_t region_code = cad[i + 0]; + uint16_t facility_code = (cad[i + 1] << 8) + cad[i + 2]; + uint32_t current_aid = cad_aid_byte_to_uint(&cad[i + 3]); + + if (verbose) { + if (region_code > 0 || facility_code > 0) + PrintAndLogEx(INFO, "Reading AID: %06X, region: %u, facility: %u", current_aid, region_code, facility_code); + else + PrintAndLogEx(INFO, "Reading AID: %06X", current_aid); + } + + // Read & decode credentials + GallagherCredentials_t creds = {0}; + res = hfgal_read_creds_app(&dctx, current_aid, site_key, &creds, verbose); + HFGAL_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application credentials"); + + PrintAndLogEx(SUCCESS, "GALLAGHER (AID %06X) - Region: " _GREEN_("%u") ", Facility: " _GREEN_("%u") + ", Card No.: " _GREEN_("%u") ", Issue Level: " _GREEN_("%u"), current_aid, + creds.region_code, creds.facility_code, creds.card_number, creds.issue_level); + } + + return PM3_SUCCESS; +} + +static int CmdGallagherReader(const char *cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf gallagher reader", + "Read a GALLAGHER tag", + "hf gallagher reader --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" + " -> act as a reader that skips reading the Card Application Directory and uses a non-default site key\n" + "hf gallagher reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_str0(NULL, "aid", "", "Application ID to read (3 bytes)"), + arg_str0("k", "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), + arg_lit0(NULL, "apdu", "Show APDU requests and responses"), + arg_lit0("v", "verbose", "Verbose mode"), + arg_lit0("@", "continuous", "Continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, cmd, argtable, true); + + int aid_len = 0; + uint8_t aid_buf[3] = {0}; + CLIGetHexWithReturn(ctx, 1, aid_buf, &aid_len); + if (aid_len > 0 && aid_len != 3) + HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); + + reverse_aid(aid_buf); // PM3 displays AIDs backwards + uint32_t aid = DesfireAIDByteToUint(aid_buf); + + int site_key_len = 0; + uint8_t site_key[16] = {0}; + memcpy(site_key, DEFAULT_SITE_KEY, ARRAYLEN(site_key)); + CLIGetHexWithReturn(ctx, 2, site_key, &site_key_len); + if (site_key_len > 0 && site_key_len != 16) + HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); + + SetAPDULogging(arg_get_lit(ctx, 3)); + bool verbose = arg_get_lit(ctx, 4); + bool continuous_mode = arg_get_lit(ctx, 5); + CLIParserFree(ctx); + + if (!continuous_mode) + // Read single card + return hfgal_read_card(aid, site_key, verbose, false); + + // Loop until is pressed + PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); + while (!kbd_enter_pressed()) + hfgal_read_card(aid, site_key, verbose, !verbose); + return PM3_SUCCESS; +} + static int CmdGallagherClone(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher clone", From 84ff84ffd0218816ec1032c8a9b2690e4b6951c5 Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Fri, 7 Jan 2022 00:05:38 +1300 Subject: [PATCH 23/26] Add `hf gallagher diversify` --- client/src/cmdhfgallagher.c | 89 +++++++++++++++++++++++++++++++++++-- client/src/rl_vocabulory.h | 1 + doc/commands.json | 23 ++++++++-- doc/commands.md | 1 + 4 files changed, 107 insertions(+), 7 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index e5ef0401b..8635cfebd 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -947,13 +947,94 @@ static int CmdGallagherDelete(const char *cmd) { return PM3_SUCCESS; } +static int CmdGallagherDiversify(const char *cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf gallagher diversify", + "Diversify Gallagher key", + "hf gallagher diversify --uid 11223344556677 --aid 2081f4" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0(NULL, "apdu", "Show APDU requests and responses"), + + arg_str1(NULL, "aid", "", "Application ID for diversification (3 bytes)"), + arg_int0(NULL, "keynum", "", "Key number [default=0]"), + arg_str0(NULL, "uid", "", "Card UID to delete (4 or 7 bytes)"), + arg_str0(NULL, "sitekey", "", "MIFARE site key to compute diversified keys (16 bytes, required if using non-default key)"), + arg_param_end + }; + CLIExecWithReturn(ctx, cmd, argtable, false); + + SetAPDULogging(arg_get_lit(ctx, 1)); + + int aid_len = 0; + uint8_t aid_buf[3] = {0}; + uint32_t aid = 0; + CLIGetHexWithReturn(ctx, 2, aid_buf, &aid_len); + + if (aid_len != 3) + HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); + reverse_aid(aid_buf); // PM3 displays AIDs backwards + aid = DesfireAIDByteToUint(aid_buf); + + // Check that the AID is in the expected range + if (memcmp(aid_buf, "\xF4\x81", 2) != 0 || aid_buf[2] < 0x20 || aid_buf[2] > 0x2B) + // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't + HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); + + int key_num = arg_get_int_def(ctx, 3, 0); + + int uid_len = 0; + uint8_t uid[7] = {0}; + CLIGetHexWithReturn(ctx, 4, uid, &uid_len); + if (uid_len > 0 && uid_len != 4 && uid_len != 7) + HFGAL_RET_ERR(PM3_EINVARG, "--uid must be 4 or 7 bytes"); + + int site_key_len = 0; + uint8_t site_key[16] = {0}; + memcpy(site_key, DEFAULT_SITE_KEY, ARRAYLEN(site_key)); + CLIGetHexWithReturn(ctx, 5, site_key, &site_key_len); + if (site_key_len > 0 && site_key_len != 16) + HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); + CLIParserFree(ctx); + + if (uid_len == 0) { + // Set up context + DropField(); + DesfireContext_t dctx = {0}; + DesfireClearContext(&dctx); + + // Get card UID (for key diversification) + int res = DesfireGetCardUID(&dctx); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed retrieving card UID"); + + uid_len = dctx.uidlen; + memcpy(uid, dctx.uid, uid_len); + } + + // Diversify key + uint8_t key[CRYPTO_AES128_KEY_SIZE] = {0}; + int res = hfgal_diversify_key(site_key, uid, uid_len, key_num, aid, key); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key"); + + char *key_str = sprint_hex_inrow(key, ARRAYLEN(key)); + PrintAndLogEx(SUCCESS, "Successfully diversified key: " _GREEN_("%s"), key_str); + + if (IfPm3Iso14443()) + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfdes auth --aid %06X --keyno %d " + "--algo AES --key %s`") " to verify", aid, key_num, key_str); + return PM3_SUCCESS; +} + static int CmdHelp(const char *cmd); static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"reader", CmdGallagherReader, IfPm3Iso14443, "Read & decode all Gallagher credentials on the DESFire card"}, - {"clone", CmdGallagherClone, IfPm3Iso14443, "Add Gallagher credentials to a DESFire card"}, - {"delete", CmdGallagherDelete, IfPm3Iso14443, "Delete Gallagher credentials from a DESFire card"}, + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"reader", CmdGallagherReader, IfPm3Iso14443, "Read & decode all Gallagher credentials on the DESFire card"}, + {"clone", CmdGallagherClone, IfPm3Iso14443, "Add Gallagher credentials to a DESFire card"}, + {"delete", CmdGallagherDelete, IfPm3Iso14443, "Delete Gallagher credentials from a DESFire card"}, + {"diversifykey", CmdGallagherDiversify, AlwaysAvailable, "Diversify Gallagher key"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/rl_vocabulory.h b/client/src/rl_vocabulory.h index 69f389a5d..87dcf1b6d 100644 --- a/client/src/rl_vocabulory.h +++ b/client/src/rl_vocabulory.h @@ -220,6 +220,7 @@ const static vocabulory_t vocabulory[] = { { 0, "hf gallagher reader" }, { 0, "hf gallagher clone" }, { 0, "hf gallagher delete" }, + { 1, "hf gallagher diversifykey" }, { 1, "hf ksx6924 help" }, { 0, "hf ksx6924 balance" }, { 0, "hf ksx6924 info" }, diff --git a/doc/commands.json b/doc/commands.json index 8cd2d65d5..b0b01bf45 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -2359,9 +2359,26 @@ ], "usage": "hf gallagher delete [-hv] [--apdu] --aid [--sitekey ]" }, + "hf gallagher diversifykey": { + "command": "hf gallagher diversifykey", + "description": "diversify gallagher key", + "notes": [ + "hf gallagher diversify --uid 11223344556677 --aid 2081f4 -> diversify" + ], + "offline": true, + "options": [ + "-h, --help this help", + "--apdu show apdu requests and responses", + "--aid application id for diversification (3 bytes)", + "--keynum key number [default=0]", + "--uid card uid to delete (4 or 7 bytes)", + "--sitekey mifare site key to compute diversified keys (16 bytes, required if using non-default key)" + ], + "usage": "hf gallagher diversify [-h] [--apdu] --aid [--keynum ] [--uid ] [--sitekey ]" + }, "hf gallagher help": { "command": "hf gallagher help", - "description": "help this help --------------------------------------------------------------------------------------- hf gallagher reader available offline: no read a gallagher tag", + "description": "help this help diversifykey diversify gallagher key --------------------------------------------------------------------------------------- hf gallagher reader available offline: no read a gallagher tag", "notes": [ "hf gallagher reader --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff -> act as a reader that skips reading the card application directory and uses a non-default site key", "hf gallagher reader -@ -> continuous reader mode" @@ -10217,8 +10234,8 @@ } }, "metadata": { - "commands_extracted": 600, + "commands_extracted": 601, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2022-01-05T09:45:02" + "extracted_on": "2022-01-06T11:03:41" } } \ No newline at end of file diff --git a/doc/commands.md b/doc/commands.md index ec92dcf2c..735be384a 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -327,6 +327,7 @@ Check column "offline" for their availability. |`hf gallagher reader `|N |`Read & decode all Gallagher credentials on the DESFire card` |`hf gallagher clone `|N |`Add Gallagher credentials to a DESFire card` |`hf gallagher delete `|N |`Delete Gallagher credentials from a DESFire card` +|`hf gallagher diversifykey`|Y |`Diversify Gallagher key` ### hf ksx6924 From 6f510db9fbb7d86e818c86fa7b59e9108ffe693a Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Fri, 7 Jan 2022 00:30:25 +1300 Subject: [PATCH 24/26] Fix incorrect CAD was written when removing credentials --- client/src/cmdhfgallagher.c | 46 ++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 8635cfebd..0bcb9d31f 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -386,7 +386,7 @@ static int hfgal_create_creds_file(DesfireContext_t *ctx, uint8_t *site_key, uin * @param num_entries Will be set to the number of entries in the Card Application Directory. */ static int hfgal_read_cad(DesfireContext_t *ctx, uint8_t *dest_buf, - uint8_t dest_buf_len, uint8_t *num_entries, bool verbose) { + uint8_t dest_buf_len, uint8_t *num_entries_out, bool verbose) { if (dest_buf_len < 3 * 36) { PrintAndLogEx(ERR, "hfgal_read_cad destination buffer is incorrectly sized. " "Received length %d, must be at least %d", dest_buf_len, 3 * 36); @@ -409,16 +409,19 @@ static int hfgal_read_cad(DesfireContext_t *ctx, uint8_t *dest_buf, } // Count number of entries (i.e. count until we hit a NULL entry) - *num_entries = 0; + uint8_t num_entries = 0; for (uint8_t i = 0; i < dest_buf_len; i += 6) { if (memcmp(&dest_buf[i], "\0\0\0\0\0\0", 6) == 0) break; - *num_entries += 1; + num_entries++; } + *num_entries_out = num_entries; - if (verbose) { + if (num_entries == 0) { + PrintAndLogEx(WARNING, "Card Application Directory is empty"); + } else if (verbose) { // Print what we found PrintAndLogEx(SUCCESS, "Card Application Directory contains:" NOLF); - for (int i = 0; i < *num_entries; i++) + for (int i = 0; i < num_entries; i++) PrintAndLogEx(NORMAL, "%s %06X" NOLF, (i == 0) ? "" : ",", cad_aid_byte_to_uint(&dest_buf[i * 6 + 3])); PrintAndLogEx(NORMAL, ""); @@ -594,19 +597,19 @@ static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, HFGAL_RET_IF_ERR(res); // Check if facility already exists in CAD - uint8_t entry_num = 0; - for (; entry_num < num_entries; entry_num++) { - if (aid > 0 && aid == cad_aid_byte_to_uint(&cad[entry_num * 6 + 3])) + uint8_t entry_idx; + for (entry_idx = 0; entry_idx < num_entries; entry_idx++) { + if (aid > 0 && aid == cad_aid_byte_to_uint(&cad[entry_idx * 6 + 3])) break; } - if (entry_num >= num_entries) + if (entry_idx >= num_entries) HFGAL_RET_ERR(PM3_EINVARG, "Specified facility or AID does not exist in the Card Application Directory"); // Remove entry (shift all entries left, then clear the last entry) memmove( - &cad[entry_num * 6], - &cad[(entry_num + 1) * 6], - ARRAYLEN(cad) - (entry_num + 1) * 6 + &cad[entry_idx * 6], + &cad[(entry_idx + 1) * 6], + ARRAYLEN(cad) - (entry_idx + 1) * 6 ); memset(&cad[ARRAYLEN(cad) - 6], 0, 6); @@ -617,10 +620,11 @@ static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, HFGAL_RET_IF_ERR(res); // Determine what files we need to update - uint8_t file_id_start = (entry_num - 1) / 6; + uint8_t file_id_start = entry_idx / 6; uint8_t file_id_stop = (num_entries - 1) / 6; + bool delete_last_file = (num_entries - 1) % 6 == 0; - for (uint8_t file_id = file_id_start; file_id <= file_id_stop; file_id++) { + for (uint8_t file_id = file_id_start; file_id <= file_id_stop - delete_last_file; file_id++) { // Write file res = DesfireWriteFile(ctx, file_id, 0, 36, &cad[file_id * 36]); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", file_id, CAD_AID); @@ -629,8 +633,8 @@ static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, PrintAndLogEx(INFO, "Updated file %d in CAD", file_id); } - // Delete empty files if necessary - if (file_id_start != file_id_stop) { + // Delete empty file if necessary + if (delete_last_file) { uint8_t file_id = file_id_stop; DesfireSetCommMode(ctx, DCMMACed); @@ -639,16 +643,6 @@ static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, if (verbose) PrintAndLogEx(INFO, "Deleted unnecessary file %d from CAD (AID %06X)", file_id, CAD_AID); - - // Delete the Card Application Directory if necessary - // (if we just deleted the last file in it) - if (file_id == 0) { - res = hfgal_delete_app(ctx, site_key, CAD_AID, verbose); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed deleting file %d from CAD (AID %06X)", file_id, CAD_AID); - - if (verbose) - PrintAndLogEx(INFO, "Removed CAD because it was empty"); - } } PrintAndLogEx(INFO, "Successfully removed %06X from the Card Application Directory", aid); From 533b31bc6de5e65fc33683d967982b8489ce12ea Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Fri, 7 Jan 2022 01:03:43 +1300 Subject: [PATCH 25/26] Format code/strings --- client/src/cmdhfgallagher.c | 185 +++++++++++++++++++++--------------- doc/commands.json | 48 +++++----- doc/commands.md | 2 +- 3 files changed, 133 insertions(+), 102 deletions(-) diff --git a/client/src/cmdhfgallagher.c b/client/src/cmdhfgallagher.c index 0bcb9d31f..801699480 100644 --- a/client/src/cmdhfgallagher.c +++ b/client/src/cmdhfgallagher.c @@ -80,7 +80,7 @@ static void reverse_aid(uint8_t *aid) { /** * @brief Converts a Card Application Directory format application ID to an integer. - * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDByteToUint(). + * Note: the CAD stores AIDs in reverse order, so this is different to DesfireAIDByteToUint(). */ static uint32_t cad_aid_byte_to_uint(uint8_t *data) { return data[2] + (data[1] << 8) + (data[0] << 16); @@ -88,7 +88,7 @@ static uint32_t cad_aid_byte_to_uint(uint8_t *data) { /** * @brief Converts an integer application ID to Card Application Directory format. - * Note that the CAD stores AIDs in reverse order, so this function is different to DesfireAIDUintToByte(). + * Note: the CAD stores AIDs in reverse order, so this is different to DesfireAIDUintToByte(). */ static void cad_aid_uint_to_byte(uint32_t aid, uint8_t *data) { data[2] = aid & 0xff; @@ -173,10 +173,12 @@ static bool aid_exists(DesfireContext_t *ctx, uint32_t aid, bool verbose) { int res = DesfireSelectAIDHex(ctx, aid, false, 0); if (res != PM3_SUCCESS && res != PM3_EAPDU_FAIL) - HFGAL_RET_ERR(false, "Select failed with error %d, assuming AID %06X does not exist", res, aid); + HFGAL_RET_ERR(false, "Select failed with error %d, assuming AID %06X " + "does not exist", res, aid); if (verbose) - PrintAndLogEx(INFO, "AID %06X %s", aid, res == PM3_SUCCESS ? "exists" : "does not exist"); + PrintAndLogEx(INFO, "AID %06X %s", aid, + res == PM3_SUCCESS ? "exists" : "does not exist"); return res == PM3_SUCCESS; } @@ -228,7 +230,8 @@ static int hfgal_read_creds_app(DesfireContext_t *ctx, uint32_t aid, uint8_t *si GallagherCredentials_t *creds, bool verbose) { // Check that card UID has been set if (ctx->uidlen == 0) - HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext (required for key diversification)"); + HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext " + "(required for key diversification)"); // Select application & authenticate DesfireSetKeyNoClear(ctx, 2, T_AES, site_key); @@ -245,13 +248,15 @@ static int hfgal_read_creds_app(DesfireContext_t *ctx, uint32_t aid, uint8_t *si // Check file contained 16 bytes of data if (read_len != 16) - HFGAL_RET_ERR(PM3_EFAILED, "Failed reading file 0 in AID %06X, expected 16 bytes but received %d bytes", aid, read_len); + HFGAL_RET_ERR(PM3_EFAILED, "Failed reading file 0 in AID %06X, expected " + "16 bytes but received %d bytes", aid, read_len); // Check second half of file is the bitwise inverse of the first half for (uint8_t i = 8; i < 16; i++) buf[i] ^= 0xFF; if (memcmp(buf, &buf[8], 8) != 0) - HFGAL_RET_ERR(PM3_EFAILED, "Invalid cardholder data in file 0 in AID %06X. Received %s", sprint_hex_inrow(buf, 16)); + HFGAL_RET_ERR(PM3_EFAILED, "Invalid cardholder data in file 0 in " + "AID %06X. Received %s", sprint_hex_inrow(buf, 16)); gallagher_decode_creds(buf, creds); @@ -274,7 +279,8 @@ static int hfgal_create_creds_app(DesfireContext_t *ctx, uint8_t *site_key, uint // UID is required for key diversification if (ctx->uidlen == 0) - HFGAL_RET_ERR(PM3_EINVARG, "UID is required for key diversification. Please fetch it before calling `hfgal_create_creds_app`"); + HFGAL_RET_ERR(PM3_EINVARG, "UID is required for key diversification. " + "Please fetch it before calling `hfgal_create_creds_app`"); // Create application DesfireCryptoAlgorithm app_algo = T_AES; @@ -289,10 +295,12 @@ static int hfgal_create_creds_app(DesfireContext_t *ctx, uint8_t *site_key, uint DesfireSetCommMode(ctx, DCMMACed); res = DesfireCreateApplication(ctx, data, ARRAYLEN(data)); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating application %06X. Does it already exist?", aid); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating application %06X. " + "Does it already exist?", aid); if (verbose) - PrintAndLogEx(INFO, "Created application %06X (currently has empty contents & blank keys)", aid); + PrintAndLogEx(INFO, "Created application %06X (currently has empty " + "contents & blank keys)", aid); // Select the new application res = select_aid(ctx, aid, verbose); @@ -305,14 +313,16 @@ static int hfgal_create_creds_app(DesfireContext_t *ctx, uint8_t *site_key, uint res = hfgal_diversify_key(site_key, ctx->uid, ctx->uidlen, i, aid, buf); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key %d for AID %06X", i, aid); - PrintAndLogEx(INFO, "Diversified key %d for AID %06X: " _GREEN_("%s"), i, aid, sprint_hex_inrow(buf, ARRAYLEN(buf))); + PrintAndLogEx(INFO, "Diversified key %d for AID %06X: " _GREEN_("%s"), + i, aid, sprint_hex_inrow(buf, ARRAYLEN(buf))); // Authenticate uint8_t blank_key[CRYPTO_AES128_KEY_SIZE] = {0}; DesfireSetKeyNoClear(ctx, 0, T_AES, blank_key); DesfireSetKdf(ctx, MFDES_KDF_ALGO_NONE, NULL, 0); res = authenticate(ctx, verbose); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Desfire authenticate error. Result: [%d] %s", res, DesfireAuthErrorToStr(res)); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Desfire authenticate error. Result: " + "[%d] %s", res, DesfireAuthErrorToStr(res)); // Change key DesfireSetCommMode(ctx, DCMEncryptedPlain); @@ -374,16 +384,17 @@ static int hfgal_create_creds_file(DesfireContext_t *ctx, uint8_t *site_key, uin res = DesfireWriteFile(ctx, file_id, 0, ARRAYLEN(contents), contents); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file 0 in AID %06X"); - PrintAndLogEx(INFO, "Successfully wrote cardholder credentials to file 0 in AID %06X", aid); + PrintAndLogEx(INFO, "Successfully wrote cardholder credentials to " + "file 0 in AID %06X", aid); return PM3_SUCCESS; } /** - * @brief Read Gallagher Card Application Directory from card. + * @brief Read Gallagher Card Application Directory (CAD) from card. * * @param dest_buf Buffer to copy Card Application Directory into. * @param dest_buf_len Size of dest_buf. Must be at least 108 bytes. - * @param num_entries Will be set to the number of entries in the Card Application Directory. + * @param num_entries Will be set to the number of entries in the CAD. */ static int hfgal_read_cad(DesfireContext_t *ctx, uint8_t *dest_buf, uint8_t dest_buf_len, uint8_t *num_entries_out, bool verbose) { @@ -395,14 +406,16 @@ static int hfgal_read_cad(DesfireContext_t *ctx, uint8_t *dest_buf, // Get card AIDs from Card Application Directory (which contains 1 to 3 files) int res = select_aid(ctx, CAD_AID, verbose); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting Card Application Directory, does AID %06X exist?", CAD_AID); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed selecting Card Application " + "Directory, does AID %06X exist?", CAD_AID); // Read up to 3 files with 6x 6-byte entries each for (uint8_t i = 0; i < 3; i++) { size_t read_len; res = DesfireReadFile(ctx, i, 0, 36, &dest_buf[i * 36], &read_len); if (res != PM3_SUCCESS && res != PM3_EAPDU_FAIL) - HFGAL_RET_ERR(res, "Failed reading file %d in Card Application Directory (AID %06X)", i, CAD_AID); + HFGAL_RET_ERR(res, "Failed reading file %d in Card Application " + "Directory (AID %06X)", i, CAD_AID); // end if the last entry is NULL if (memcmp(&dest_buf[36 * i + 30], "\0\0\0\0\0\0", 6) == 0) break; @@ -438,7 +451,8 @@ static int hfgal_read_cad(DesfireContext_t *ctx, uint8_t *dest_buf, static int hfgal_create_cad(DesfireContext_t *ctx, uint8_t *site_key, bool verbose) { // Check that card UID has been set if (ctx->uidlen == 0) - HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext (required for key diversification)"); + HFGAL_RET_ERR(PM3_EINVARG, "Card UID must be set in DesfireContext " + "(required for key diversification)"); // Select application & authenticate int res = select_aid_and_authenticate(ctx, 0x000000, verbose); @@ -457,10 +471,12 @@ static int hfgal_create_cad(DesfireContext_t *ctx, uint8_t *site_key, bool verbo DesfireSetCommMode(ctx, DCMMACed); res = DesfireCreateApplication(ctx, data, ARRAYLEN(data)); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Card Application Directory. Does it already exist?", CAD_AID); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating Card Application Directory. " + "Does it already exist?", CAD_AID); if (verbose) - PrintAndLogEx(INFO, "Created Card Application Directory (AID %06X, currently has empty contents & blank keys)", CAD_AID); + PrintAndLogEx(INFO, "Created Card Application Directory (AID %06X, " + "currently has empty contents & blank keys)", CAD_AID); // Select application & authenticate uint8_t blank_key[DESFIRE_MAX_KEY_SIZE] = {0}; @@ -474,7 +490,8 @@ static int hfgal_create_cad(DesfireContext_t *ctx, uint8_t *site_key, bool verbo res = hfgal_diversify_key(site_key, ctx->uid, ctx->uidlen, 0, CAD_AID, buf); HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed diversifying key 0 for AID %06X", CAD_AID); - PrintAndLogEx(INFO, "Diversified key 0 for CAD (AID %06X): " _GREEN_("%s"), CAD_AID, sprint_hex_inrow(buf, ARRAYLEN(buf))); + PrintAndLogEx(INFO, "Diversified key 0 for CAD (AID %06X): " _GREEN_("%s"), + CAD_AID, sprint_hex_inrow(buf, ARRAYLEN(buf))); // Change key DesfireSetCommMode(ctx, DCMEncryptedPlain); @@ -484,7 +501,8 @@ static int hfgal_create_cad(DesfireContext_t *ctx, uint8_t *site_key, bool verbo if (verbose) PrintAndLogEx(INFO, "Successfully set key 0 for CAD"); - PrintAndLogEx(INFO, "Successfully created Card Application Directory (AID %06X)", CAD_AID); + PrintAndLogEx(INFO, "Successfully created Card Application Directory " + "(AID %06X)", CAD_AID); return PM3_SUCCESS; } @@ -537,7 +555,8 @@ static int hfgal_add_aid_to_cad(DesfireContext_t *ctx, uint8_t *site_key, uint32 cad_aid_uint_to_byte(aid, &entry[3]); if (verbose) - PrintAndLogEx(INFO, "Adding entry to CAD (position %d in file %d): %s", entry_num, file_id, sprint_hex_inrow(entry, 6)); + PrintAndLogEx(INFO, "Adding entry to CAD (position %d in file %d): %s", + entry_num, file_id, sprint_hex_inrow(entry, 6)); // Select application & authenticate DesfireSetKeyNoClear(ctx, 0, T_AES, site_key); @@ -565,19 +584,23 @@ static int hfgal_add_aid_to_cad(DesfireContext_t *ctx, uint8_t *site_key, uint32 // Create file res = DesfireCreateFile(ctx, file_type, data, ARRAYLEN(data), false); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file %d in CAD (AID %06X)", file_id, CAD_AID); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed creating file %d in CAD " + "(AID %06X)", file_id, CAD_AID); if (verbose) - PrintAndLogEx(INFO, "Created file %d in CAD (currently has empty contents)", file_id); + PrintAndLogEx(INFO, "Created file %d in CAD (currently has " + "empty contents)", file_id); // Write file res = DesfireWriteFile(ctx, file_id, 0, 36, &cad[file_id * 36]); } else // Write file res = DesfireWriteFile(ctx, file_id, entry_num * 6, 6, entry); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", file_id, CAD_AID); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD " + "(AID %06X)", file_id, CAD_AID); - PrintAndLogEx(INFO, "Successfully added new entry for %06X to the Card Application Directory", aid); + PrintAndLogEx(INFO, "Successfully added new entry for %06X to the Card " + "Application Directory", aid); return PM3_SUCCESS; } @@ -603,7 +626,8 @@ static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, break; } if (entry_idx >= num_entries) - HFGAL_RET_ERR(PM3_EINVARG, "Specified facility or AID does not exist in the Card Application Directory"); + HFGAL_RET_ERR(PM3_EINVARG, "Specified facility or AID does not exist " + "in the Card Application Directory"); // Remove entry (shift all entries left, then clear the last entry) memmove( @@ -627,7 +651,8 @@ static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, for (uint8_t file_id = file_id_start; file_id <= file_id_stop - delete_last_file; file_id++) { // Write file res = DesfireWriteFile(ctx, file_id, 0, 36, &cad[file_id * 36]); - HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD (AID %06X)", file_id, CAD_AID); + HFGAL_RET_IF_ERR_WITH_MSG(res, "Failed writing data to file %d in CAD " + "(AID %06X)", file_id, CAD_AID); if (verbose) PrintAndLogEx(INFO, "Updated file %d in CAD", file_id); @@ -652,7 +677,8 @@ static int hfgal_remove_aid_from_cad(DesfireContext_t *ctx, uint8_t *site_key, /** * @brief Read credentials from a Gallagher card. * - * @param aid Application ID to read. If 0, then the Card Application Directory will be queried and all entries will be read. + * @param aid Application ID to read. If 0, then the Card Application Directory + * will be queried and all entries will be read. * @param site_key MIFARE site key. * @param quiet Suppress error messages. Used when in continuous reader mode. */ @@ -687,7 +713,8 @@ static int hfgal_read_card(uint32_t aid, uint8_t *site_key, bool verbose, bool q if (verbose) { if (region_code > 0 || facility_code > 0) - PrintAndLogEx(INFO, "Reading AID: %06X, region: %u, facility: %u", current_aid, region_code, facility_code); + PrintAndLogEx(INFO, "Reading AID: %06X, region: %u, facility: %u", + current_aid, region_code, facility_code); else PrintAndLogEx(INFO, "Reading AID: %06X", current_aid); } @@ -708,7 +735,7 @@ static int hfgal_read_card(uint32_t aid, uint8_t *site_key, bool verbose, bool q static int CmdGallagherReader(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher reader", - "Read a GALLAGHER tag", + "Read a Gallagher DESFire tag", "hf gallagher reader --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff" " -> act as a reader that skips reading the Card Application Directory and uses a non-default site key\n" "hf gallagher reader -@ -> continuous reader mode" @@ -716,11 +743,12 @@ static int CmdGallagherReader(const char *cmd) { void *argtable[] = { arg_param_begin, - arg_str0(NULL, "aid", "", "Application ID to read (3 bytes)"), - arg_str0("k", "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), - arg_lit0(NULL, "apdu", "Show APDU requests and responses"), - arg_lit0("v", "verbose", "Verbose mode"), - arg_lit0("@", "continuous", "Continuous reader mode"), + arg_str0(NULL, "aid", "", "Application ID to read (3 bytes). If specified, then the Card Application Directory is not used"), + arg_str0(NULL, "sitekey", "", "MIFARE site key to compute diversified keys (16 bytes, required if using non-default key)"), + arg_lit0("@", "continuous", "Continuous reader mode"), + + arg_lit0(NULL, "apdu", "Show APDU requests and responses"), + arg_lit0("v", "verbose", "Verbose mode"), arg_param_end }; CLIExecWithReturn(ctx, cmd, argtable, true); @@ -741,9 +769,9 @@ static int CmdGallagherReader(const char *cmd) { if (site_key_len > 0 && site_key_len != 16) HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); - SetAPDULogging(arg_get_lit(ctx, 3)); - bool verbose = arg_get_lit(ctx, 4); - bool continuous_mode = arg_get_lit(ctx, 5); + bool continuous_mode = arg_get_lit(ctx, 3); + SetAPDULogging(arg_get_lit(ctx, 4)); + bool verbose = arg_get_lit(ctx, 5); CLIParserFree(ctx); if (!continuous_mode) @@ -760,53 +788,52 @@ static int CmdGallagherReader(const char *cmd) { static int CmdGallagherClone(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf gallagher clone", - "Clone a GALLAGHER card to a blank DESFire card", + "Clone Gallagher credentials to a writable DESFire card", "hf gallagher clone --rc 1 --fc 22 --cn 3333 --il 4 --sitekey 00112233445566778899aabbccddeeff" ); void *argtable[] = { arg_param_begin, - arg_lit0(NULL, "apdu", "show APDU requests and responses"), - arg_lit0("v", "verbose", "Verbose mode"), - arg_int0("n", "keyno", "", "Key number [default=0]"), + arg_int0("n", "keynum", "", "Key number [default=0]"), arg_str0("t", "algo", "", "Crypt algo: DES, 2TDEA, 3TDEA, AES"), - arg_str0("k", "key", "", "Key for authenticate (HEX 8(DES), 16(2TDEA or AES) or 24(3TDEA) bytes)"), + arg_str0("k", "key", "", "Key for authentication to the PICC (HEX 8(DES), 16(2TDEA or AES) or 24(3TDEA) bytes)"), arg_u64_1(NULL, "rc", "", "Region code. 4 bits max"), arg_u64_1(NULL, "fc", "", "Facility code. 2 bytes max"), arg_u64_1(NULL, "cn", "", "Card number. 3 bytes max"), arg_u64_1(NULL, "il", "", "Issue level. 4 bits max"), arg_str0(NULL, "aid", "", "Application ID to write (3 bytes) [default finds lowest available in range 0x2?81F4, where 0 <= ? <= 0xB]"), - arg_str0(NULL, "sitekey", "", "Master site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), + arg_str0(NULL, "sitekey", "", "MIFARE site key to compute diversified keys (16 bytes, required if using non-default key)"), + + arg_lit0(NULL, "apdu", "Show APDU requests and responses"), + arg_lit0("v", "verbose", "Verbose mode"), arg_param_end }; CLIExecWithReturn(ctx, cmd, argtable, false); - SetAPDULogging(arg_get_lit(ctx, 1)); - bool verbose = arg_get_lit(ctx, 2); - int key_num = arg_get_int_def(ctx, 3, 0); + int key_num = arg_get_int_def(ctx, 1, 0); int key_algo = T_DES; - if (CLIGetOptionList(arg_get_str(ctx, 4), DesfireAlgoOpts, &key_algo)) return PM3_ESOFT; + if (CLIGetOptionList(arg_get_str(ctx, 2), DesfireAlgoOpts, &key_algo)) return PM3_ESOFT; int key_len = 0; uint8_t key[DESFIRE_MAX_KEY_SIZE] = {0}; - CLIGetHexWithReturn(ctx, 5, key, &key_len); + CLIGetHexWithReturn(ctx, 3, key, &key_len); if (key_len && key_len != desfire_get_key_length(key_algo)) HFGAL_RET_ERR(PM3_EINVARG, "%s key must have %d bytes length instead of %d", CLIGetOptionListStr(DesfireAlgoOpts, key_algo), desfire_get_key_length(key_algo), key_len); if (key_len == 0) // Default to a key of all zeros key_len = desfire_get_key_length(key_algo); - uint64_t region_code = arg_get_u64(ctx, 6); // uint4, input will be validated later - uint64_t facility_code = arg_get_u64(ctx, 7); // uint16 - uint64_t card_number = arg_get_u64(ctx, 8); // uint24 - uint64_t issue_level = arg_get_u64(ctx, 9); // uint4 + uint64_t region_code = arg_get_u64(ctx, 4); // uint4, input will be validated later + uint64_t facility_code = arg_get_u64(ctx, 5); // uint16 + uint64_t card_number = arg_get_u64(ctx, 6); // uint24 + uint64_t issue_level = arg_get_u64(ctx, 7); // uint4 int aid_len = 0; uint8_t aid_buf[3] = {0}; uint32_t aid = 0; - CLIGetHexWithReturn(ctx, 10, aid_buf, &aid_len); + CLIGetHexWithReturn(ctx, 8, aid_buf, &aid_len); if (aid_len > 0) { if (aid_len != 3) HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); @@ -822,9 +849,12 @@ static int CmdGallagherClone(const char *cmd) { int site_key_len = 0; uint8_t site_key[16] = {0}; memcpy(site_key, DEFAULT_SITE_KEY, ARRAYLEN(site_key)); - CLIGetHexWithReturn(ctx, 11, site_key, &site_key_len); + CLIGetHexWithReturn(ctx, 9, site_key, &site_key_len); if (site_key_len > 0 && site_key_len != 16) HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); + + SetAPDULogging(arg_get_lit(ctx, 10)); + bool verbose = arg_get_lit(ctx, 11); CLIParserFree(ctx); if (!gallagher_is_valid_creds(region_code, facility_code, card_number, issue_level)) @@ -884,22 +914,19 @@ static int CmdGallagherDelete(const char *cmd) { void *argtable[] = { arg_param_begin, - arg_lit0(NULL, "apdu", "Show APDU requests and responses"), - arg_lit0("v", "verbose", "Verbose mode"), + arg_str1(NULL, "aid", "", "Application ID to delete (3 bytes)"), + arg_str0(NULL, "sitekey", "", "MIFARE site key to compute diversified keys (16 bytes, required if using non-default key)"), - arg_str1(NULL, "aid", "", "Application ID to delete (3 bytes)"), - arg_str0(NULL, "sitekey", "", "MIFARE site key to compute diversified keys (16 bytes) [default=3112B738D8862CCD34302EB299AAB456]"), + arg_lit0(NULL, "apdu", "Show APDU requests and responses"), + arg_lit0("v", "verbose", "Verbose mode"), arg_param_end }; CLIExecWithReturn(ctx, cmd, argtable, false); - SetAPDULogging(arg_get_lit(ctx, 1)); - bool verbose = arg_get_lit(ctx, 2); - int aid_len = 0; uint8_t aid_buf[3] = {0}; uint32_t aid = 0; - CLIGetHexWithReturn(ctx, 3, aid_buf, &aid_len); + CLIGetHexWithReturn(ctx, 1, aid_buf, &aid_len); if (aid_len != 3) HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); @@ -914,9 +941,12 @@ static int CmdGallagherDelete(const char *cmd) { int site_key_len = 0; uint8_t site_key[16] = {0}; memcpy(site_key, DEFAULT_SITE_KEY, ARRAYLEN(site_key)); - CLIGetHexWithReturn(ctx, 4, site_key, &site_key_len); + CLIGetHexWithReturn(ctx, 2, site_key, &site_key_len); if (site_key_len > 0 && site_key_len != 16) HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); + + SetAPDULogging(arg_get_lit(ctx, 3)); + bool verbose = arg_get_lit(ctx, 4); CLIParserFree(ctx); // Set up context @@ -950,22 +980,20 @@ static int CmdGallagherDiversify(const char *cmd) { void *argtable[] = { arg_param_begin, - arg_lit0(NULL, "apdu", "Show APDU requests and responses"), - arg_str1(NULL, "aid", "", "Application ID for diversification (3 bytes)"), arg_int0(NULL, "keynum", "", "Key number [default=0]"), arg_str0(NULL, "uid", "", "Card UID to delete (4 or 7 bytes)"), arg_str0(NULL, "sitekey", "", "MIFARE site key to compute diversified keys (16 bytes, required if using non-default key)"), + + arg_lit0(NULL, "apdu", "Show APDU requests and responses"), arg_param_end }; CLIExecWithReturn(ctx, cmd, argtable, false); - SetAPDULogging(arg_get_lit(ctx, 1)); - int aid_len = 0; uint8_t aid_buf[3] = {0}; uint32_t aid = 0; - CLIGetHexWithReturn(ctx, 2, aid_buf, &aid_len); + CLIGetHexWithReturn(ctx, 1, aid_buf, &aid_len); if (aid_len != 3) HFGAL_RET_ERR(PM3_EINVARG, "--aid must be 3 bytes"); @@ -977,20 +1005,22 @@ static int CmdGallagherDiversify(const char *cmd) { // TODO: this should probably be a warning, but key diversification will throw an error later even if we don't HFGAL_RET_ERR(PM3_EINVARG, "Invalid Gallagher AID %06X, expected 2?81F4, where 0 <= ? <= 0xB", aid); - int key_num = arg_get_int_def(ctx, 3, 0); + int key_num = arg_get_int_def(ctx, 2, 0); int uid_len = 0; uint8_t uid[7] = {0}; - CLIGetHexWithReturn(ctx, 4, uid, &uid_len); + CLIGetHexWithReturn(ctx, 3, uid, &uid_len); if (uid_len > 0 && uid_len != 4 && uid_len != 7) HFGAL_RET_ERR(PM3_EINVARG, "--uid must be 4 or 7 bytes"); int site_key_len = 0; uint8_t site_key[16] = {0}; memcpy(site_key, DEFAULT_SITE_KEY, ARRAYLEN(site_key)); - CLIGetHexWithReturn(ctx, 5, site_key, &site_key_len); + CLIGetHexWithReturn(ctx, 4, site_key, &site_key_len); if (site_key_len > 0 && site_key_len != 16) HFGAL_RET_ERR(PM3_EINVARG, "--sitekey must be 16 bytes"); + + SetAPDULogging(arg_get_lit(ctx, 5)); CLIParserFree(ctx); if (uid_len == 0) { @@ -1016,8 +1046,9 @@ static int CmdGallagherDiversify(const char *cmd) { PrintAndLogEx(SUCCESS, "Successfully diversified key: " _GREEN_("%s"), key_str); if (IfPm3Iso14443()) - PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfdes auth --aid %06X --keyno %d " - "--algo AES --key %s`") " to verify", aid, key_num, key_str); + PrintAndLogEx(HINT, "Hint: try " + _YELLOW_("`hf mfdes auth --aid %06X --keyno %d --algo AES --key %s`") + " to verify", aid, key_num, key_str); return PM3_SUCCESS; } @@ -1025,7 +1056,7 @@ static int CmdHelp(const char *cmd); static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"reader", CmdGallagherReader, IfPm3Iso14443, "Read & decode all Gallagher credentials on the DESFire card"}, + {"reader", CmdGallagherReader, IfPm3Iso14443, "Read & decode all Gallagher credentials on a DESFire card"}, {"clone", CmdGallagherClone, IfPm3Iso14443, "Add Gallagher credentials to a DESFire card"}, {"delete", CmdGallagherDelete, IfPm3Iso14443, "Delete Gallagher credentials from a DESFire card"}, {"diversifykey", CmdGallagherDiversify, AlwaysAvailable, "Diversify Gallagher key"}, diff --git a/doc/commands.json b/doc/commands.json index b0b01bf45..980d42544 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -2322,26 +2322,26 @@ }, "hf gallagher clone": { "command": "hf gallagher clone", - "description": "clone a gallagher card to a blank desfire card", + "description": "clone gallagher credentials to a writable desfire card", "notes": [ "hf gallagher clone --rc 1 --fc 22 --cn 3333 --il 4 --sitekey 00112233445566778899aabbccddeeff" ], "offline": false, "options": [ "-h, --help this help", - "--apdu show apdu requests and responses", - "-v, --verbose verbose mode", - "-n, --keyno key number [default=0]", + "-n, --keynum key number [default=0]", "-t, --algo crypt algo: des, 2tdea, 3tdea, aes", - "-k, --key key for authenticate (hex 8(des), 16(2tdea or aes) or 24(3tdea) bytes)", + "-k, --key key for authentication to the picc (hex 8(des), 16(2tdea or aes) or 24(3tdea) bytes)", "--rc region code. 4 bits max", "--fc facility code. 2 bytes max", "--cn card number. 3 bytes max", "--il issue level. 4 bits max", "--aid application id to write (3 bytes) [default finds lowest available in range 0x2?81f4, where 0 <= ? <= 0xb]", - "--sitekey master site key to compute diversified keys (16 bytes) [default=3112b738d8862ccd34302eb299aab456]" + "--sitekey mifare site key to compute diversified keys (16 bytes, required if using non-default key)", + "--apdu show apdu requests and responses", + "-v, --verbose verbose mode" ], - "usage": "hf gallagher clone [-hv] [--apdu] [-n ] [-t ] [-k ] --rc --fc --cn --il [--aid ] [--sitekey ]" + "usage": "hf gallagher clone [-hv] [-n ] [-t ] [-k ] --rc --fc --cn --il [--aid ] [--sitekey ] [--apdu]" }, "hf gallagher delete": { "command": "hf gallagher delete", @@ -2352,33 +2352,33 @@ "offline": false, "options": [ "-h, --help this help", - "--apdu show apdu requests and responses", - "-v, --verbose verbose mode", "--aid application id to delete (3 bytes)", - "--sitekey mifare site key to compute diversified keys (16 bytes) [default=3112b738d8862ccd34302eb299aab456]" + "--sitekey mifare site key to compute diversified keys (16 bytes, required if using non-default key)", + "--apdu show apdu requests and responses", + "-v, --verbose verbose mode" ], - "usage": "hf gallagher delete [-hv] [--apdu] --aid [--sitekey ]" + "usage": "hf gallagher delete [-hv] --aid [--sitekey ] [--apdu]" }, "hf gallagher diversifykey": { "command": "hf gallagher diversifykey", "description": "diversify gallagher key", "notes": [ - "hf gallagher diversify --uid 11223344556677 --aid 2081f4 -> diversify" + "hf gallagher diversify --uid 11223344556677 --aid 2081f4" ], "offline": true, "options": [ "-h, --help this help", - "--apdu show apdu requests and responses", "--aid application id for diversification (3 bytes)", "--keynum key number [default=0]", "--uid card uid to delete (4 or 7 bytes)", - "--sitekey mifare site key to compute diversified keys (16 bytes, required if using non-default key)" + "--sitekey mifare site key to compute diversified keys (16 bytes, required if using non-default key)", + "--apdu show apdu requests and responses" ], - "usage": "hf gallagher diversify [-h] [--apdu] --aid [--keynum ] [--uid ] [--sitekey ]" + "usage": "hf gallagher diversify [-h] --aid [--keynum ] [--uid ] [--sitekey ] [--apdu]" }, "hf gallagher help": { "command": "hf gallagher help", - "description": "help this help diversifykey diversify gallagher key --------------------------------------------------------------------------------------- hf gallagher reader available offline: no read a gallagher tag", + "description": "help this help diversifykey diversify gallagher key --------------------------------------------------------------------------------------- hf gallagher reader available offline: no read a gallagher desfire tag", "notes": [ "hf gallagher reader --aid 2081f4 --sitekey 00112233445566778899aabbccddeeff -> act as a reader that skips reading the card application directory and uses a non-default site key", "hf gallagher reader -@ -> continuous reader mode" @@ -2386,13 +2386,13 @@ "offline": true, "options": [ "-h, --help this help", - "--aid application id to read (3 bytes)", - "-k, --sitekey master site key to compute diversified keys (16 bytes) [default=3112b738d8862ccd34302eb299aab456]", + "--aid application id to read (3 bytes). if specified, then the card application directory is not used", + "--sitekey mifare site key to compute diversified keys (16 bytes, required if using non-default key)", + "-@, --continuous continuous reader mode", "--apdu show apdu requests and responses", - "-v, --verbose verbose mode", - "-@, --continuous continuous reader mode" + "-v, --verbose verbose mode" ], - "usage": "hf gallagher reader [-hv@] [--aid ] [-k ] [--apdu]" + "usage": "hf gallagher reader [-h@v] [--aid ] [--sitekey ] [--apdu]" }, "hf help": { "command": "hf help", @@ -6036,8 +6036,8 @@ "command": "hw connect", "description": "connects to a proxmark3 device via specified serial port. baudrate here is only for physical uart or uart-bt, not for usb-cdc or blue shark add-on", "notes": [ - "hw connect -p /dev/ttyacm0", - "hw connect -p /dev/ttyacm0 -b 115200" + "hw connect -p com3", + "hw connect -p com3 -b 115200" ], "offline": true, "options": [ @@ -10236,6 +10236,6 @@ "metadata": { "commands_extracted": 601, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2022-01-06T11:03:41" + "extracted_on": "2022-01-06T12:03:19" } } \ No newline at end of file diff --git a/doc/commands.md b/doc/commands.md index 735be384a..7bf7ce494 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -324,7 +324,7 @@ Check column "offline" for their availability. |command |offline |description |------- |------- |----------- |`hf gallagher help `|Y |`This help` -|`hf gallagher reader `|N |`Read & decode all Gallagher credentials on the DESFire card` +|`hf gallagher reader `|N |`Read & decode all Gallagher credentials on a DESFire card` |`hf gallagher clone `|N |`Add Gallagher credentials to a DESFire card` |`hf gallagher delete `|N |`Delete Gallagher credentials from a DESFire card` |`hf gallagher diversifykey`|Y |`Diversify Gallagher key` From 14b6580fcb0aed2c287fd7cc72d6a8dd732e937e Mon Sep 17 00:00:00 2001 From: Matt Moran Date: Fri, 7 Jan 2022 01:08:55 +1300 Subject: [PATCH 26/26] Squashed commit of the following: commit 8f77179a2fdf4856120ada4357dd1c5e737e6774 Author: Philippe Teuwen Date: Thu Jan 6 11:25:38 2022 +0100 remove unused file commit bcafc5d03c18373e5bbd7d3687a8535e46f02aed Author: Philippe Teuwen Date: Thu Jan 6 11:24:04 2022 +0100 some historical copyright adjustments, thanks @iceman1001! commit b703bb746b13dfffd87b8b153e83e8190f82e254 Author: Philippe Teuwen Date: Thu Jan 6 02:19:46 2022 +0100 Adapting license headers, WIP commit 8952a1f71248f39396703e809c2a5b32fc79ad0f Author: Philippe Teuwen Date: Thu Jan 6 00:37:34 2022 +0100 adapt contributing text commit cdfb83075fa5e98b83cb16de815fca3e9792b221 Author: Philippe Teuwen Date: Thu Jan 6 00:24:15 2022 +0100 toc commit 014817f854db443725144c74c40f6df77b65c2c3 Author: Philippe Teuwen Date: Thu Jan 6 00:15:40 2022 +0100 Adding AUTHORS and changing licensing terms from 'GPLv2 or later' to 'GPLv3 or later' to comply with components available only under 'GPLv3 or later'. Details: Initial releases by Jonathan Westhues in 2005-2007 were made under GPL "either version 2 of the License, or (at your option) any later version" Since then, a number of dependencies and files were integrated to the project, but under a "GPLv3 or later" license. These components are reveng, desfire_crypto and lrpcrypto. Note that compnents cryptorf, hitag2crack and fpga-xc3s100e are also under GPLv3+ but not bound to the firmware or client source code. Therefore, we must mechanically upgrade the license of the whole project to GPLv3+, as made possible by the initial licensing terms and as mandated by the inclusion of GPLv3+ code. Still to do: update each source file header: Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . commit 5561466fe8b3a649d8a5567b1f2ddf51a3aab7a2 Author: Philippe Teuwen Date: Wed Jan 5 18:56:56 2022 +0100 make style commit 2d1a1dc03489aef4f03d0be5b789680f40921bc3 Author: Philippe Teuwen Date: Wed Jan 5 17:57:49 2022 +0100 make style doc/commands.json commit fc53665e5cf97d101418bc94e6599ab7a5567cc6 Merge: a6d22ee43 c0cc09d86 Author: Philippe Teuwen Date: Wed Jan 5 17:52:44 2022 +0100 Merge pull request #1552 from joswr1ght/master Add --no-auth support for hf mfdes createapp commit c0cc09d86bff0d19f854455133a689924e84f7ce Author: Joshua Wright Date: Wed Jan 5 07:12:20 2022 -0500 Style consistency changes for hf mfdes createapp feature addition commit f9c96f49da751b769a55ecb8077779239bc098ac Author: Joshua Wright Date: Tue Jan 4 17:01:10 2022 -0500 Update CHANGELOG with MIFARE DESFire createapp --no-auth change commit 859b55933d8a8c957f3b30e9c897866fa4e70570 Author: Joshua Wright Date: Tue Jan 4 15:55:26 2022 -0500 Add --no-auth support for hf mfdes createapp --- AUTHORS.md | 17 + CHANGELOG.md | 19 +- CONTRIBUTING.md | 21 +- LICENSE.txt | 845 +++++++++++++++------ README.md | 21 + armsrc/BigBuf.c | 17 +- armsrc/BigBuf.h | 17 +- armsrc/LCD_disabled.c | 16 +- armsrc/LCD_disabled.h | 16 +- armsrc/Makefile | 18 +- armsrc/Standalone/Makefile.hal | 15 + armsrc/Standalone/Makefile.inc | 16 + armsrc/Standalone/dankarmulti.c | 17 +- armsrc/Standalone/dankarmulti.h | 18 + armsrc/Standalone/hf_14asniff.c | 17 +- armsrc/Standalone/hf_aveful.c | 17 +- armsrc/Standalone/hf_bog.c | 17 +- armsrc/Standalone/hf_colin.c | 18 +- armsrc/Standalone/hf_colin.h | 20 +- armsrc/Standalone/hf_craftbyte.c | 22 +- armsrc/Standalone/hf_iceclass.c | 17 +- armsrc/Standalone/hf_legic.c | 18 +- armsrc/Standalone/hf_mattyrun.c | 18 +- armsrc/Standalone/hf_mfcsim.c | 17 +- armsrc/Standalone/hf_msdsal.c | 17 +- armsrc/Standalone/hf_reblay.c | 17 +- armsrc/Standalone/hf_tcprst.c | 17 +- armsrc/Standalone/hf_tmudford.c | 22 +- armsrc/Standalone/hf_young.c | 18 +- armsrc/Standalone/lf_em4100emul.c | 17 +- armsrc/Standalone/lf_em4100rswb.c | 18 +- armsrc/Standalone/lf_em4100rwc.c | 17 +- armsrc/Standalone/lf_hidbrute.c | 21 +- armsrc/Standalone/lf_hidbrute.h | 37 +- armsrc/Standalone/lf_hidfcbrute.c | 17 +- armsrc/Standalone/lf_hidfcbrute.h | 16 + armsrc/Standalone/lf_icehid.c | 17 +- armsrc/Standalone/lf_nexid.c | 17 +- armsrc/Standalone/lf_proxbrute.c | 19 +- armsrc/Standalone/lf_samyrun.c | 18 +- armsrc/Standalone/lf_skeleton.c | 16 +- armsrc/Standalone/lf_tharexde.c | 17 +- armsrc/Standalone/placeholder.c | 15 + armsrc/Standalone/standalone.h | 16 +- armsrc/appmain.c | 19 +- armsrc/appmain.h | 19 +- armsrc/buzzer_disabled.c | 16 + armsrc/buzzer_disabled.h | 19 +- armsrc/cmd.c | 46 +- armsrc/cmd.h | 46 +- armsrc/dbprint.c | 21 +- armsrc/dbprint.h | 22 +- armsrc/desfire_crypto.c | 36 +- armsrc/desfire_crypto.h | 18 + armsrc/em4x50.c | 16 +- armsrc/em4x50.h | 16 +- armsrc/em4x70.c | 18 +- armsrc/em4x70.h | 16 +- armsrc/emvtags.h | 16 +- armsrc/epa.c | 16 +- armsrc/epa.h | 16 +- armsrc/felica.c | 15 + armsrc/felica.h | 17 +- armsrc/flashmem.c | 17 + armsrc/flashmem.h | 40 +- armsrc/fonts_disabled.c | 16 +- armsrc/fonts_disabled.h | 16 +- armsrc/fpgaloader.c | 18 +- armsrc/fpgaloader.h | 18 +- armsrc/frozen.c | 35 +- armsrc/frozen.h | 35 +- armsrc/hfsnoop.c | 16 +- armsrc/hfsnoop.h | 20 +- armsrc/hitag2.c | 28 +- armsrc/hitag2.h | 17 +- armsrc/hitag2_crypto.c | 20 +- armsrc/hitag2_crypto.h | 15 + armsrc/hitag2crack.c | 20 +- armsrc/hitag2crack.h | 19 +- armsrc/hitagS.c | 24 +- armsrc/hitagS.h | 21 +- armsrc/i2c.c | 17 +- armsrc/i2c.h | 15 + armsrc/iclass.c | 30 +- armsrc/iclass.h | 22 +- armsrc/iso14443a.c | 20 +- armsrc/iso14443a.h | 20 +- armsrc/iso14443b.c | 19 +- armsrc/iso14443b.h | 20 +- armsrc/iso15693.c | 22 +- armsrc/iso15693.h | 19 +- armsrc/legicrf.c | 18 +- armsrc/legicrf.h | 18 +- armsrc/legicrfsim.c | 18 +- armsrc/legicrfsim.h | 20 +- armsrc/lfadc.c | 16 +- armsrc/lfadc.h | 16 +- armsrc/lfops.c | 17 +- armsrc/lfops.h | 20 +- armsrc/lfsampling.c | 16 +- armsrc/lfsampling.h | 15 + armsrc/lfzx.c | 16 +- armsrc/lfzx.h | 16 +- armsrc/mifarecmd.c | 24 +- armsrc/mifarecmd.h | 20 +- armsrc/mifaredesfire.c | 15 + armsrc/mifaredesfire.h | 19 +- armsrc/mifaresim.c | 21 +- armsrc/mifaresim.h | 19 +- armsrc/mifaresniff_disabled.c | 17 +- armsrc/mifaresniff_disabled.h | 17 +- armsrc/mifareutil.c | 19 +- armsrc/mifareutil.h | 18 +- armsrc/nprintf.c | 48 +- armsrc/nprintf.h | 49 +- armsrc/optimized_cipher.c | 74 +- armsrc/optimized_cipher.h | 33 + armsrc/optimized_cipherutils.c | 69 +- armsrc/optimized_cipherutils.h | 69 +- armsrc/optimized_elite.c | 70 +- armsrc/optimized_elite.h | 71 +- armsrc/optimized_ikeys.c | 69 +- armsrc/optimized_ikeys.h | 70 +- armsrc/pcf7931.c | 15 + armsrc/pcf7931.h | 15 + armsrc/printf.c | 58 +- armsrc/printf.h | 24 +- armsrc/radixsort.c | 99 --- armsrc/radixsort.h | 22 - armsrc/spiffs.c | 20 +- armsrc/spiffs.h | 23 +- armsrc/spiffs_cache.c | 23 +- armsrc/spiffs_check.c | 23 +- armsrc/spiffs_config.h | 23 +- armsrc/spiffs_gc.c | 17 + armsrc/spiffs_hydrogen.c | 23 +- armsrc/spiffs_nucleus.c | 17 + armsrc/spiffs_nucleus.h | 23 +- armsrc/start.c | 17 +- armsrc/string.c | 16 +- armsrc/string.h | 17 +- armsrc/thinfilm.c | 16 +- armsrc/thinfilm.h | 16 +- armsrc/ticks.c | 18 +- armsrc/ticks.h | 18 +- armsrc/usart.c | 17 +- armsrc/usart.h | 15 + armsrc/util.c | 17 +- armsrc/util.h | 17 +- armsrc/vtsend.c | 50 +- armsrc/vtsend.h | 50 +- armsrc/wiegand.c | 18 +- armsrc/wiegand.h | 16 +- bootrom/Makefile | 17 +- bootrom/bootrom.c | 17 +- bootrom/flash-reset.s | 17 +- bootrom/ldscript-flash | 17 +- bootrom/ram-reset.s | 17 +- client/src/cmdhficlass.c | 70 +- client/src/cmdhfmfdes.c | 4 +- client/src/cmdlfkeri.c | 8 +- doc/commands.json | 5 +- fpga-xc3s100e/LICENSE | 674 ---------------- include/iclass_cmd.h | 6 +- tools/hitag2crack/crack5opencl/LICENSE.txt | 674 ---------------- 165 files changed, 3023 insertions(+), 2893 deletions(-) create mode 100644 AUTHORS.md delete mode 100644 armsrc/radixsort.c delete mode 100644 armsrc/radixsort.h delete mode 100644 fpga-xc3s100e/LICENSE delete mode 100644 tools/hitag2crack/crack5opencl/LICENSE.txt diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 000000000..7fde2b668 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,17 @@ +Initial author of the Proxmark3 code is Jonathan Westhues, starting in August 2005. +His latest release was done in May 2007 and is available [here](https://cq.cx/dl/proxmark3-may23-2007.zip) (copy available [here](http://proxmark.org/files/J.Westhues/)). + +Initial copyright notice is therefore: +Copyright (C) 2005-2007 Jonathan Westhues + +Since then, each contribution is under the copyright of its respective author. + +A few releases were done by the Proxmark community between 2007 and March 2009 before using version control. +The last release which served as basis for version control, under SVN then migrated to Git, was the `20090306_ela` release by Edouard Lafargue. See the first commit of this repository. + +Therefore, only the following copyright notices are left untouched in the corresponding files: +- copyright notices present in the `20090306_ela` release +- copyright notices of code borrowed from other projects +- copyright notices of standalone modes initial authors + +Since then, copyright of each contribution is tracked by the Git history. See the output of `git shortlog -nse` for a full list. See also [the Contributors page on Github](https://github.com/RfidResearchGroup/proxmark3/graphs/contributors). diff --git a/CHANGELOG.md b/CHANGELOG.md index eebf307e2..6b6622413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Added support for MIFARE DESFire application creation without authentication (@joswr1ght) - Changed drastically Hitag S ARM code to remove state machines and ease way to build new commands (@doegox) - Fixed Hitag S crypto mode with key or NrAr, fixed `lf hitag cc`, fixed pwd dump in hitagS dump with LKP (@doegox) - Changed `trace list -h` - textual change (@iceman1001) @@ -93,7 +94,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Fixed `hf_msdsal` standalone in simulation flow (@salmg) - Added a picture viewer in QT. To be used with `hf emrtd info` (@iceman1001) - Fixed - move des functions to libcrypto (@merlokk) - - Added `CLIGetOptionList` to cliparser that makes it easier to implement text options in the cli (@merlokk) + - Added `CLIGetOptionList` to cliparser that makes it easier to implement text options in the cli (@merlokk) - Added experimental support for macOS users utilizing MacPorts instead of Homebrew (@linuxgemini) - Added `pm3_online_check.py` - a script to verify and initialize a Proxmark3 RDV4 device (@iceman1001) @@ -113,9 +114,9 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Added more keys (@equipter) - Changed `hf nfc ndefread` - ndef parser now handles more types (@iceman1001) - Fixed `hf desfire` changekey, GetUID, 3DES session key tweak. (@mwalker33) - - Fixed `hf fido` commands now works correctly (@merlokk) + - Fixed `hf fido` commands now works correctly (@merlokk) - Moved / renamed `client/resource/fido2_defparams.json` -> `client/resource/hf_fido2_defparams.json` (@merlokk) - - Added `hf cipurse` commands to work with cipurse transport cards (@merlokk) + - Added `hf cipurse` commands to work with cipurse transport cards (@merlokk) - Added `--gap` option to lf em 410x sim for more control over sim data (@mwalker) - Changed `hf fido` - refactored load/save json objects (@iceman1001) - Moved / renamed `fido2.json` -> `client/resource/fido2_defparams.json` (@iceman1001) @@ -145,8 +146,8 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Changed `lf pac demod` - now also search for inverted bitstreams (@iceman1001) - Changed `hf 14b reader` - now supports continuous mode (@iceman1001) - Fixed `hf search` - now doesn't false identify ISO15693 (@iceman1001) - - Changed emv commands now works with tokenized cards (@merlokk) - - Changed `hf 15 restore` - now also support EML/JSON (@iceman1001) + - Changed emv commands now works with tokenized cards (@merlokk) + - Changed `hf 15 restore` - now also support EML/JSON (@iceman1001) - Changed - all commands now use cliparser (@iceman1001) - Changed `lf t55xx restore` - now also support JSON (@iceman1001) - Changed `hf mf csetuid` - adapted to accept 7byte uids ~untested~ (@iceman1001) @@ -233,7 +234,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Added `hf emrtd` ePassport dumping and parsing (@aveao) - Added `aidsearch` to `hf 14b info` (@iceman1001) - Added `ICE_STATE_DUMP_SIM` - standalone mode for dumping/simming one iClass tag (@iconicsec) - - Added `lf em 4x50 eview` - show uploaded EM4x50 data in emul memory (@tharexde) + - Added `lf em 4x50 eview` - show uploaded EM4x50 data in emul memory (@tharexde) - Fixed `data rawdemod` parsing for psk2 and user defined clock (@cyberpunk-re) - Added `hf iclass encode` - encode a wiegand binary to a encrypted credential (@iceman1001) - Changed `recoverpk.py` - now tests more ECDSA curves (@doegox) @@ -320,7 +321,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Added `lf em 4x50_info` (@tharexde) - Added `4x50_write` (@tharexde) - Added `4x50_write_password` (@tharexde) - - Fixed em4x50 demodulation error (@tharexde) + - Fixed em4x50 demodulation error (@tharexde) - Fixed `hf mfdes` authentication issues, DES working (@bkerler) - Added Android cross-compilation to client cmake (@dxl, @doegox) - Fixed `emv scan` - now saves in current folder and uses unique names (@iceman1001) @@ -450,7 +451,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Changed enforce PACKED structs [compiler trials] (@iceman1001) - Changed adjust number of threads according to cpu (@iceman1001) - Changed `hitag2crack` compile flags(@doegox) - - Changed msdsal fix bug after var de-shadowing (@doegox) + - Changed msdsal fix bug after var de-shadowing (@doegox) - Changed lighter msg for loading prefs, json will anyway always tell the filename (@doegox) - Changed make sure colors and emoji are disabled when not on TTY (@doegox) - Added `pref` command. PM3 client now support user preferences saved to a json file. (@mwalker33) @@ -1108,7 +1109,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Updated the Reveng 1.30 sourcecode to 1.31 from Reveng project homepage (@iceman1001) - Updated the Reveng 1.31 sourcecode to 1.40 from Reveng project homepage (@iceman1001) - Added possibility to write direct to a Legic Prime Tag (MIM256/1024) without using values from the `BigBuffer` -> `hf legic writeRaw ` (@icsom) - - Added possibility to decrease DCF values at address 0x05 & 0x06 on a Legic Prime Tag + - Added possibility to decrease DCF values at address 0x05 & 0x06 on a Legic Prime Tag DCF-value will be pulled from the BigBuffer (address 0x05 & 0x06) so you have to load the data into the BigBuffer before with `hf legic load ` & then write the DCF-Values (both at once) with `hf legic write 0x05 0x02` (@icsom) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d80477cee..2941753d6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -266,17 +266,26 @@ For these reasons, vague and general filenames (e.g. `util.*`, `global.*`, `misc License/description header first: ```c //----------------------------------------------------------------------------- -// YOUR COPYRIGHT LINE GOES HERE +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // FILE DESCRIPTION GOES HERE //----------------------------------------------------------------------------- ``` -If you modify a file in any non-trivial way (add code, etc.), add your copyright -to the top with the current year. + +To avoid a huge mess of copyright notices in the source files, it has been chosen to keep this generic notice. Don't worry, you still hold the copyright on your respective contributions and date and authorship are tracked by the Git history, as explained in [AUTHORS](AUTHORS.md). +In January 2022, the Git history has recorded 293 different authors. ## Header files diff --git a/LICENSE.txt b/LICENSE.txt index 7f48bec21..94a9ed024 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,281 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + TERMS AND CONDITIONS - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". + 0. Definitions. -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. + "This License" refers to version 3 of the GNU General Public License. - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. + A "covered work" means either the unmodified Program or a work based +on the Program. - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. + 1. Source Code. -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. + The Corresponding Source for a work in source code form is that +same work. -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. + 2. Basic Permissions. - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of this License. - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. + 13. Use with the GNU Affero General Public License. -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. + 14. Revised Versions of this License. - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. - NO WARRANTY + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. + 15. Disclaimer of Warranty. - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - END OF TERMS AND CONDITIONS + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md index 5decd8b24..45ee9d99b 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ 9. [Official channels](#official-channels) 10. [Maintainers](#maintainers) 11. [Citation](#citation) +12. [Copyright and licensing terms](#copyright-and-licensing-terms) # PROXMARK3 INSTALLATION AND OVERVIEW @@ -216,3 +217,23 @@ If you need to refer to a specific state of the repository, use a commit number note = {Accessed: commit 12327f71a27da23831901847886aaf20e8ad3ca0} note = {Accessed: 2021-01-01} ``` + +## Copyright and licensing terms + +Each contribution is under the copyright of its author. See [AUTHORS](AUTHORS.md). + +The Proxmark3 source code is covered by the following licensing terms, usually referred as **GPLv3 or later**. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +A copy of the GPLv3 is available in [LICENSE](LICENSE.txt). + +Some dependencies may be under other free licensing terms compatible with the Proxmark3 licensing terms, see their respective description. diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index 126e6baf1..9c27bd4d8 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -1,10 +1,17 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // BigBuf and functions to allocate/free parts of it. //----------------------------------------------------------------------------- diff --git a/armsrc/BigBuf.h b/armsrc/BigBuf.h index 435aeb80d..dd1f727d7 100644 --- a/armsrc/BigBuf.h +++ b/armsrc/BigBuf.h @@ -1,10 +1,17 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // BigBuf and functions to allocate/free parts of it. //----------------------------------------------------------------------------- diff --git a/armsrc/LCD_disabled.c b/armsrc/LCD_disabled.c index 97bf6da71..1a4b253e2 100644 --- a/armsrc/LCD_disabled.c +++ b/armsrc/LCD_disabled.c @@ -1,7 +1,17 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LCD code //----------------------------------------------------------------------------- diff --git a/armsrc/LCD_disabled.h b/armsrc/LCD_disabled.h index ed765298f..e2f57e02c 100644 --- a/armsrc/LCD_disabled.h +++ b/armsrc/LCD_disabled.h @@ -1,7 +1,17 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LCD code //----------------------------------------------------------------------------- diff --git a/armsrc/Makefile b/armsrc/Makefile index 71555e15b..a797cddb9 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -1,6 +1,18 @@ -# This code is licensed to you under the terms of the GNU GPL, version 2 or, -# at your option, any later version. See the LICENSE.txt file for the text of -# the license. +#----------------------------------------------------------------------------- +# Copyright (C) Jonathan Westhues, Mar 2006 +# Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See LICENSE.txt for the text of the license. #----------------------------------------------------------------------------- # Makefile for armsrc, see ../common_arm/Makefile.common for common settings #----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/Makefile.hal b/armsrc/Standalone/Makefile.hal index e3076a76f..f8277da97 100644 --- a/armsrc/Standalone/Makefile.hal +++ b/armsrc/Standalone/Makefile.hal @@ -1,3 +1,18 @@ +#----------------------------------------------------------------------------- +# Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See LICENSE.txt for the text of the license. +#----------------------------------------------------------------------------- # Default standalone if no standalone specified DEFAULT_STANDALONE=LF_SAMYRUN HELP_EXAMPLE_STANDALONE=LF_SAMYRUN diff --git a/armsrc/Standalone/Makefile.inc b/armsrc/Standalone/Makefile.inc index 8b923586a..021d219f4 100644 --- a/armsrc/Standalone/Makefile.inc +++ b/armsrc/Standalone/Makefile.inc @@ -1,4 +1,20 @@ +#----------------------------------------------------------------------------- +# Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See LICENSE.txt for the text of the license. +#----------------------------------------------------------------------------- # Generic standalone Mode injection of source code +#----------------------------------------------------------------------------- SRC_STANDALONE = placeholder.c # WITH_STANDALONE_LF_SKELETON diff --git a/armsrc/Standalone/dankarmulti.c b/armsrc/Standalone/dankarmulti.c index b83c7ccc2..81fc379c8 100644 --- a/armsrc/Standalone/dankarmulti.c +++ b/armsrc/Standalone/dankarmulti.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Daniel Karling, 2021 +// Copyright (C) Daniel Karling, 2021 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for Multi Loader //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/dankarmulti.h b/armsrc/Standalone/dankarmulti.h index 02cfd06c3..482391ddd 100644 --- a/armsrc/Standalone/dankarmulti.h +++ b/armsrc/Standalone/dankarmulti.h @@ -1,3 +1,21 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Daniel Karling, 2021 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// main code for Multi Loader +//----------------------------------------------------------------------------- #ifndef _DANKARMULTI_H_ #define _DANKARMULTI_H_ diff --git a/armsrc/Standalone/hf_14asniff.c b/armsrc/Standalone/hf_14asniff.c index 479405145..05c8628d7 100644 --- a/armsrc/Standalone/hf_14asniff.c +++ b/armsrc/Standalone/hf_14asniff.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Copyright 2020 Michael Farrell +// Copyright (C) 2020 Michael Farrell +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for standalone HF/iso14a Sniff to flash //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_aveful.c b/armsrc/Standalone/hf_aveful.c index dc481fc47..fd9b7ff36 100644 --- a/armsrc/Standalone/hf_aveful.c +++ b/armsrc/Standalone/hf_aveful.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// A. Ozkal, 2020 +// Copyright (C) A. Ozkal, 2020 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for HF Mifare Ultralight read/simulation by Ave Ozkal //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_bog.c b/armsrc/Standalone/hf_bog.c index 944b0b4be..5fa6fa247 100644 --- a/armsrc/Standalone/hf_bog.c +++ b/armsrc/Standalone/hf_bog.c @@ -1,7 +1,18 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Bogiton 2018 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for standalone HF Sniff (and ULC/NTAG/ULEV1 pwd storing) //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_colin.c b/armsrc/Standalone/hf_colin.c index a48d839db..2da9a582a 100644 --- a/armsrc/Standalone/hf_colin.c +++ b/armsrc/Standalone/hf_colin.c @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Colin Brigato, 2016, 2017, 2018, 2019 -// Christian Herrmann, 2017 +// Copyright (C) Colin Brigato, 2016 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for HF Mifare aka ColinRun by Colin Brigato //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_colin.h b/armsrc/Standalone/hf_colin.h index a4b870abc..aedc132d6 100644 --- a/armsrc/Standalone/hf_colin.h +++ b/armsrc/Standalone/hf_colin.h @@ -1,12 +1,18 @@ //----------------------------------------------------------------------------- -// Colin Brigato 2016, 2017 -// Christian Herrmann, 2017 +// Copyright (C) Colin Brigato 2016 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// StandAlone Mod +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- #include diff --git a/armsrc/Standalone/hf_craftbyte.c b/armsrc/Standalone/hf_craftbyte.c index d579a7de2..4e38284cc 100644 --- a/armsrc/Standalone/hf_craftbyte.c +++ b/armsrc/Standalone/hf_craftbyte.c @@ -1,16 +1,22 @@ //----------------------------------------------------------------------------- -// Copyright 2020 Anze Jensterle +// Copyright (C) 2020 Anze Jensterle +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for hf_craftbyte +// `hf_craftyte` continuously scans for ISO14443a card UID and then emulates it. //----------------------------------------------------------------------------- -// -// -// `hf_craftyte` continuesly scans for ISO14443a card UID and then emulates it. -// #include "standalone.h" #include "proxmark3_arm.h" diff --git a/armsrc/Standalone/hf_iceclass.c b/armsrc/Standalone/hf_iceclass.c index f614c07fb..cdaa4f220 100644 --- a/armsrc/Standalone/hf_iceclass.c +++ b/armsrc/Standalone/hf_iceclass.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Christian Herrmann, 2020 +// Copyright (C) Christian Herrmann, 2020 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for hf_iceclass by Iceman //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_legic.c b/armsrc/Standalone/hf_legic.c index 8f1a0ff66..3f332a7e1 100644 --- a/armsrc/Standalone/hf_legic.c +++ b/armsrc/Standalone/hf_legic.c @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// (c) Stefanie Hofmann, 2020 -// (c) Uli Heilmeier, 2020 +// Copyright (C) Stefanie Hofmann and Uli Heilmeier, 2020 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for Legic Prime read/sim //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_mattyrun.c b/armsrc/Standalone/hf_mattyrun.c index dc32b4946..97a02a278 100644 --- a/armsrc/Standalone/hf_mattyrun.c +++ b/armsrc/Standalone/hf_mattyrun.c @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Matías A. Ré Medina 2016 -// Christian Herrmann, 2018 +// Copyright (C) Matías A. Ré Medina 2016 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for HF aka MattyRun by Matías A. Ré Medina //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_mfcsim.c b/armsrc/Standalone/hf_mfcsim.c index 5608e2769..34541a390 100644 --- a/armsrc/Standalone/hf_mfcsim.c +++ b/armsrc/Standalone/hf_mfcsim.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Ray Lee, 2021 +// Copyright (C) Ray Lee, 2021 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for mifare classic simulator aka MFCSIM //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_msdsal.c b/armsrc/Standalone/hf_msdsal.c index 2b836c8da..8940909d1 100644 --- a/armsrc/Standalone/hf_msdsal.c +++ b/armsrc/Standalone/hf_msdsal.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Salvador Mendoza (salmg.net), 2020 +// Copyright (C) Salvador Mendoza (salmg.net), 2020 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Code for reading and emulating 14a technology aka MSDSal by Salvador Mendoza //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_reblay.c b/armsrc/Standalone/hf_reblay.c index 5416ea884..c058e83f2 100644 --- a/armsrc/Standalone/hf_reblay.c +++ b/armsrc/Standalone/hf_reblay.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Salvador Mendoza (salmg.net) - January 01, 2021 +// Copyright (C) Salvador Mendoza (salmg.net) - January 01, 2021 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Code to relay 14a technology data aka reblay by Salvador Mendoza //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_tcprst.c b/armsrc/Standalone/hf_tcprst.c index a15e4a7eb..3f6a77687 100644 --- a/armsrc/Standalone/hf_tcprst.c +++ b/armsrc/Standalone/hf_tcprst.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Nick Draffen, 2020 +// Copyright (C) Nick Draffen, 2020 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // code for HF ST25TA IKEA Rothult read/sim/dump/emulation by Nick Draffen //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/hf_tmudford.c b/armsrc/Standalone/hf_tmudford.c index dca6b6957..7fc277a47 100644 --- a/armsrc/Standalone/hf_tmudford.c +++ b/armsrc/Standalone/hf_tmudford.c @@ -1,16 +1,22 @@ //----------------------------------------------------------------------------- -// Copyright 2021 Tim Mudford +// Copyright (C) 2021 Tim Mudford +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for hf_tmudford -//----------------------------------------------------------------------------- -// -// // `hf_tmudford` Continuously scans for ISO15693 card UID and then emulates it. -// +//----------------------------------------------------------------------------- #include "standalone.h" #include "proxmark3_arm.h" diff --git a/armsrc/Standalone/hf_young.c b/armsrc/Standalone/hf_young.c index aed5e0dd6..725b6bc28 100644 --- a/armsrc/Standalone/hf_young.c +++ b/armsrc/Standalone/hf_young.c @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Craig Young, 2014 -// Christian Herrmann, 2017 +// Copyright (C) Craig Young, 2014 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for HF standalone mode Mifare /sniff/emulation by Craig Young //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/lf_em4100emul.c b/armsrc/Standalone/lf_em4100emul.c index 8412b4a50..614ca44ea 100644 --- a/armsrc/Standalone/lf_em4100emul.c +++ b/armsrc/Standalone/lf_em4100emul.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Artyom Gnatyuk, 2020 +// Copyright (C) Artyom Gnatyuk, 2020 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LF emul - Very simple mode. Simulate only predefined in low[] IDs // Short click - select next slot and start simulation diff --git a/armsrc/Standalone/lf_em4100rswb.c b/armsrc/Standalone/lf_em4100rswb.c index 6f6b5e223..574619da9 100644 --- a/armsrc/Standalone/lf_em4100rswb.c +++ b/armsrc/Standalone/lf_em4100rswb.c @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Monster1024 -// based on code by: Artyom Gnatyuk, 2020 +// Copyright (C) 2020 Dmitriy Loginoov +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LF rswb - This mode can simulate ID from selected slot, read ID to // selected slot, write from selected slot to T5555/T55x7 tag and store diff --git a/armsrc/Standalone/lf_em4100rwc.c b/armsrc/Standalone/lf_em4100rwc.c index fdcd0b7c6..7eed44d1d 100644 --- a/armsrc/Standalone/lf_em4100rwc.c +++ b/armsrc/Standalone/lf_em4100rwc.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Artyom Gnatyuk, 2020 +// Copyright (C) Artyom Gnatyuk, 2020 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LF rwc - This mode can simulate ID from selected slot, read ID to // selected slot, write from selected slot to T5555 tag and store diff --git a/armsrc/Standalone/lf_hidbrute.c b/armsrc/Standalone/lf_hidbrute.c index e2563eca4..87878cfa3 100644 --- a/armsrc/Standalone/lf_hidbrute.c +++ b/armsrc/Standalone/lf_hidbrute.c @@ -1,16 +1,21 @@ //----------------------------------------------------------------------------- -// Samy Kamkar, 2012 -// Federico Dotta, 2015 -// Maurizio Agazzini, 2015 -// Christian Herrmann, 2017 +// Copyright (C) Federico Dotta and Maurizio Agazzini, 2015 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- // PROXMARK3 - HID CORPORATE 1000 BRUTEFORCER (STAND-ALONE MODE) // -// This version of Proxmark3 firmware adds one extra stand-alone mode. // The new stand-alone mode allows to execute a bruteforce on HID Corporate 1000 readers, by // reading a specific badge and bruteforcing the Card Number (incrementing and decrementing it), // mainteining the same Facility Code of the original badge. diff --git a/armsrc/Standalone/lf_hidbrute.h b/armsrc/Standalone/lf_hidbrute.h index 72e12d305..b82c1bf49 100644 --- a/armsrc/Standalone/lf_hidbrute.h +++ b/armsrc/Standalone/lf_hidbrute.h @@ -1,15 +1,34 @@ //----------------------------------------------------------------------------- -// Samy Kamkar 2012 -// Federico Dotta, 2015 -// Maurizio Agazzini, 2015 -// Christian Herrmann, 2017 +// Copyright (C) Federico Dotta and Maurizio Agazzini, 2015 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// StandAlone Mod +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- +// PROXMARK3 - HID CORPORATE 1000 BRUTEFORCER (STAND-ALONE MODE) +// +// The new stand-alone mode allows to execute a bruteforce on HID Corporate 1000 readers, by +// reading a specific badge and bruteforcing the Card Number (incrementing and decrementing it), +// mainteining the same Facility Code of the original badge. +// +// Based on an idea of Brad Antoniewicz of McAfee® Foundstone® Professional Services (ProxBrute), +// the stand-alone mode has been rewritten in order to overcome some limitations of ProxBrute firmware, +// that does not consider parity bits. +// +// https://github.com/federicodotta/proxmark3 +// +//----------------------------------------------------------------------------------- +// main code for LF aka HID corporate brutefore by Federico Dotta & Maurizio Agazzini +//----------------------------------------------------------------------------------- #ifndef __LF_HIDBRUTE_H #define __LF_HIDBRUTE_H diff --git a/armsrc/Standalone/lf_hidfcbrute.c b/armsrc/Standalone/lf_hidfcbrute.c index 1b6fe9c9e..75c97e0bf 100644 --- a/armsrc/Standalone/lf_hidfcbrute.c +++ b/armsrc/Standalone/lf_hidfcbrute.c @@ -1,10 +1,25 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Stephen Shkardoon proxmark@ss23.geek.nz - ss23 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- /** * Bruteforce a HID system using a static card number but incrementing FC * * This is only going to work if the system has a card number registered that you know, * or if you can determine whether a given FC is valid based on external information. * - * Author: proxmark@ss23.geek.nz - ss23 * Based on lf_hidbrute * * To retrieve log file from flash: diff --git a/armsrc/Standalone/lf_hidfcbrute.h b/armsrc/Standalone/lf_hidfcbrute.h index 096d2ce53..441cf9188 100644 --- a/armsrc/Standalone/lf_hidfcbrute.h +++ b/armsrc/Standalone/lf_hidfcbrute.h @@ -1,3 +1,19 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Stephen Shkardoon proxmark@ss23.geek.nz - ss23 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef __LF_HIDFCBRUTE_H #define __LF_HIDFCBRUTE_H diff --git a/armsrc/Standalone/lf_icehid.c b/armsrc/Standalone/lf_icehid.c index 3fdc3e3cd..05cf039c5 100644 --- a/armsrc/Standalone/lf_icehid.c +++ b/armsrc/Standalone/lf_icehid.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Christian Herrmann, 2020 +// Copyright (C) Christian Herrmann, 2020 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for HID collector aka IceHID by Iceman //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/lf_nexid.c b/armsrc/Standalone/lf_nexid.c index f255a79c9..2904bab46 100644 --- a/armsrc/Standalone/lf_nexid.c +++ b/armsrc/Standalone/lf_nexid.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// BOSCA Maxime, RIOUX Guilhem 2021 +// Copyright (C) BOSCA Maxime and RIOUX Guilhem 2021 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for Nexwatch ID / Magic number collector. //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/lf_proxbrute.c b/armsrc/Standalone/lf_proxbrute.c index 8f777a020..112693077 100644 --- a/armsrc/Standalone/lf_proxbrute.c +++ b/armsrc/Standalone/lf_proxbrute.c @@ -1,11 +1,18 @@ //----------------------------------------------------------------------------- -// Samy Kamkar, 2011, 2012 -// Brad antoniewicz 2011 -// Christian Herrmann, 2017 +// Copyright (C) Brad Antoniewicz 2011 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for LF aka Proxbrute by Brad antoniewicz //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/lf_samyrun.c b/armsrc/Standalone/lf_samyrun.c index 82656f9d7..215ccfa44 100644 --- a/armsrc/Standalone/lf_samyrun.c +++ b/armsrc/Standalone/lf_samyrun.c @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Samy Kamkar, 2012 -// Christian Herrmann, 2017 +// Copyright (C) Samy Kamkar, 2012 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for LF aka SamyRun by Samy Kamkar //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/lf_skeleton.c b/armsrc/Standalone/lf_skeleton.c index a2d566cb7..4272cfc7e 100644 --- a/armsrc/Standalone/lf_skeleton.c +++ b/armsrc/Standalone/lf_skeleton.c @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Christian Herrmann, 2019 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for skeleton by Iceman //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/lf_tharexde.c b/armsrc/Standalone/lf_tharexde.c index f082f5b32..b46ea69d8 100644 --- a/armsrc/Standalone/lf_tharexde.c +++ b/armsrc/Standalone/lf_tharexde.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// tharexde, 2021 +// Copyright (C) tharexde, 2021 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // main code for EM4x50 simulator and collector aka THAREXDE //----------------------------------------------------------------------------- diff --git a/armsrc/Standalone/placeholder.c b/armsrc/Standalone/placeholder.c index 49028e27c..eb0e638da 100644 --- a/armsrc/Standalone/placeholder.c +++ b/armsrc/Standalone/placeholder.c @@ -1,3 +1,18 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "standalone.h" // standalone definitions #include "dbprint.h" diff --git a/armsrc/Standalone/standalone.h b/armsrc/Standalone/standalone.h index 29363f82f..2a8f1f837 100644 --- a/armsrc/Standalone/standalone.h +++ b/armsrc/Standalone/standalone.h @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Christian Herrmann, 2017 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // StandAlone Mod header file //----------------------------------------------------------------------------- diff --git a/armsrc/appmain.c b/armsrc/appmain.c index da9c6b9f5..a37b3aa78 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1,10 +1,19 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Mar 2006 -// Edits by Gerhard de Koning Gans, Sep 2007 (##) +// Copyright (C) Jonathan Westhues, Mar 2006 +// Copyright (C) Gerhard de Koning Gans, Sep 2007 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // The main application code. This is the first thing called after start.c // executes. diff --git a/armsrc/appmain.h b/armsrc/appmain.h index 863fbe1bb..3e69db47a 100644 --- a/armsrc/appmain.h +++ b/armsrc/appmain.h @@ -1,10 +1,19 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 +// Copyright (C) Jonathan Westhues, Aug 2005 +// Copyright (C) Gerhard de Koning Gans, April 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Definitions internal to the app source. //----------------------------------------------------------------------------- diff --git a/armsrc/buzzer_disabled.c b/armsrc/buzzer_disabled.c index 579ffaa4e..ccd4717fe 100644 --- a/armsrc/buzzer_disabled.c +++ b/armsrc/buzzer_disabled.c @@ -1,3 +1,19 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- + #include "buzzer_disabled.h" void Ring_BEE_ONCE(uint16_t music_note) { diff --git a/armsrc/buzzer_disabled.h b/armsrc/buzzer_disabled.h index c8b6e4472..b97862afe 100644 --- a/armsrc/buzzer_disabled.h +++ b/armsrc/buzzer_disabled.h @@ -1,6 +1,19 @@ -/******* ---by sww.2017.4.6 -*******/ +//----------------------------------------------------------------------------- +// Copyright (C) sww 2017.4.6 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef __BUZZER_H #define __BUZZER_H diff --git a/armsrc/cmd.c b/armsrc/cmd.c index 7a94cf536..fd0ce9a93 100644 --- a/armsrc/cmd.c +++ b/armsrc/cmd.c @@ -1,34 +1,18 @@ -/* - * Proxmark send and receive commands - * - * Copyright (c) 2012, Roel Verdult - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @file cmd.c - * @brief - */ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "cmd.h" #include "usb_cdc.h" #include "usart.h" diff --git a/armsrc/cmd.h b/armsrc/cmd.h index f4ae95ab1..4a42d9898 100644 --- a/armsrc/cmd.h +++ b/armsrc/cmd.h @@ -1,34 +1,18 @@ -/* - * Proxmark send and receive commands - * - * Copyright (c) 2010, Roel Verdult - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * @file cmd.h - * @brief - */ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef _PROXMARK_CMD_H_ #define _PROXMARK_CMD_H_ diff --git a/armsrc/dbprint.c b/armsrc/dbprint.c index bfeb0ded2..7be7bba4c 100644 --- a/armsrc/dbprint.c +++ b/armsrc/dbprint.c @@ -1,13 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Mar 2006 -// Edits by Gerhard de Koning Gans, Sep 2007 (##) +// Copyright (C) Jonathan Westhues, Mar 2006 +// Copyright (C) Gerhard de Koning Gans, Sep 2007 // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// The main application code. This is the first thing called after start.c -// executes. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- #include "dbprint.h" diff --git a/armsrc/dbprint.h b/armsrc/dbprint.h index 993e06289..b1a7753da 100644 --- a/armsrc/dbprint.h +++ b/armsrc/dbprint.h @@ -1,13 +1,21 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 +// Copyright (C) Jonathan Westhues, Aug 2005 +// Copyright (C) Gerhard de Koning Gans, April 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Definitions internal to the app source. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- + #ifndef __DBPRINT_H #define __DBPRINT_H diff --git a/armsrc/desfire_crypto.c b/armsrc/desfire_crypto.c index 5ad43647d..ad3265aec 100644 --- a/armsrc/desfire_crypto.c +++ b/armsrc/desfire_crypto.c @@ -1,22 +1,20 @@ -/*- - * Copyright (C) 2010, Romain Tartiere. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see - * - * $Id$ - */ - +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/nfc-tools/libfreefare +// Copyright (C) 2010, Romain Tartiere. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- /* * This implementation was written based on information provided by the * following documents: diff --git a/armsrc/desfire_crypto.h b/armsrc/desfire_crypto.h index 11e151475..c7f3dd004 100644 --- a/armsrc/desfire_crypto.h +++ b/armsrc/desfire_crypto.h @@ -1,3 +1,21 @@ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/nfc-tools/libfreefare +// Copyright (C) 2010, Romain Tartiere. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- + #ifndef __DESFIRE_CRYPTO_H #define __DESFIRE_CRYPTO_H diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 8c64baed7..a03e0090f 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2020 tharexde +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Low frequency EM4x50 commands //----------------------------------------------------------------------------- diff --git a/armsrc/em4x50.h b/armsrc/em4x50.h index 41aaa9605..af3a7a8db 100644 --- a/armsrc/em4x50.h +++ b/armsrc/em4x50.h @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2020 tharexde +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Low frequency EM4x50 commands //----------------------------------------------------------------------------- diff --git a/armsrc/em4x70.c b/armsrc/em4x70.c index d91847ea5..4dad5f236 100644 --- a/armsrc/em4x70.c +++ b/armsrc/em4x70.c @@ -1,11 +1,19 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2020 sirloins based on em4x50 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- -// Low frequency EM4170 commands +// Low frequency EM4x70 commands //----------------------------------------------------------------------------- #include "fpgaloader.h" diff --git a/armsrc/em4x70.h b/armsrc/em4x70.h index 1c301d909..363f119e3 100644 --- a/armsrc/em4x70.h +++ b/armsrc/em4x70.h @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2020 sirloins +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Low frequency EM4x70 commands //----------------------------------------------------------------------------- diff --git a/armsrc/emvtags.h b/armsrc/emvtags.h index fda3b2f37..2ea2a88e6 100644 --- a/armsrc/emvtags.h +++ b/armsrc/emvtags.h @@ -1,11 +1,17 @@ //----------------------------------------------------------------------------- -// Peter Fillmore 2014 -// code derived off merloks mifare code +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // structure to hold EMV card and terminal parameters //----------------------------------------------------------------------------- diff --git a/armsrc/epa.c b/armsrc/epa.c index 74e16d808..7206e5fd2 100644 --- a/armsrc/epa.c +++ b/armsrc/epa.c @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Frederik Möllers - August 2012 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support the German electronic "Personalausweis" (ID card) // Note that the functions which do not implement USB commands do NOT initialize diff --git a/armsrc/epa.h b/armsrc/epa.h index 92c644966..d3ed7b75e 100644 --- a/armsrc/epa.h +++ b/armsrc/epa.h @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Frederik Möllers - August 2012 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support the German electronic "Personalausweis" (ID card) //----------------------------------------------------------------------------- diff --git a/armsrc/felica.c b/armsrc/felica.c index 969da0ca1..21c71ff92 100644 --- a/armsrc/felica.c +++ b/armsrc/felica.c @@ -1,3 +1,18 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "felica.h" #include "proxmark3_arm.h" #include "BigBuf.h" diff --git a/armsrc/felica.h b/armsrc/felica.h index f30de4b6f..8f232b3e4 100644 --- a/armsrc/felica.h +++ b/armsrc/felica.h @@ -1,10 +1,17 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Definitions internal to the FeliCa functionality //----------------------------------------------------------------------------- diff --git a/armsrc/flashmem.c b/armsrc/flashmem.c index f7b69c922..fb1f74140 100644 --- a/armsrc/flashmem.c +++ b/armsrc/flashmem.c @@ -1,3 +1,20 @@ +//----------------------------------------------------------------------------- +// Borrowed initially from Arduino SPIFlash Library v.2.5.0 +// Copyright (C) 2015 by Prajwal Bhattaram. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "flashmem.h" #include "pmflash.h" diff --git a/armsrc/flashmem.h b/armsrc/flashmem.h index 54a101ea6..2b829c378 100644 --- a/armsrc/flashmem.h +++ b/armsrc/flashmem.h @@ -1,27 +1,19 @@ -/* Arduino SPIFlash Library v.2.5.0 - * Copyright (C) 2015 by Prajwal Bhattaram - * Modified by Prajwal Bhattaram - 13/11/2016 - * - * This file is part of the Arduino SPIFlash Library. This library is for - * Winbond NOR flash memory modules. In its current form it enables reading - * and writing individual data variables, structs and arrays from and to various locations; - * reading and writing pages; continuous read functions; sector, block and chip erase; - * suspending and resuming programming/erase and powering down for low power operation. - * - * This Library is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This Library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License v3.0 - * along with the Arduino SPIFlash Library. If not, see - * . - */ +//----------------------------------------------------------------------------- +// Borrowed initially from Arduino SPIFlash Library v.2.5.0 +// Copyright (C) 2015 by Prajwal Bhattaram. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// // Common Instructions // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// diff --git a/armsrc/fonts_disabled.c b/armsrc/fonts_disabled.c index 45a85e679..d971098b1 100644 --- a/armsrc/fonts_disabled.c +++ b/armsrc/fonts_disabled.c @@ -1,7 +1,17 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Fonts for the LCD //----------------------------------------------------------------------------- diff --git a/armsrc/fonts_disabled.h b/armsrc/fonts_disabled.h index 000be07af..71d4e0bc8 100644 --- a/armsrc/fonts_disabled.h +++ b/armsrc/fonts_disabled.h @@ -1,7 +1,17 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Fonts for the LCD //----------------------------------------------------------------------------- diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index 66210af21..5765519d1 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, April 2006 -// iZsh , 2014 +// Copyright (C) Jonathan Westhues, April 2006 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to load the FPGA image, and then to configure the FPGA's major // mode once it is configured. diff --git a/armsrc/fpgaloader.h b/armsrc/fpgaloader.h index 530dc21b4..cff84c3e2 100644 --- a/armsrc/fpgaloader.h +++ b/armsrc/fpgaloader.h @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, April 2006 -// iZsh , 2014 +// Copyright (C) Jonathan Westhues, April 2006 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to load the FPGA image, and then to configure the FPGA's major // mode once it is configured. diff --git a/armsrc/frozen.c b/armsrc/frozen.c index b8a6f3a02..455d9a3f2 100644 --- a/armsrc/frozen.c +++ b/armsrc/frozen.c @@ -1,20 +1,21 @@ -/* - * Copyright (c) 2004-2013 Sergey Lyubka - * Copyright (c) 2018 Cesanta Software Limited - * All rights reserved - * - * Licensed under the Apache License, Version 2.0 (the ""License""); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an ""AS IS"" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/cesanta/frozen +// Copyright (c) 2004-2013 Sergey Lyubka +// Copyright (c) 2018 Cesanta Software Limited +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005+ */ diff --git a/armsrc/frozen.h b/armsrc/frozen.h index fc6fd3b3b..b239d564c 100644 --- a/armsrc/frozen.h +++ b/armsrc/frozen.h @@ -1,20 +1,21 @@ -/* - * Copyright (c) 2004-2013 Sergey Lyubka - * Copyright (c) 2018 Cesanta Software Limited - * All rights reserved - * - * Licensed under the Apache License, Version 2.0 (the ""License""); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an ""AS IS"" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/cesanta/frozen +// Copyright (c) 2004-2013 Sergey Lyubka +// Copyright (c) 2018 Cesanta Software Limited +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef CS_FROZEN_FROZEN_H_ #define CS_FROZEN_FROZEN_H_ diff --git a/armsrc/hfsnoop.c b/armsrc/hfsnoop.c index 71420e2cd..ba9ef0740 100644 --- a/armsrc/hfsnoop.c +++ b/armsrc/hfsnoop.c @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// piwi, 2019 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to get sample data from FPGA. //----------------------------------------------------------------------------- diff --git a/armsrc/hfsnoop.h b/armsrc/hfsnoop.h index 8ed263fa5..4b715753d 100644 --- a/armsrc/hfsnoop.h +++ b/armsrc/hfsnoop.h @@ -1,13 +1,17 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 -// Piwi, Feb 2019 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Definitions internal to the app source. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- #ifndef __HFSNOOP_H #define __HFSNOOP_H diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 376971a97..20518674c 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -1,24 +1,18 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Hitag2 emulation +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// (c) 2009 Henryk Plötz -//----------------------------------------------------------------------------- -// Hitag2 complete rewrite of the code -// - Fixed modulation/encoding issues -// - Rewrote code for transponder emulation -// - Added sniffing of transponder communication -// - Added reader functionality +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // -// (c) 2012 Roel Verdult +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- -// Piwi, 2019 -// Iceman, 2019 -// Anon, 2019 -// Doegox, 2020 #define DBG if (g_dbglevel >= DBG_EXTENDED) diff --git a/armsrc/hitag2.h b/armsrc/hitag2.h index 3cff714c8..dcad3b417 100644 --- a/armsrc/hitag2.h +++ b/armsrc/hitag2.h @@ -1,10 +1,17 @@ //----------------------------------------------------------------------------- -// (c) 2012 Roel Verdult -// modified 2021 Iceman +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Hitag2 type prototyping //----------------------------------------------------------------------------- diff --git a/armsrc/hitag2_crypto.c b/armsrc/hitag2_crypto.c index 91c04ef43..a8a01dae4 100644 --- a/armsrc/hitag2_crypto.c +++ b/armsrc/hitag2_crypto.c @@ -1,13 +1,19 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Hitag2 Crypto -// -// (c) 2009 Henryk Plötz -// (c) 2012 Roel Verdult -// (c) 2019 Iceman //----------------------------------------------------------------------------- #include "hitag2_crypto.h" diff --git a/armsrc/hitag2_crypto.h b/armsrc/hitag2_crypto.h index 8544c7e1c..c6a7d7308 100644 --- a/armsrc/hitag2_crypto.h +++ b/armsrc/hitag2_crypto.h @@ -1,3 +1,18 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef __HITAG2_CRYPTO_H #define __HITAG2_CRYPTO_H diff --git a/armsrc/hitag2crack.c b/armsrc/hitag2crack.c index b6db19741..4bffee52c 100644 --- a/armsrc/hitag2crack.c +++ b/armsrc/hitag2crack.c @@ -1,12 +1,20 @@ //----------------------------------------------------------------------------- -// Kevin Sheldrake , Aug 2018 +// Borrowed initially from https://github.com/factoritbv/hitag2hell +// and https://github.com/AdamLaurie/RFIDler/blob/master/firmware/Pic32/RFIDler.X/src/hitag2crack.c +// Copyright (C) Kevin Sheldrake , Aug 2018 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // -// iceman, Jan, 2020 -// doegox, Jan, 2020 +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // hitag2 attack functions //----------------------------------------------------------------------------- diff --git a/armsrc/hitag2crack.h b/armsrc/hitag2crack.h index af3e41d14..4bf01791e 100644 --- a/armsrc/hitag2crack.h +++ b/armsrc/hitag2crack.h @@ -1,9 +1,20 @@ //----------------------------------------------------------------------------- -// Kevin Sheldrake , Aug 2018 +// Borrowed initially from https://github.com/factoritbv/hitag2hell +// and https://github.com/AdamLaurie/RFIDler/blob/master/firmware/Pic32/RFIDler.X/src/hitag2crack.c +// Copyright (C) Kevin Sheldrake , Aug 2018 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Definitions hitag2 attack functions //----------------------------------------------------------------------------- diff --git a/armsrc/hitagS.c b/armsrc/hitagS.c index 3a047738f..35ea870ea 100644 --- a/armsrc/hitagS.c +++ b/armsrc/hitagS.c @@ -1,16 +1,22 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Borrowed initially from https://github.com/Proxmark/proxmark3/pull/167/files +// Copyright (C) 2016 Oguzhan Cicek, Hendrik Schwartke, Ralf Spenneberg +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // HitagS emulation (preliminary test version) -// -// (c) 2016 Oguzhan Cicek, Hendrik Schwartke, Ralf Spenneberg -// //----------------------------------------------------------------------------- -// Some code was copied from Hitag2.c -//----------------------------------------------------------------------------- -// bosb 2020 #include "hitagS.h" diff --git a/armsrc/hitagS.h b/armsrc/hitagS.h index 4bda3c75b..49a4f358f 100644 --- a/armsrc/hitagS.h +++ b/armsrc/hitagS.h @@ -1,12 +1,21 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Borrowed initially from https://github.com/Proxmark/proxmark3/pull/167/files +// Copyright (C) 2016 Oguzhan Cicek, Hendrik Schwartke, Ralf Spenneberg +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // HitagS emulation (preliminary test version) -// -// (c) 2016 Oguzhan Cicek, Hendrik Schwartke, Ralf Spenneberg -// //----------------------------------------------------------------------------- #ifndef _HITAGS_H_ diff --git a/armsrc/i2c.c b/armsrc/i2c.c index 9734ccaf5..12d7c9cd2 100644 --- a/armsrc/i2c.c +++ b/armsrc/i2c.c @@ -1,10 +1,17 @@ //----------------------------------------------------------------------------- -// Willok, June 2018 -// Edits by Iceman, July 2018 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // The main i2c code, for communications with smart card module //----------------------------------------------------------------------------- diff --git a/armsrc/i2c.h b/armsrc/i2c.h index 20674b8d5..c1b6ada03 100644 --- a/armsrc/i2c.h +++ b/armsrc/i2c.h @@ -1,3 +1,18 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef __I2C_H #define __I2C_H diff --git a/armsrc/iclass.c b/armsrc/iclass.c index b7090ad9d..e8029dd69 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -1,20 +1,22 @@ //----------------------------------------------------------------------------- -// Gerhard de Koning Gans - May 2008 -// Hagen Fritsch - June 2010 -// Gerhard de Koning Gans - May 2011 -// Gerhard de Koning Gans - June 2012 - Added iClass card and reader emulation -// piwi - 2019 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Contribution made during a security research at Radboud University Nijmegen +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support iClass. //----------------------------------------------------------------------------- -// Contribution made during a security research at Radboud University Nijmegen -// -// Please feel free to contribute and extend iClass support!! -//----------------------------------------------------------------------------- #include "iclass.h" #include "proxmark3_arm.h" @@ -1445,9 +1447,9 @@ void ReaderIClass(uint8_t flags) { }; memcpy(&payload.header.hdr, &hdr, sizeof(picopass_hdr_t)); - reply_ng(CMD_HF_ICLASS_READER, PM3_SUCCESS, (uint8_t*)&payload, sizeof(iclass_card_select_resp_t)); + reply_ng(CMD_HF_ICLASS_READER, PM3_SUCCESS, (uint8_t *)&payload, sizeof(iclass_card_select_resp_t)); -out: +out: switch_off(); } diff --git a/armsrc/iclass.h b/armsrc/iclass.h index c0cbe9b3b..6801777f9 100644 --- a/armsrc/iclass.h +++ b/armsrc/iclass.h @@ -1,13 +1,19 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 -// Iceman, August 2020 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Contribution made during a security research at Radboud University Nijmegen +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Definitions internal to the app source. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- #ifndef __ICLASS_H #define __ICLASS_H diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index f8aec2a81..7fb0b4b0c 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -1,11 +1,19 @@ //----------------------------------------------------------------------------- -// Merlok - June 2011, 2012 -// Gerhard de Koning Gans - May 2008 -// Hagen Fritsch - June 2010 +// Copyright (C) Jonathan Westhues, Nov 2006 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support ISO 14443 type A. //----------------------------------------------------------------------------- diff --git a/armsrc/iso14443a.h b/armsrc/iso14443a.h index 2eebf0f8c..58664201a 100644 --- a/armsrc/iso14443a.h +++ b/armsrc/iso14443a.h @@ -1,11 +1,19 @@ //----------------------------------------------------------------------------- -// Merlok - June 2011 -// Gerhard de Koning Gans - May 2008 -// Hagen Fritsch - June 2010 +// Copyright (C) Jonathan Westhues, Nov 2006 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support ISO 14443 type A. //----------------------------------------------------------------------------- diff --git a/armsrc/iso14443b.c b/armsrc/iso14443b.c index 0820a8d80..8ad7b87d0 100644 --- a/armsrc/iso14443b.c +++ b/armsrc/iso14443b.c @@ -1,10 +1,19 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, split Nov 2006 -// piwi 2018 +// Copyright (C) Jonathan Westhues, Nov 2006 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support ISO 14443B. This includes both the reader software and // the `fake tag' modes. diff --git a/armsrc/iso14443b.h b/armsrc/iso14443b.h index 4ad840bfe..3dcbceaae 100644 --- a/armsrc/iso14443b.h +++ b/armsrc/iso14443b.h @@ -1,11 +1,19 @@ //----------------------------------------------------------------------------- -// Merlok - June 2011 -// Gerhard de Koning Gans - May 2008 -// Hagen Fritsch - June 2010 +// Copyright (C) Jonathan Westhues, Nov 2006 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support ISO 14443 type B. //----------------------------------------------------------------------------- diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 5a03c19e3..a09415f76 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -1,13 +1,19 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, split Nov 2006 -// Modified by Greg Jones, Jan 2009 -// Modified by Adrian Dabrowski "atrox", Mar-Sept 2010,Oct 2011 -// Modified by Christian Herrmann "iceman", 2017, 2020 -// Modified by piwi, Oct 2018 +// Copyright (C) Jonathan Westhues, Nov 2006 +// Copyright (C) Greg Jones, Jan 2009 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support ISO 15693. This includes both the reader software and // the `fake tag' modes. diff --git a/armsrc/iso15693.h b/armsrc/iso15693.h index db25e2c60..1b6c96977 100644 --- a/armsrc/iso15693.h +++ b/armsrc/iso15693.h @@ -1,10 +1,19 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 +// Copyright (C) Jonathan Westhues, Nov 2006 +// Copyright (C) Greg Jones, Jan 2009 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Definitions internal to the app source. //----------------------------------------------------------------------------- diff --git a/armsrc/legicrf.c b/armsrc/legicrf.c index f8b7e5cb6..840fd74f9 100644 --- a/armsrc/legicrf.c +++ b/armsrc/legicrf.c @@ -1,11 +1,17 @@ //----------------------------------------------------------------------------- -// (c) 2009 Henryk Plötz -// 2016 Iceman -// 2018 AntiCat +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LEGIC RF simulation code //----------------------------------------------------------------------------- diff --git a/armsrc/legicrf.h b/armsrc/legicrf.h index 687accbeb..670688aab 100644 --- a/armsrc/legicrf.h +++ b/armsrc/legicrf.h @@ -1,11 +1,17 @@ //----------------------------------------------------------------------------- -// (c) 2009 Henryk Plötz -// 2018 AntiCat -// 2020 iceman +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LEGIC RF emulation public interface //----------------------------------------------------------------------------- diff --git a/armsrc/legicrfsim.c b/armsrc/legicrfsim.c index 42867e799..58ca40320 100644 --- a/armsrc/legicrfsim.c +++ b/armsrc/legicrfsim.c @@ -1,11 +1,17 @@ //----------------------------------------------------------------------------- -// (c) 2009 Henryk Plötz -// 2016 Iceman -// 2018 AntiCat +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LEGIC RF simulation code //----------------------------------------------------------------------------- diff --git a/armsrc/legicrfsim.h b/armsrc/legicrfsim.h index 0b0bdbd9c..159d350f3 100644 --- a/armsrc/legicrfsim.h +++ b/armsrc/legicrfsim.h @@ -1,11 +1,17 @@ //----------------------------------------------------------------------------- -// (c) 2009 Henryk Plötz -// 2018 AntiCat -// 2019 Piwi -// 2020 Iceman -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LEGIC RF emulation public interface //----------------------------------------------------------------------------- diff --git a/armsrc/lfadc.c b/armsrc/lfadc.c index 930bf6af5..e33d9bfbf 100644 --- a/armsrc/lfadc.c +++ b/armsrc/lfadc.c @@ -1,7 +1,17 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LF ADC read/write implementation //----------------------------------------------------------------------------- diff --git a/armsrc/lfadc.h b/armsrc/lfadc.h index bb5a5c0c2..322584de2 100644 --- a/armsrc/lfadc.h +++ b/armsrc/lfadc.h @@ -1,7 +1,17 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // LF ADC read/write implementation //----------------------------------------------------------------------------- diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 44b98ae2c..d19e61d65 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -1,7 +1,18 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Jonathan Westhues, 2005 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Miscellaneous routines for low frequency tag operations. // Tags supported here so far are Texas Instruments (TI), HID, EM4x05, EM410x diff --git a/armsrc/lfops.h b/armsrc/lfops.h index 5c5a0fc74..0d6b7e342 100644 --- a/armsrc/lfops.h +++ b/armsrc/lfops.h @@ -1,12 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 +// Copyright (C) Jonathan Westhues, 2005 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Definitions internal to the app source. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- #ifndef __LFOPS_H #define __LFOPS_H diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c index ed0be0f81..ee9f8d772 100644 --- a/armsrc/lfsampling.c +++ b/armsrc/lfsampling.c @@ -1,7 +1,17 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Miscellaneous routines for low frequency sampling. //----------------------------------------------------------------------------- diff --git a/armsrc/lfsampling.h b/armsrc/lfsampling.h index ef7529fbf..11c03ca74 100644 --- a/armsrc/lfsampling.h +++ b/armsrc/lfsampling.h @@ -1,3 +1,18 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef __LFSAMPLING_H #define __LFSAMPLING_H diff --git a/armsrc/lfzx.c b/armsrc/lfzx.c index b392eba0e..be09247ca 100644 --- a/armsrc/lfzx.c +++ b/armsrc/lfzx.c @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2021 Iceman +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Low frequency ZX8211 funtions //----------------------------------------------------------------------------- diff --git a/armsrc/lfzx.h b/armsrc/lfzx.h index 3acb79543..1be9e72df 100644 --- a/armsrc/lfzx.h +++ b/armsrc/lfzx.h @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2021 Iceman +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Low frequency ZX8211 funtions //----------------------------------------------------------------------------- diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 38ba66548..76312a702 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1,16 +1,18 @@ //----------------------------------------------------------------------------- -// Merlok - June 2011, 2012 -// Gerhard de Koning Gans - May 2008 -// Hagen Fritsch - June 2010 -// Midnitesnake - Dec 2013 -// Andy Davies - Apr 2014 -// Iceman - May 2014,2015,2016 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Routines to support ISO 14443 type A. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- #include "mifarecmd.h" diff --git a/armsrc/mifarecmd.h b/armsrc/mifarecmd.h index 49f1832e7..c854cd136 100644 --- a/armsrc/mifarecmd.h +++ b/armsrc/mifarecmd.h @@ -1,12 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Definitions internal to the app source. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- #ifndef __MIFARECMD_H #define __MIFARECMD_H diff --git a/armsrc/mifaredesfire.c b/armsrc/mifaredesfire.c index 00379db45..08d7a9379 100644 --- a/armsrc/mifaredesfire.c +++ b/armsrc/mifaredesfire.c @@ -1,3 +1,18 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "mifaredesfire.h" #include "common.h" diff --git a/armsrc/mifaredesfire.h b/armsrc/mifaredesfire.h index b34e436f1..c8462cace 100644 --- a/armsrc/mifaredesfire.h +++ b/armsrc/mifaredesfire.h @@ -1,12 +1,17 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Gerhard de Koning Gans, April 2008, May 2011 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. -//----------------------------------------------------------------------------- -// Definitions internal to the app source. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- #ifndef __MIFAREDESFIRE_H #define __MIFAREDESFIRE_H diff --git a/armsrc/mifaresim.c b/armsrc/mifaresim.c index a05148514..a4691ccb8 100644 --- a/armsrc/mifaresim.c +++ b/armsrc/mifaresim.c @@ -1,11 +1,18 @@ -//----------------------------------------------------------------------------- -// Merlok - June 2011, 2012 -// Gerhard de Koning Gans - May 2008 -// Hagen Fritsch - June 2010 +//----------------------------------------------------------------------------- +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Mifare Classic Card Simulation //----------------------------------------------------------------------------- diff --git a/armsrc/mifaresim.h b/armsrc/mifaresim.h index d8c15aee2..b22659df6 100644 --- a/armsrc/mifaresim.h +++ b/armsrc/mifaresim.h @@ -1,11 +1,18 @@ //----------------------------------------------------------------------------- -// Merlok - June 2011, 2012 -// Gerhard de Koning Gans - May 2008 -// Hagen Fritsch - June 2010 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Mifare Classic Card Simulation //----------------------------------------------------------------------------- diff --git a/armsrc/mifaresniff_disabled.c b/armsrc/mifaresniff_disabled.c index 021d5a9a3..75a5b9524 100644 --- a/armsrc/mifaresniff_disabled.c +++ b/armsrc/mifaresniff_disabled.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Merlok - 2012 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support mifare classic sniffer. //----------------------------------------------------------------------------- diff --git a/armsrc/mifaresniff_disabled.h b/armsrc/mifaresniff_disabled.h index 426e5ccfa..8911ea268 100644 --- a/armsrc/mifaresniff_disabled.h +++ b/armsrc/mifaresniff_disabled.h @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Merlok - June 2012 +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support mifare classic sniffer. //----------------------------------------------------------------------------- diff --git a/armsrc/mifareutil.c b/armsrc/mifareutil.c index 9d276f98f..d0da3191e 100644 --- a/armsrc/mifareutil.c +++ b/armsrc/mifareutil.c @@ -1,9 +1,18 @@ -// Merlok, May 2011, 2012 -// Many authors, whom made it possible +//----------------------------------------------------------------------------- +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Work with mifare cards. //----------------------------------------------------------------------------- diff --git a/armsrc/mifareutil.h b/armsrc/mifareutil.h index d444dc81f..dddb76c98 100644 --- a/armsrc/mifareutil.h +++ b/armsrc/mifareutil.h @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Merlok, May 2011 -// Many authors, that makes it possible +// Copyright (C) Gerhard de Koning Gans - May 2008 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // code for work with mifare cards. //----------------------------------------------------------------------------- diff --git a/armsrc/nprintf.c b/armsrc/nprintf.c index 1ce3842d3..d60140d8c 100644 --- a/armsrc/nprintf.c +++ b/armsrc/nprintf.c @@ -1,34 +1,26 @@ -/////////////////////////////////////////////////////////////////////////////// -// \author (c) Marco Paland (info@paland.com) -// 2014-2019, PALANDesign Hannover, Germany +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/mpaland/printf +// Copyright (C) Marco Paland 2014-2019, PALANDesign Hannover, Germany +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// \license The MIT License (MIT) +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// \brief Tiny printf, sprintf and (v)snprintf implementation, optimized for speed on -// embedded systems with a very limited resources. These routines are thread -// safe and reentrant! -// Use this instead of the bloated standard/newlib printf cause these use -// malloc for printf (and may not be thread safe). -// -/////////////////////////////////////////////////////////////////////////////// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// Tiny printf, sprintf and (v)snprintf implementation, optimized for speed on +// embedded systems with a very limited resources. These routines are thread +// safe and reentrant! +// Use this instead of the bloated standard/newlib printf cause these use +// malloc for printf (and may not be thread safe). +//----------------------------------------------------------------------------- #include "nprintf.h" diff --git a/armsrc/nprintf.h b/armsrc/nprintf.h index 5c83384b7..8861f616a 100644 --- a/armsrc/nprintf.h +++ b/armsrc/nprintf.h @@ -1,33 +1,26 @@ -/////////////////////////////////////////////////////////////////////////////// -// \author (c) Marco Paland (info@paland.com) -// 2014-2019, PALANDesign Hannover, Germany +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/mpaland/printf +// Copyright (C) Marco Paland 2014-2019, PALANDesign Hannover, Germany +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// \license The MIT License (MIT) +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on -// embedded systems with a very limited resources. -// Use this instead of bloated standard/newlib printf. -// These routines are thread safe and reentrant. -// -/////////////////////////////////////////////////////////////////////////////// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// Tiny printf, sprintf and (v)snprintf implementation, optimized for speed on +// embedded systems with a very limited resources. These routines are thread +// safe and reentrant! +// Use this instead of the bloated standard/newlib printf cause these use +// malloc for printf (and may not be thread safe). +//----------------------------------------------------------------------------- #ifndef _PRINTF_H_ #define _PRINTF_H_ diff --git a/armsrc/optimized_cipher.c b/armsrc/optimized_cipher.c index 3910a18cd..bbe9f62ea 100644 --- a/armsrc/optimized_cipher.c +++ b/armsrc/optimized_cipher.c @@ -1,43 +1,37 @@ -/***************************************************************************** - * WARNING - * - * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. - * - * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL - * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, - * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. - * - * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. - * - ***************************************************************************** - * - * This file is part of loclass. It is a reconstructon of the cipher engine - * used in iClass, and RFID techology. - * - * The implementation is based on the work performed by - * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and - * Milosch Meriac in the paper "Dismantling IClass". - * - * Copyright (C) 2014 Martin Holst Swende - * - * This is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation, or, at your option, any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with loclass. If not, see . - * - * - * - ****************************************************************************/ - -/** - +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/holiman/loclass +// Copyright (C) 2014 Martin Holst Swende +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// WARNING +// +// THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. +// +// USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL +// PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, +// AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. +// +// THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. +//----------------------------------------------------------------------------- +// It is a reconstruction of the cipher engine used in iClass, and RFID techology. +// +// The implementation is based on the work performed by +// Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and +// Milosch Meriac in the paper "Dismantling IClass". +//----------------------------------------------------------------------------- +/* This file contains an optimized version of the MAC-calculation algorithm. Some measurements on a std laptop showed it runs in about 1/3 of the time: diff --git a/armsrc/optimized_cipher.h b/armsrc/optimized_cipher.h index 7f4236d1d..c9525a4dd 100644 --- a/armsrc/optimized_cipher.h +++ b/armsrc/optimized_cipher.h @@ -1,3 +1,36 @@ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/holiman/loclass +// Copyright (C) 2014 Martin Holst Swende +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// WARNING +// +// THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. +// +// USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL +// PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, +// AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. +// +// THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. +//----------------------------------------------------------------------------- +// It is a reconstruction of the cipher engine used in iClass, and RFID techology. +// +// The implementation is based on the work performed by +// Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and +// Milosch Meriac in the paper "Dismantling IClass". +//----------------------------------------------------------------------------- #ifndef OPTIMIZED_CIPHER_H #define OPTIMIZED_CIPHER_H diff --git a/armsrc/optimized_cipherutils.c b/armsrc/optimized_cipherutils.c index 14b699b8a..299d14800 100644 --- a/armsrc/optimized_cipherutils.c +++ b/armsrc/optimized_cipherutils.c @@ -1,39 +1,36 @@ -/***************************************************************************** - * WARNING - * - * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. - * - * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL - * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, - * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. - * - * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. - * - ***************************************************************************** - * - * This file is part of loclass. It is a reconstructon of the cipher engine - * used in iClass, and RFID techology. - * - * The implementation is based on the work performed by - * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and - * Milosch Meriac in the paper "Dismantling IClass". - * - * Copyright (C) 2014 Martin Holst Swende - * - * This is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation, or, at your option, any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with loclass. If not, see . - * - * - ****************************************************************************/ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/holiman/loclass +// Copyright (C) 2014 Martin Holst Swende +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// WARNING +// +// THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. +// +// USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL +// PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, +// AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. +// +// THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. +//----------------------------------------------------------------------------- +// It is a reconstruction of the cipher engine used in iClass, and RFID techology. +// +// The implementation is based on the work performed by +// Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and +// Milosch Meriac in the paper "Dismantling IClass". +//----------------------------------------------------------------------------- #include "optimized_cipherutils.h" #include diff --git a/armsrc/optimized_cipherutils.h b/armsrc/optimized_cipherutils.h index b95dd5f35..73fbfc730 100644 --- a/armsrc/optimized_cipherutils.h +++ b/armsrc/optimized_cipherutils.h @@ -1,39 +1,36 @@ -/***************************************************************************** - * WARNING - * - * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. - * - * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL - * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, - * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. - * - * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. - * - ***************************************************************************** - * - * This file is part of loclass. It is a reconstructon of the cipher engine - * used in iClass, and RFID techology. - * - * The implementation is based on the work performed by - * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and - * Milosch Meriac in the paper "Dismantling IClass". - * - * Copyright (C) 2014 Martin Holst Swende - * - * This is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation, or, at your option, any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with loclass. If not, see . - * - * - ****************************************************************************/ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/holiman/loclass +// Copyright (C) 2014 Martin Holst Swende +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// WARNING +// +// THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. +// +// USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL +// PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, +// AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. +// +// THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. +//----------------------------------------------------------------------------- +// It is a reconstruction of the cipher engine used in iClass, and RFID techology. +// +// The implementation is based on the work performed by +// Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and +// Milosch Meriac in the paper "Dismantling IClass". +//----------------------------------------------------------------------------- #ifndef CIPHERUTILS_H #define CIPHERUTILS_H #include diff --git a/armsrc/optimized_elite.c b/armsrc/optimized_elite.c index c84dd58be..7d9e752c9 100644 --- a/armsrc/optimized_elite.c +++ b/armsrc/optimized_elite.c @@ -1,40 +1,36 @@ -/***************************************************************************** - * WARNING - * - * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. - * - * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL - * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, - * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. - * - * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. - * - ***************************************************************************** - * - * This file is part of loclass. It is a reconstructon of the cipher engine - * used in iClass, and RFID techology. - * - * The implementation is based on the work performed by - * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and - * Milosch Meriac in the paper "Dismantling IClass". - * - * Copyright (C) 2014 Martin Holst Swende - * - * This is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation, or, at your option, any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with loclass. If not, see . - * - * - * - ****************************************************************************/ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/holiman/loclass +// Copyright (C) 2014 Martin Holst Swende +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// WARNING +// +// THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. +// +// USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL +// PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, +// AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. +// +// THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. +//----------------------------------------------------------------------------- +// It is a reconstruction of the cipher engine used in iClass, and RFID techology. +// +// The implementation is based on the work performed by +// Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and +// Milosch Meriac in the paper "Dismantling IClass". +//----------------------------------------------------------------------------- #include "optimized_elite.h" #include diff --git a/armsrc/optimized_elite.h b/armsrc/optimized_elite.h index 281ecf0bb..f11cb8f2d 100644 --- a/armsrc/optimized_elite.h +++ b/armsrc/optimized_elite.h @@ -1,41 +1,36 @@ -/***************************************************************************** - * WARNING - * - * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. - * - * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL - * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, - * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. - * - * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. - * - ***************************************************************************** - * - * This file is part of loclass. It is a reconstructon of the cipher engine - * used in iClass, and RFID techology. - * - * The implementation is based on the work performed by - * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and - * Milosch Meriac in the paper "Dismantling IClass". - * - * Copyright (C) 2014 Martin Holst Swende - * - * This is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation, or, at your option, any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with loclass. If not, see . - * - * - ****************************************************************************/ - - +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/holiman/loclass +// Copyright (C) 2014 Martin Holst Swende +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// WARNING +// +// THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. +// +// USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL +// PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, +// AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. +// +// THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. +//----------------------------------------------------------------------------- +// It is a reconstruction of the cipher engine used in iClass, and RFID techology. +// +// The implementation is based on the work performed by +// Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and +// Milosch Meriac in the paper "Dismantling IClass". +//----------------------------------------------------------------------------- #ifndef ELITE_CRACK_H #define ELITE_CRACK_H diff --git a/armsrc/optimized_ikeys.c b/armsrc/optimized_ikeys.c index 38b939262..66bbe41bc 100644 --- a/armsrc/optimized_ikeys.c +++ b/armsrc/optimized_ikeys.c @@ -1,39 +1,36 @@ -/***************************************************************************** - * WARNING - * - * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. - * - * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL - * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, - * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. - * - * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. - * - ***************************************************************************** - * - * This file is part of loclass. It is a reconstructon of the cipher engine - * used in iClass, and RFID techology. - * - * The implementation is based on the work performed by - * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and - * Milosch Meriac in the paper "Dismantling IClass". - * - * Copyright (C) 2014 Martin Holst Swende - * - * This is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation, or, at your option, any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with loclass. If not, see . - * - * - ****************************************************************************/ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/holiman/loclass +// Copyright (C) 2014 Martin Holst Swende +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// WARNING +// +// THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. +// +// USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL +// PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, +// AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. +// +// THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. +//----------------------------------------------------------------------------- +// It is a reconstruction of the cipher engine used in iClass, and RFID techology. +// +// The implementation is based on the work performed by +// Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and +// Milosch Meriac in the paper "Dismantling IClass". +//----------------------------------------------------------------------------- /** From "Dismantling iclass": diff --git a/armsrc/optimized_ikeys.h b/armsrc/optimized_ikeys.h index ae02911cc..2aa762eea 100644 --- a/armsrc/optimized_ikeys.h +++ b/armsrc/optimized_ikeys.h @@ -1,40 +1,36 @@ -/***************************************************************************** - * WARNING - * - * THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. - * - * USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL - * PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, - * AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. - * - * THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. - * - ***************************************************************************** - * - * This file is part of loclass. It is a reconstructon of the cipher engine - * used in iClass, and RFID techology. - * - * The implementation is based on the work performed by - * Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and - * Milosch Meriac in the paper "Dismantling IClass". - * - * Copyright (C) 2014 Martin Holst Swende - * - * This is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation, or, at your option, any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with loclass. If not, see . - * - * - ****************************************************************************/ - +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/holiman/loclass +// Copyright (C) 2014 Martin Holst Swende +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// WARNING +// +// THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY. +// +// USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL +// PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL, +// AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES. +// +// THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS. +//----------------------------------------------------------------------------- +// It is a reconstruction of the cipher engine used in iClass, and RFID techology. +// +// The implementation is based on the work performed by +// Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and +// Milosch Meriac in the paper "Dismantling IClass". +//----------------------------------------------------------------------------- #ifndef IKEYS_H #define IKEYS_H diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index fcd32eac8..68d660377 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -1,3 +1,18 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "pcf7931.h" #include "proxmark3_arm.h" diff --git a/armsrc/pcf7931.h b/armsrc/pcf7931.h index be13e10b5..18bd928b6 100644 --- a/armsrc/pcf7931.h +++ b/armsrc/pcf7931.h @@ -1,3 +1,18 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef __PCF7931_H #define __PCF7931_H diff --git a/armsrc/printf.c b/armsrc/printf.c index 25d4a4df8..9689bdb1f 100644 --- a/armsrc/printf.c +++ b/armsrc/printf.c @@ -1,38 +1,26 @@ -/*- - * Copyright (c) 1986, 1988, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 - */ +//----------------------------------------------------------------------------- +// Borrowed initially from subr_prf.c 8.3 (Berkeley) 1/21/94 +// Copyright (c) 1986, 1988, 1991, 1993 +// The Regents of the University of California. All rights reserved. +// (c) UNIX System Laboratories, Inc. +// All or some portions of this file are derived from material licensed +// to the University of California by American Telephone and Telegraph +// Co. or Unix System Laboratories, Inc. and are reproduced herein with +// the permission of UNIX System Laboratories, Inc. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "printf.h" #include "string.h" diff --git a/armsrc/printf.h b/armsrc/printf.h index bd0a6e2c9..cd2c7bf9b 100644 --- a/armsrc/printf.h +++ b/armsrc/printf.h @@ -1,9 +1,25 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2010 Hector Martin "marcan" +// Borrowed initially from subr_prf.c 8.3 (Berkeley) 1/21/94 +// Copyright (c) 1986, 1988, 1991, 1993 +// The Regents of the University of California. All rights reserved. +// (c) UNIX System Laboratories, Inc. +// All or some portions of this file are derived from material licensed +// to the University of California by American Telephone and Telegraph +// Co. or Unix System Laboratories, Inc. and are reproduced herein with +// the permission of UNIX System Laboratories, Inc. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Common *printf() functions //----------------------------------------------------------------------------- diff --git a/armsrc/radixsort.c b/armsrc/radixsort.c deleted file mode 100644 index 83b26d609..000000000 --- a/armsrc/radixsort.c +++ /dev/null @@ -1,99 +0,0 @@ -#include "radixsort.h" - -uint64_t *radixSort(uint64_t *array, uint32_t size) { - rscounts_t counts; - memset(&counts, 0, 256 * 8 * sizeof(uint32_t)); - uint64_t *cpy = (uint64_t *)calloc(size * sizeof(uint64_t), sizeof(uint8_t)); - uint32_t o8 = 0, o7 = 0, o6 = 0, o5 = 0, o4 = 0, o3 = 0, o2 = 0, o1 = 0; - uint32_t t8, t7, t6, t5, t4, t3, t2, t1; - uint32_t x; - // calculate counts - for (x = 0; x < size; ++x) { - t8 = array[x] & 0xff; - t7 = (array[x] >> 8) & 0xff; - t6 = (array[x] >> 16) & 0xff; - t5 = (array[x] >> 24) & 0xff; - t4 = (array[x] >> 32) & 0xff; - t3 = (array[x] >> 40) & 0xff; - t2 = (array[x] >> 48) & 0xff; - t1 = (array[x] >> 56) & 0xff; - counts.c8[t8]++; - counts.c7[t7]++; - counts.c6[t6]++; - counts.c5[t5]++; - counts.c4[t4]++; - counts.c3[t3]++; - counts.c2[t2]++; - counts.c1[t1]++; - } - // convert counts to offsets - for (x = 0; x < 256; ++x) { - t8 = o8 + counts.c8[x]; - t7 = o7 + counts.c7[x]; - t6 = o6 + counts.c6[x]; - t5 = o5 + counts.c5[x]; - t4 = o4 + counts.c4[x]; - t3 = o3 + counts.c3[x]; - t2 = o2 + counts.c2[x]; - t1 = o1 + counts.c1[x]; - counts.c8[x] = o8; - counts.c7[x] = o7; - counts.c6[x] = o6; - counts.c5[x] = o5; - counts.c4[x] = o4; - counts.c3[x] = o3; - counts.c2[x] = o2; - counts.c1[x] = o1; - o8 = t8; - o7 = t7; - o6 = t6; - o5 = t5; - o4 = t4; - o3 = t3; - o2 = t2; - o1 = t1; - } - // radix - for (x = 0; x < size; ++x) { - t8 = array[x] & 0xff; - cpy[counts.c8[t8]] = array[x]; - counts.c8[t8]++; - } - for (x = 0; x < size; ++x) { - t7 = (cpy[x] >> 8) & 0xff; - array[counts.c7[t7]] = cpy[x]; - counts.c7[t7]++; - } - for (x = 0; x < size; ++x) { - t6 = (array[x] >> 16) & 0xff; - cpy[counts.c6[t6]] = array[x]; - counts.c6[t6]++; - } - for (x = 0; x < size; ++x) { - t5 = (cpy[x] >> 24) & 0xff; - array[counts.c5[t5]] = cpy[x]; - counts.c5[t5]++; - } - for (x = 0; x < size; ++x) { - t4 = (array[x] >> 32) & 0xff; - cpy[counts.c4[t4]] = array[x]; - counts.c4[t4]++; - } - for (x = 0; x < size; ++x) { - t3 = (cpy[x] >> 40) & 0xff; - array[counts.c3[t3]] = cpy[x]; - counts.c3[t3]++; - } - for (x = 0; x < size; ++x) { - t2 = (array[x] >> 48) & 0xff; - cpy[counts.c2[t2]] = array[x]; - counts.c2[t2]++; - } - for (x = 0; x < size; ++x) { - t1 = (cpy[x] >> 56) & 0xff; - array[counts.c1[t1]] = cpy[x]; - counts.c1[t1]++; - } - free(cpy); - return array; -} diff --git a/armsrc/radixsort.h b/armsrc/radixsort.h deleted file mode 100644 index fb2bcc044..000000000 --- a/armsrc/radixsort.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef RADIXSORT_H__ -#define RADIXSORT_H__ - -#include "common.h" - -typedef union { - struct { - uint32_t c8[256]; - uint32_t c7[256]; - uint32_t c6[256]; - uint32_t c5[256]; - uint32_t c4[256]; - uint32_t c3[256]; - uint32_t c2[256]; - uint32_t c1[256]; - }; - uint32_t counts[256 * 8]; -} rscounts_t; - -uint64_t *radixSort(uint64_t *array, uint32_t size); - -#endif // RADIXSORT_H__ diff --git a/armsrc/spiffs.c b/armsrc/spiffs.c index 81e998ee9..bf20f8a70 100644 --- a/armsrc/spiffs.c +++ b/armsrc/spiffs.c @@ -1,11 +1,21 @@ //----------------------------------------------------------------------------- -// Colin J. Brigato, 2019 - [colin@brigato.fr] +// Borrowed initially from https://github.com/pellepl/spiffs +// Copyright (c) 2013-2017 Peter Andersson (pelleplutt1976 at gmail.com) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- -// SPIFFS api for RDV40 Integration by Colin Brigato +// SPIFFS api for RDV40 Integration //----------------------------------------------------------------------------- #define SPIFFS_CFG_PHYS_SZ (1024 * 128) diff --git a/armsrc/spiffs.h b/armsrc/spiffs.h index 5e85a8d82..01bf113e8 100644 --- a/armsrc/spiffs.h +++ b/armsrc/spiffs.h @@ -1,9 +1,20 @@ -/* - * spiffs.h - * - * Created on: May 26, 2013 - * Author: petera - */ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/pellepl/spiffs +// Copyright (c) 2013-2017 Peter Andersson (pelleplutt1976 at gmail.com) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef SPIFFS_H_ #define SPIFFS_H_ diff --git a/armsrc/spiffs_cache.c b/armsrc/spiffs_cache.c index 98acc4c2f..1eda9e6a9 100644 --- a/armsrc/spiffs_cache.c +++ b/armsrc/spiffs_cache.c @@ -1,9 +1,20 @@ -/* - * spiffs_cache.c - * - * Created on: Jun 23, 2013 - * Author: petera - */ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/pellepl/spiffs +// Copyright (c) 2013-2017 Peter Andersson (pelleplutt1976 at gmail.com) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "spiffs.h" #include "spiffs_nucleus.h" diff --git a/armsrc/spiffs_check.c b/armsrc/spiffs_check.c index 90fba8a41..c59fcabef 100644 --- a/armsrc/spiffs_check.c +++ b/armsrc/spiffs_check.c @@ -1,6 +1,21 @@ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/pellepl/spiffs +// Copyright (c) 2013-2017 Peter Andersson (pelleplutt1976 at gmail.com) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- /* - * spiffs_check.c - * * Contains functionality for checking file system consistency * and mending problems. * Three levels of consistency checks are implemented: @@ -13,10 +28,6 @@ * This is critical for the following page consistency check. * Page consistency * Checks for pages that ought to be indexed, ought not to be indexed, are multiple indexed - * - * - * Created on: Jul 7, 2013 - * Author: petera */ diff --git a/armsrc/spiffs_config.h b/armsrc/spiffs_config.h index 85997903b..eb699d976 100644 --- a/armsrc/spiffs_config.h +++ b/armsrc/spiffs_config.h @@ -1,9 +1,20 @@ -/* - * spiffs_config.h - * - * Created on: Jul 3, 2013 - * Author: petera - */ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/pellepl/spiffs +// Copyright (c) 2013-2017 Peter Andersson (pelleplutt1976 at gmail.com) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef SPIFFS_CONFIG_H_ #define SPIFFS_CONFIG_H_ diff --git a/armsrc/spiffs_gc.c b/armsrc/spiffs_gc.c index 76ff094c9..e5cf262b4 100644 --- a/armsrc/spiffs_gc.c +++ b/armsrc/spiffs_gc.c @@ -1,3 +1,20 @@ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/pellepl/spiffs +// Copyright (c) 2013-2017 Peter Andersson (pelleplutt1976 at gmail.com) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "spiffs.h" #include "spiffs_nucleus.h" diff --git a/armsrc/spiffs_hydrogen.c b/armsrc/spiffs_hydrogen.c index a166c3b7a..7fb5250c4 100644 --- a/armsrc/spiffs_hydrogen.c +++ b/armsrc/spiffs_hydrogen.c @@ -1,9 +1,20 @@ -/* - * spiffs_hydrogen.c - * - * Created on: Jun 16, 2013 - * Author: petera - */ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/pellepl/spiffs +// Copyright (c) 2013-2017 Peter Andersson (pelleplutt1976 at gmail.com) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "spiffs.h" #include "spiffs_nucleus.h" diff --git a/armsrc/spiffs_nucleus.c b/armsrc/spiffs_nucleus.c index 74c5ade09..2ebfabe04 100644 --- a/armsrc/spiffs_nucleus.c +++ b/armsrc/spiffs_nucleus.c @@ -1,3 +1,20 @@ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/pellepl/spiffs +// Copyright (c) 2013-2017 Peter Andersson (pelleplutt1976 at gmail.com) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #include "spiffs.h" #include "spiffs_nucleus.h" #include "printf.h" diff --git a/armsrc/spiffs_nucleus.h b/armsrc/spiffs_nucleus.h index 7fbf98acf..5f488ab16 100644 --- a/armsrc/spiffs_nucleus.h +++ b/armsrc/spiffs_nucleus.h @@ -1,9 +1,20 @@ -/* - * spiffs_nucleus.h - * - * Created on: Jun 15, 2013 - * Author: petera - */ +//----------------------------------------------------------------------------- +// Borrowed initially from https://github.com/pellepl/spiffs +// Copyright (c) 2013-2017 Peter Andersson (pelleplutt1976 at gmail.com) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- /* SPIFFS layout * diff --git a/armsrc/start.c b/armsrc/start.c index b399293c4..26a190d68 100644 --- a/armsrc/start.c +++ b/armsrc/start.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Mar 2006 +// Copyright (C) Jonathan Westhues, Mar 2006 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Just vector to AppMain(). This is in its own file so that I can place it // with the linker script. diff --git a/armsrc/string.c b/armsrc/string.c index d65cb6839..b7e549ff1 100644 --- a/armsrc/string.c +++ b/armsrc/string.c @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Sept 2005 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Common string.h functions //----------------------------------------------------------------------------- diff --git a/armsrc/string.h b/armsrc/string.h index 9232508dd..7b5d06e90 100644 --- a/armsrc/string.h +++ b/armsrc/string.h @@ -1,10 +1,17 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Copyright (C) 2010 Hector Martin "marcan" +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Common string.h functions //----------------------------------------------------------------------------- diff --git a/armsrc/thinfilm.c b/armsrc/thinfilm.c index 506dbbe85..96cbeafe5 100644 --- a/armsrc/thinfilm.c +++ b/armsrc/thinfilm.c @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2019 iceman +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support a mangeled ISO 14443 type A for Thinfilm tags by Kovio //----------------------------------------------------------------------------- diff --git a/armsrc/thinfilm.h b/armsrc/thinfilm.h index af1564482..7e7c5ac62 100644 --- a/armsrc/thinfilm.h +++ b/armsrc/thinfilm.h @@ -1,9 +1,17 @@ //----------------------------------------------------------------------------- -// Iceman - August 2019 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Routines to support a mangeled ISO 14443 type A for Thinfilm tags by Kovio //----------------------------------------------------------------------------- diff --git a/armsrc/ticks.c b/armsrc/ticks.c index 1d5e92bcf..61089595c 100644 --- a/armsrc/ticks.c +++ b/armsrc/ticks.c @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Sept 2005 -// Iceman, Sept 2016 +// Copyright (C) Jonathan Westhues, Sept 2005 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Timers, Clocks functions used in LF or Legic where you would need detailed time. //----------------------------------------------------------------------------- diff --git a/armsrc/ticks.h b/armsrc/ticks.h index d26b05bbc..7ad4486fa 100644 --- a/armsrc/ticks.h +++ b/armsrc/ticks.h @@ -1,10 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 -// Iceman, Sept 2016 +// Copyright (C) Jonathan Westhues, Aug 2005 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Timers, Clocks functions used in LF or Legic where you would need detailed time. //----------------------------------------------------------------------------- diff --git a/armsrc/usart.c b/armsrc/usart.c index 5b3a09fc0..f92e9c701 100644 --- a/armsrc/usart.c +++ b/armsrc/usart.c @@ -1,10 +1,17 @@ //----------------------------------------------------------------------------- -// Iceman, July 2018 -// edits by - Anticat, August 2018 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // The main USART code, for serial communications over FPC connector //----------------------------------------------------------------------------- diff --git a/armsrc/usart.h b/armsrc/usart.h index abe495692..e33745e00 100644 --- a/armsrc/usart.h +++ b/armsrc/usart.h @@ -1,3 +1,18 @@ +//----------------------------------------------------------------------------- +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- #ifndef __USART_H #define __USART_H diff --git a/armsrc/util.c b/armsrc/util.c index 027155547..831be2b4d 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Sept 2005 +// Copyright (C) Jonathan Westhues, Sept 2005 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Utility functions used in many places, not specific to any piece of code. //----------------------------------------------------------------------------- diff --git a/armsrc/util.h b/armsrc/util.h index 1d8586c43..65d24f026 100644 --- a/armsrc/util.h +++ b/armsrc/util.h @@ -1,9 +1,18 @@ //----------------------------------------------------------------------------- -// Jonathan Westhues, Aug 2005 +// Copyright (C) Jonathan Westhues, Aug 2005 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. // -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Utility functions used in many places, not specific to any piece of code. //----------------------------------------------------------------------------- diff --git a/armsrc/vtsend.c b/armsrc/vtsend.c index f07793cce..725df35d6 100644 --- a/armsrc/vtsend.c +++ b/armsrc/vtsend.c @@ -1,34 +1,22 @@ -/** - * @file vtsend.c - * @author CuBeatSystems - * @author Shinichiro Nakamura - * @copyright - * =============================================================== - * Natural Tiny Shell (NT-Shell) Version 0.3.1 - * =============================================================== - * Copyright (c) 2010-2016 Shinichiro Nakamura - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ +//----------------------------------------------------------------------------- +// Borrowed initially from https://cubeatsystems.com/ntshell/index.html +// Copyright (C) 2010-2016 Shinichiro Nakamura (CuBeatSystems) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// Natural Tiny Shell (NT-Shell) Version 0.3.1 +//----------------------------------------------------------------------------- #include "vtsend.h" #include "pm3_cmd.h" diff --git a/armsrc/vtsend.h b/armsrc/vtsend.h index 63d3d2461..c6d46ebec 100644 --- a/armsrc/vtsend.h +++ b/armsrc/vtsend.h @@ -1,34 +1,22 @@ -/** - * @file vtsend.h - * @author CuBeatSystems - * @author Shinichiro Nakamura - * @copyright - * =============================================================== - * Natural Tiny Shell (NT-Shell) Version 0.3.1 - * =============================================================== - * Copyright (c) 2010-2016 Shinichiro Nakamura - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ +//----------------------------------------------------------------------------- +// Borrowed initially from https://cubeatsystems.com/ntshell/index.html +// Copyright (C) 2010-2016 Shinichiro Nakamura (CuBeatSystems) +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. +//----------------------------------------------------------------------------- +// Natural Tiny Shell (NT-Shell) Version 0.3.1 +//----------------------------------------------------------------------------- #ifndef VTSEND_H #define VTSEND_H diff --git a/armsrc/wiegand.c b/armsrc/wiegand.c index cd4fb3eb6..506d43ded 100644 --- a/armsrc/wiegand.c +++ b/armsrc/wiegand.c @@ -1,9 +1,19 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- -// Wiegand functions +// Generic Wiegand Calculation code //----------------------------------------------------------------------------- #include "wiegand.h" diff --git a/armsrc/wiegand.h b/armsrc/wiegand.h index ce219fad1..5001bf715 100644 --- a/armsrc/wiegand.h +++ b/armsrc/wiegand.h @@ -1,7 +1,17 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Generic Wiegand Calculation code //----------------------------------------------------------------------------- diff --git a/bootrom/Makefile b/bootrom/Makefile index 49083c0d4..a1bc5f7ae 100644 --- a/bootrom/Makefile +++ b/bootrom/Makefile @@ -1,7 +1,18 @@ #----------------------------------------------------------------------------- -# This code is licensed to you under the terms of the GNU GPL, version 2 or, -# at your option, any later version. See the LICENSE.txt file for the text of -# the license. +# Copyright (C) Jonathan Westhues, Mar 2006 +# Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See LICENSE.txt for the text of the license. #----------------------------------------------------------------------------- # Makefile for bootrom, see ../common_arm/Makefile.common for common settings #----------------------------------------------------------------------------- diff --git a/bootrom/bootrom.c b/bootrom/bootrom.c index 5fc535cae..f59f66ef9 100644 --- a/bootrom/bootrom.c +++ b/bootrom/bootrom.c @@ -1,7 +1,18 @@ //----------------------------------------------------------------------------- -// This code is licensed to you under the terms of the GNU GPL, version 2 or, -// at your option, any later version. See the LICENSE.txt file for the text of -// the license. +// Copyright (C) Jonathan Westhues, Mar 2006 +// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// See LICENSE.txt for the text of the license. //----------------------------------------------------------------------------- // Main code for the bootloader //----------------------------------------------------------------------------- diff --git a/bootrom/flash-reset.s b/bootrom/flash-reset.s index efd0cccc2..f486eda15 100644 --- a/bootrom/flash-reset.s +++ b/bootrom/flash-reset.s @@ -1,7 +1,18 @@ @----------------------------------------------------------------------------- -@ This code is licensed to you under the terms of the GNU GPL, version 2 or, -@ at your option, any later version. See the LICENSE.txt file for the text of -@ the license. +@ Copyright (C) Jonathan Westhues, Mar 2006 +@ Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +@ +@ This program is free software: you can redistribute it and/or modify +@ it under the terms of the GNU General Public License as published by +@ the Free Software Foundation, either version 3 of the License, or +@ (at your option) any later version. +@ +@ This program is distributed in the hope that it will be useful, +@ but WITHOUT ANY WARRANTY; without even the implied warranty of +@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +@ GNU General Public License for more details. +@ +@ See LICENSE.txt for the text of the license. @----------------------------------------------------------------------------- @ Reset vector for running from FLASH @----------------------------------------------------------------------------- diff --git a/bootrom/ldscript-flash b/bootrom/ldscript-flash index c9174ffcd..5d63f9689 100644 --- a/bootrom/ldscript-flash +++ b/bootrom/ldscript-flash @@ -1,8 +1,19 @@ /* ----------------------------------------------------------------------------- - This code is licensed to you under the terms of the GNU GPL, version 2 or, - at your option, any later version. See the LICENSE.txt file for the text of - the license. + Copyright (C) Jonathan Westhues, Mar 2006 + Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See LICENSE.txt for the text of the license. ----------------------------------------------------------------------------- Bootrom linker script ----------------------------------------------------------------------------- diff --git a/bootrom/ram-reset.s b/bootrom/ram-reset.s index ab57ee29a..aed87a1ce 100644 --- a/bootrom/ram-reset.s +++ b/bootrom/ram-reset.s @@ -1,7 +1,18 @@ @----------------------------------------------------------------------------- -@ This code is licensed to you under the terms of the GNU GPL, version 2 or, -@ at your option, any later version. See the LICENSE.txt file for the text of -@ the license. +@ Copyright (C) Jonathan Westhues, Mar 2006 +@ Copyright (C) Proxmark3 contributors. See AUTHORS.md for details. +@ +@ This program is free software: you can redistribute it and/or modify +@ it under the terms of the GNU General Public License as published by +@ the Free Software Foundation, either version 3 of the License, or +@ (at your option) any later version. +@ +@ This program is distributed in the hope that it will be useful, +@ but WITHOUT ANY WARRANTY; without even the implied warranty of +@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +@ GNU General Public License for more details. +@ +@ See LICENSE.txt for the text of the license. @----------------------------------------------------------------------------- @ RAM reset vector for relaunching the bootloader @----------------------------------------------------------------------------- diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index b9945bf2e..7810f38b0 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -280,7 +280,7 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke HFiClassCalcDivKey(cc->csn, iClass_Key_Table[0], cc->key_d, false); } else { PrintAndLogEx(FAILED, "failed to read a card"); - PrintAndLogEx(INFO,"falling back to default config card"); + PrintAndLogEx(INFO, "falling back to default config card"); } // generate dump file @@ -338,7 +338,7 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke if (Encrypt(ffs, ffs) == false) { PrintAndLogEx(WARNING, "failed to encrypt FF"); } else { - PrintAndLogEx(NORMAL,"( " _GREEN_("ok") " )"); + PrintAndLogEx(NORMAL, "( " _GREEN_("ok") " )"); } // local key copy @@ -349,7 +349,7 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke if (Encrypt(lkey, enckey1) == false) { PrintAndLogEx(WARNING, "failed to encrypt key1"); } else { - PrintAndLogEx(NORMAL,"( " _GREEN_("ok") " )"); + PrintAndLogEx(NORMAL, "( " _GREEN_("ok") " )"); } PrintAndLogEx(INFO, "Copy data... " NOLF); @@ -362,7 +362,7 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke for (uint8_t i = 0xD; i < 0x14; i++) { memcpy(data + (i * 8), ffs, sizeof(ffs)); } - PrintAndLogEx(NORMAL,"( " _GREEN_("ok") " )"); + PrintAndLogEx(NORMAL, "( " _GREEN_("ok") " )"); // encrypted partial keyroll key 14 PrintAndLogEx(INFO, "Setting encrypted partial key14... " NOLF); @@ -373,7 +373,7 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke PrintAndLogEx(WARNING, "failed to encrypt partial 1"); } memcpy(data + (0x14 * 8), enckey2, sizeof(enckey2)); - PrintAndLogEx(NORMAL,"( " _GREEN_("ok") " )"); + PrintAndLogEx(NORMAL, "( " _GREEN_("ok") " )"); // encrypted partial keyroll key 15 @@ -384,14 +384,14 @@ static int generate_config_card(const iclass_config_card_item_t *o, uint8_t *ke PrintAndLogEx(WARNING, "failed to encrypt partial 2"); } memcpy(data + (0x15 * 8), enckey2, sizeof(enckey2)); - PrintAndLogEx(NORMAL,"( " _GREEN_("ok") " )"); + PrintAndLogEx(NORMAL, "( " _GREEN_("ok") " )"); // encrypted 0xFF PrintAndLogEx(INFO, "Setting 0xFF's... " NOLF); for (uint8_t i = 0x16; i <= app1_limit; i++) { memcpy(data + (i * 8), ffs, sizeof(ffs)); - } - PrintAndLogEx(NORMAL,"( " _GREEN_("ok") " )"); + } + PrintAndLogEx(NORMAL, "( " _GREEN_("ok") " )"); // revert potential modified app1_limit cc->conf.app_limit = old_limit; @@ -541,7 +541,7 @@ static void mem_app_config(const picopass_hdr_t *hdr) { uint8_t app_areas = 2; uint8_t books = 1; uint8_t pages = 1; - + getMemConfig(mem, chip, &app_areas, &kb, &books, &pages); uint8_t type = get_mem_config(hdr); @@ -558,25 +558,25 @@ static void mem_app_config(const picopass_hdr_t *hdr) { } PrintAndLogEx(INFO, " %u KBits/%u App Areas ( " _YELLOW_("%u") " bytes )" - , kb - , app_areas - , ((app2_limit + 1) * 8) * books * pages); + , kb + , app_areas + , ((app2_limit + 1) * 8) * books * pages); PrintAndLogEx(INFO, " %u books / %u pages" - , books - , pages - ); + , books + , pages + ); PrintAndLogEx(INFO, " First book / first page configuration"); PrintAndLogEx(INFO, " Config | 0 - 5 ( 0x00 - 0x05 ) - 6 blocks "); PrintAndLogEx(INFO, " AA1 | 6 - %2d ( 0x06 - 0x%02X ) - %u blocks", app1_limit + 5, app1_limit + 5, app1_limit); - if (app1_limit + 5 < app2_limit ) { + if (app1_limit + 5 < app2_limit) { PrintAndLogEx(INFO, " AA2 | %2d - %2d ( 0x%02X - 0x%02X ) - %u blocks", app1_limit + 5 + 1, app2_limit, app1_limit + 5 + 1, app2_limit, app2_limit - app1_limit); } -/* -[=] 32 KBits/3 App Areas ( 2048 bytes ) -[=] AA1 blocks 250 { 0x06 - 0xFF (06 - 255) } -[=] AA2 blocks 5 { 0x100 - 0xFF (256 - 255) } -*/ + /* + [=] 32 KBits/3 App Areas ( 2048 bytes ) + [=] AA1 blocks 250 { 0x06 - 0xFF (06 - 255) } + [=] AA2 blocks 5 { 0x100 - 0xFF (256 - 255) } + */ PrintAndLogEx(INFO, "------------------------- " _CYAN_("KeyAccess") " ------------------------"); PrintAndLogEx(INFO, " * Kd, Debit key, AA1 Kc, Credit key, AA2 *"); @@ -898,7 +898,7 @@ static int CmdHFiClassInfo(const char *Cmd) { int read_iclass_csn(bool loop, bool verbose) { iclass_card_select_t payload = { - .flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE) + .flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE) }; int res = PM3_SUCCESS; @@ -906,11 +906,11 @@ int read_iclass_csn(bool loop, bool verbose) { do { clearCommandBuffer(); PacketResponseNG resp; - SendCommandNG(CMD_HF_ICLASS_READER, (uint8_t*)&payload, sizeof(iclass_card_select_t)); + SendCommandNG(CMD_HF_ICLASS_READER, (uint8_t *)&payload, sizeof(iclass_card_select_t)); if (WaitForResponseTimeout(CMD_HF_ICLASS_READER, &resp, 2000)) { - iclass_card_select_resp_t *r = (iclass_card_select_resp_t*)resp.data.asBytes; + iclass_card_select_resp_t *r = (iclass_card_select_resp_t *)resp.data.asBytes; if (loop) { if (resp.status == PM3_ERFTRANS) { continue; @@ -1537,7 +1537,7 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) { } else { iclass_encrypt_block_data(blk_data, key); } - + PrintAndLogEx(SUCCESS, "encrypted... " _YELLOW_("%s"), sprint_hex_inrow(blk_data, sizeof(blk_data))); return PM3_SUCCESS; } @@ -1545,19 +1545,19 @@ static int CmdHFiClassEncryptBlk(const char *Cmd) { static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool verbose) { iclass_card_select_t payload = { - .flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE) + .flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE) }; clearCommandBuffer(); PacketResponseNG resp; - SendCommandNG(CMD_HF_ICLASS_READER, (uint8_t*)&payload, sizeof(iclass_card_select_t)); + SendCommandNG(CMD_HF_ICLASS_READER, (uint8_t *)&payload, sizeof(iclass_card_select_t)); if (WaitForResponseTimeout(CMD_HF_ICLASS_READER, &resp, 2000) == false) { PrintAndLogEx(WARNING, "command execute timeout"); return false; } - iclass_card_select_resp_t *r = (iclass_card_select_resp_t*)resp.data.asBytes; + iclass_card_select_resp_t *r = (iclass_card_select_resp_t *)resp.data.asBytes; picopass_hdr_t *hdr = &r->header.hdr; // no tag found or button pressed @@ -1700,11 +1700,11 @@ static int CmdHFiClassDump(const char *Cmd) { iclass_card_select_t payload_rdr = { - .flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE) + .flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE) }; clearCommandBuffer(); PacketResponseNG resp; - SendCommandNG(CMD_HF_ICLASS_READER, (uint8_t*)&payload_rdr, sizeof(iclass_card_select_t)); + SendCommandNG(CMD_HF_ICLASS_READER, (uint8_t *)&payload_rdr, sizeof(iclass_card_select_t)); if (WaitForResponseTimeout(CMD_HF_ICLASS_READER, &resp, 2000) == false) { PrintAndLogEx(WARNING, "command execute timeout"); @@ -1719,7 +1719,7 @@ static int CmdHFiClassDump(const char *Cmd) { return PM3_ESOFT; } - iclass_card_select_resp_t *r = (iclass_card_select_resp_t*)resp.data.asBytes; + iclass_card_select_resp_t *r = (iclass_card_select_resp_t *)resp.data.asBytes; if (r->status == FLAG_ICLASS_NULL) { PrintAndLogEx(FAILED, "failed to read block 0,1,2"); return PM3_ESOFT; @@ -4038,11 +4038,11 @@ int CmdHFiClass(const char *Cmd) { int info_iclass(void) { iclass_card_select_t payload = { - .flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE) + .flags = (FLAG_ICLASS_READER_INIT | FLAG_ICLASS_READER_CLEARTRACE) }; clearCommandBuffer(); PacketResponseNG resp; - SendCommandNG(CMD_HF_ICLASS_READER, (uint8_t*)&payload, sizeof(iclass_card_select_t)); + SendCommandNG(CMD_HF_ICLASS_READER, (uint8_t *)&payload, sizeof(iclass_card_select_t)); if (WaitForResponseTimeout(CMD_HF_ICLASS_READER, &resp, 2000) == false) { DropField(); @@ -4050,7 +4050,7 @@ int info_iclass(void) { } DropField(); - iclass_card_select_resp_t *r = (iclass_card_select_resp_t*)resp.data.asBytes; + iclass_card_select_resp_t *r = (iclass_card_select_resp_t *)resp.data.asBytes; // no tag found or button pressed if (r->status == FLAG_ICLASS_NULL || resp.status == PM3_ERFTRANS) { @@ -4093,7 +4093,7 @@ int info_iclass(void) { } else { PrintAndLogEx(SUCCESS, " Kc: %s credit key ( hidden )", sprint_hex(hdr->key_c, sizeof(hdr->key_c))); } - + if ((r->status & FLAG_ICLASS_AIA) == FLAG_ICLASS_AIA) { PrintAndLogEx(SUCCESS, " AIA: %s application issuer area", sprint_hex(hdr->app_issuer_area, sizeof(hdr->app_issuer_area))); diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 428364608..11aa7328b 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -2369,6 +2369,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) { arg_str0(NULL, "ks2", "", "Key settings 2 (HEX 1 byte). default 0x0e"), arg_str0(NULL, "dstalgo", "", "Application key crypt algo: DES, 2TDEA, 3TDEA, AES. default DES"), arg_int0(NULL, "numkeys", "", "Keys count. 0x00..0x0e. default 0x0e"), + arg_lit0(NULL, "no-auth", "execute without authentication"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); @@ -2420,6 +2421,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) { } int keycount = arg_get_int_def(ctx, 18, 0x0e); + bool noauth = arg_get_lit(ctx, 19); SetAPDULogging(APDULogging); CLIParserFree(ctx); @@ -2444,7 +2446,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) { return PM3_EINVARG; } - res = DesfireSelectAndAuthenticate(&dctx, securechann, 0x000000, verbose); + res = DesfireSelectAndAuthenticateEx(&dctx, securechann, 0x000000, noauth, verbose); if (res != PM3_SUCCESS) { DropField(); return res; diff --git a/client/src/cmdlfkeri.c b/client/src/cmdlfkeri.c index ec57d5bf8..f1ebc0efd 100644 --- a/client/src/cmdlfkeri.c +++ b/client/src/cmdlfkeri.c @@ -30,12 +30,12 @@ typedef enum {Scramble = 0, Descramble = 1} KeriMSScramble_t; static int CmdKeriMSScramble(KeriMSScramble_t Action, uint32_t *FC, uint32_t *ID, uint32_t *CardID) { // 255 = Not used/Unknown other values are the bit offset in the ID/FC values const uint8_t CardToID [] = { 255, 255, 255, 255, 13, 12, 20, 5, 16, 6, 21, 17, 8, 255, 0, 7, - 10, 15, 255, 11, 4, 1, 255, 18, 255, 19, 2, 14, 3, 9, 255, 255 - }; + 10, 15, 255, 11, 4, 1, 255, 18, 255, 19, 2, 14, 3, 9, 255, 255 + }; const uint8_t CardToFC [] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 255, 255, - 255, 255, 2, 255, 255, 255, 3, 255, 4, 255, 255, 255, 255, 255, 1, 255 - }; + 255, 255, 2, 255, 255, 255, 3, 255, 4, 255, 255, 255, 255, 255, 1, 255 + }; uint8_t card_idx; // 0 - 31 diff --git a/doc/commands.json b/doc/commands.json index 980d42544..81fe8a01d 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -4376,9 +4376,10 @@ "--ks1 key settings 1 (hex 1 byte). application master key settings. default 0x0f", "--ks2 key settings 2 (hex 1 byte). default 0x0e", "--dstalgo application key crypt algo: des, 2tdea, 3tdea, aes. default des", - "--numkeys keys count. 0x00..0x0e. default 0x0e" + "--numkeys keys count. 0x00..0x0e. default 0x0e", + "--no-auth execute without authentication" ], - "usage": "hf mfdes createapp [-hav] [-n ] [-t ] [-k ] [-f ] [-i ] [-m ] [-c ] [-s ] [--rawdata ] [--aid ] [--fid ] [--dfname ] [--ks1 ] [--ks2 ] [--dstalgo ] [--numkeys ]" + "usage": "hf mfdes createapp [-hav] [-n ] [-t ] [-k ] [-f ] [-i ] [-m ] [-c ] [-s ] [--rawdata ] [--aid ] [--fid ] [--dfname ] [--ks1 ] [--ks2 ] [--dstalgo ] [--numkeys ] [--no-auth]" }, "hf mfdes createfile": { "command": "hf mfdes createfile", diff --git a/fpga-xc3s100e/LICENSE b/fpga-xc3s100e/LICENSE deleted file mode 100644 index 94a9ed024..000000000 --- a/fpga-xc3s100e/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/include/iclass_cmd.h b/include/iclass_cmd.h index 5bb4f9c92..db9c43903 100644 --- a/include/iclass_cmd.h +++ b/include/iclass_cmd.h @@ -142,12 +142,12 @@ typedef struct { } PACKED picopass_ns_hdr_t; // reader flags -typedef struct { +typedef struct { uint8_t flags; } PACKED iclass_card_select_t; // reader flags -typedef struct { +typedef struct { uint8_t status; union { picopass_hdr_t hdr; @@ -156,4 +156,4 @@ typedef struct { } PACKED iclass_card_select_resp_t; -#endif // _ICLASS_H_ \ No newline at end of file +#endif // _ICLASS_H_ diff --git a/tools/hitag2crack/crack5opencl/LICENSE.txt b/tools/hitag2crack/crack5opencl/LICENSE.txt deleted file mode 100644 index 94a9ed024..000000000 --- a/tools/hitag2crack/crack5opencl/LICENSE.txt +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -.