From 8ae01aa1806b7da9aec067387fac2b62b75d4ed2 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Fri, 13 Aug 2021 13:58:35 +0300 Subject: [PATCH] make style and (c) --- client/src/cmdhfmfdes.c | 16 ++++++++-------- client/src/crypto/libpcrypto.c | 2 +- client/src/crypto/libpcrypto.h | 2 +- client/src/mifare/desfirecore.c | 4 ++-- client/src/mifare/desfirecrypto.c | 4 ++-- client/src/mifare/desfiretest.c | 6 +++--- doc/commands.json | 23 +++++++++++++++-------- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 447cb199f..02fbef857 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -4843,7 +4843,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) { CLIParserFree(ctx); return PM3_EINVARG; } - + uint8_t trkey[250] = {0}; int trkeylen = sizeof(trkey); CLIGetHexWithReturn(ctx, 23, trkey, &trkeylen); @@ -4860,7 +4860,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) { PrintAndLogEx(ERR, "File number range is invalid (exp 0 - 31), got %d", fnum); return PM3_EINVARG; } - + // get uid if (trkeylen > 0) DesfireGetCardUID(&dctx); @@ -4947,7 +4947,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) { PrintAndLogEx(WARNING, "GetFileSettings error. Can't get file type."); } } - + // CommitReaderID command bool readeridpushed = false; if (readeridlen > 0) { @@ -4962,24 +4962,24 @@ static int CmdHF14ADesWriteData(const char *Cmd) { if (res == PM3_SUCCESS) { PrintAndLogEx(INFO, _GREEN_("Commit Reader ID: ")); PrintAndLogEx(INFO, "Prev reader id encoded [%d]: %s", resplen, sprint_hex(resp, resplen)); - + if (trkeylen > 0) { uint8_t sessionkey[16] = {0}; uint8_t uid[7] = {0}; memcpy(uid, dctx.uid, MAX(dctx.uidlen, 7)); DesfireGenTransSessionKey(trkey, transactionCounter, uid, false, sessionkey); - + aes_decode(NULL, sessionkey, resp, resp, CRYPTO_AES_BLOCK_SIZE); PrintAndLogEx(INFO, "Prev reader id [%d]: %s", resplen, sprint_hex(resp, resplen)); } - + readeridpushed = true; if (verbose) PrintAndLogEx(INFO, "CommitReaderID " _GREEN_("OK")); } else PrintAndLogEx(WARNING, "Desfire CommitReaderID command " _RED_("error") ". Result: %d", res); } - + // write if (op == RFTData) { res = DesfireWriteFile(&dctx, fnum, offset, datalen, data); @@ -5061,7 +5061,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) { PrintAndLogEx(INFO, "TMC and TMV[%d]: %s", resplen, sprint_hex(resp, resplen)); PrintAndLogEx(INFO, "Commit " _GREEN_("OK")); } - + if (resplen == 4 + 8) { PrintAndLogEx(INFO, _GREEN_("Commit result:")); uint32_t cnt = MemLeToUint4byte(&resp[0]); diff --git a/client/src/crypto/libpcrypto.c b/client/src/crypto/libpcrypto.c index 8c4bdd8fc..5bc03bd9f 100644 --- a/client/src/crypto/libpcrypto.c +++ b/client/src/crypto/libpcrypto.c @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2018 Merlok +// Copyright (C) 2018, 2021 Merlok // Copyright (C) 2018 drHatson // // This code is licensed to you under the terms of the GNU GPL, version 2 or, diff --git a/client/src/crypto/libpcrypto.h b/client/src/crypto/libpcrypto.h index 0a9cb01ce..c589f61f6 100644 --- a/client/src/crypto/libpcrypto.h +++ b/client/src/crypto/libpcrypto.h @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// Copyright (C) 2018 Merlok +// Copyright (C) 2018, 2021 Merlok // // 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 diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index c0bf04219..82fa4f81c 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -2437,7 +2437,7 @@ void DesfirePrintCreateFileSettings(uint8_t filetype, uint8_t *data, size_t len) PrintAndLogEx(SUCCESS, "Access rights : %04x", MemLeToUint2byte(&data[xlen])); DesfirePrintAccessRight(&data[xlen]); xlen += 2; - + // https://www.nxp.com/docs/en/data-sheet/MF2DLHX0.pdf // page 14 // TransactionMAC file @@ -2449,7 +2449,7 @@ void DesfirePrintCreateFileSettings(uint8_t filetype, uint8_t *data, size_t len) DesfireDecodeFileAcessMode(&data[xlen - 2], &read, &write, &readwrite, &change); if (write != 0x0f) PrintAndLogEx(WARNING, "descr. : Write right should be set to F because write " _RED_("not allowed") "."); - + if (readwrite == 0x0f) PrintAndLogEx(SUCCESS, "descr. : ReadWrite right is %01X, CommitReaderID command disabled", readwrite); else if (readwrite == 0x0e) diff --git a/client/src/mifare/desfirecrypto.c b/client/src/mifare/desfirecrypto.c index 45d22387c..d4b1a311f 100644 --- a/client/src/mifare/desfirecrypto.c +++ b/client/src/mifare/desfirecrypto.c @@ -623,7 +623,7 @@ int DesfireEV2CalcCMAC(DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t d // page 42 void DesfireGenTransSessionKey(uint8_t *key, uint32_t trCntr, uint8_t *uid, bool forMAC, uint8_t *sessionkey) { uint8_t xiv[CRYPTO_AES_BLOCK_SIZE] = {0}; - + if (forMAC) { xiv[0] = 0x5a; } else { @@ -633,7 +633,7 @@ void DesfireGenTransSessionKey(uint8_t *key, uint32_t trCntr, uint8_t *uid, bool xiv[4] = 0x80; Uint4byteToMemLe(&xiv[5], trCntr + 1); memcpy(&xiv[9], uid, 7); - + DesfireContext ctx = {0}; DesfireSetKey(&ctx, 0, T_AES, key); DesfireCryptoCMACEx(&ctx, DCOMainKey, xiv, 16, 0, sessionkey); diff --git a/client/src/mifare/desfiretest.c b/client/src/mifare/desfiretest.c index bd1d91ef0..174d8bd71 100644 --- a/client/src/mifare/desfiretest.c +++ b/client/src/mifare/desfiretest.c @@ -452,11 +452,11 @@ static bool TestEV2MAC(void) { static bool TestTransSessionKeys(void) { bool res = true; - + uint8_t key[] = {0x66, 0xA8, 0xCB, 0x93, 0x26, 0x9D, 0xC9, 0xBC, 0x28, 0x85, 0xB7, 0xA9, 0x1B, 0x9C, 0x69, 0x7B}; uint8_t uid[] = {0x04, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; uint32_t trCntr = 8; - + uint8_t sessionkey[16] = {0}; DesfireGenTransSessionKey(key, trCntr, uid, true, sessionkey); uint8_t keymac[] = {0x7C, 0x1A, 0xD2, 0xD9, 0xC5, 0xC0, 0x81, 0x54, 0xA0, 0xA4, 0x91, 0x4B, 0x40, 0x1A, 0x65, 0x98}; @@ -465,7 +465,7 @@ static bool TestTransSessionKeys(void) { DesfireGenTransSessionKey(key, trCntr, uid, false, sessionkey); uint8_t keyenc[] = {0x11, 0x9B, 0x90, 0x2A, 0x07, 0xB1, 0x8A, 0x86, 0x5B, 0x8E, 0x1B, 0x00, 0x60, 0x59, 0x47, 0x84}; res = res && (memcmp(sessionkey, keyenc, sizeof(keyenc)) == 0); - + if (res) PrintAndLogEx(INFO, "Trans session key. " _GREEN_("passed")); else diff --git a/doc/commands.json b/doc/commands.json index eb165f824..ff0e51657 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -973,7 +973,7 @@ }, "help": { "command": "help", - "description": "help use ` help` for details of a command prefs { edit client/device preferences... } -------- ----------------------- technology ----------------------- analyse { analyse utils... } data { plot window / data buffer manipulation... } emv { emv iso-14443 / iso-7816... } hf { high frequency commands... } hw { hardware commands... } lf { low frequency commands... } nfc { nfc commands... } reveng { crc calculations from reveng software... } smart { smart card iso-7816 commands... } script { scripting commands... } trace { trace manipulation... } wiegand { wiegand format manipulation... } -------- ----------------------- general ----------------------- clear clear screen hints turn hints on / off msleep add a pause in milliseconds rem add a text line in log file quit exit exit program [=] session log e:\\proxspace\\pm3/.proxmark3/logs/log_20210812.txt --------------------------------------------------------------------------------------- auto available offline: no run lf search / hf search / data plot / data save", + "description": "help use ` help` for details of a command prefs { edit client/device preferences... } -------- ----------------------- technology ----------------------- analyse { analyse utils... } data { plot window / data buffer manipulation... } emv { emv iso-14443 / iso-7816... } hf { high frequency commands... } hw { hardware commands... } lf { low frequency commands... } nfc { nfc commands... } reveng { crc calculations from reveng software... } smart { smart card iso-7816 commands... } script { scripting commands... } trace { trace manipulation... } wiegand { wiegand format manipulation... } -------- ----------------------- general ----------------------- clear clear screen hints turn hints on / off msleep add a pause in milliseconds rem add a text line in log file quit exit exit program [=] session log e:\\proxspace\\pm3/.proxmark3/logs/log_20210813.txt --------------------------------------------------------------------------------------- auto available offline: no run lf search / hf search / data plot / data save", "notes": [ "auto" ], @@ -4241,7 +4241,9 @@ "notes": [ "--rawrights have priority over the separate rights settings.", "key/mode/etc of the authentication depends on application settings", - "hf mfdes createmacfile --aid 123456 --fid 01 --mackey --rawrights 1f30 00112233445566778899aabbccddeeff --mackeyver 01 -> create transaction mac file with parameters. rights from default. authentication with defaults from `default` command", + "write right should be always 0xf. read-write right should be 0xf if you not need to submit commitreaderid command each time transaction starts", + "", + "hf mfdes createmacfile --aid 123456 --fid 01 --rawrights 0ff0 --mackey 00112233445566778899aabbccddeeff --mackeyver 01 -> create transaction mac file with parameters. rights from default. authentication with defaults from `default` command", "hf mfdes createmacfile --aid 123456 --fid 01 --amode plain --rrights free --wrights deny --rwrights free --chrights key0 --mackey 00112233445566778899aabbccddeeff -> create file app=123456, file=01, with key, and mentioned rights with defaults from `default` command", "hf mfdes createmacfile -n 0 -t des -k 0000000000000000 -f none --aid 123456 --fid 01 -> execute with default factory setup. key and keyver == 0x00..00" ], @@ -4934,7 +4936,7 @@ }, "hf mfdes test": { "command": "hf mfdes test", - "description": "[=] ------ desfire tests ------ [!] no space for crc. pos: 1 [=] crc16............. passed [!] no space for crc. pos: 2 [=] crc32............. passed [=] cmac subkeys...... passed [=] an10922 aes....... passed [=] an10922 2tdea..... passed [=] an10922 3tdea..... passed [=] cmac 3tdea........ passed [=] cmac 2tdea........ passed [=] cmac des.......... passed [=] ev2 session keys.. passed [=] ev2 iv calc....... passed [=] ev2 mac calc...... passed [=] --------------------------- [+] tests [ ok ] ======================================================================================= hf seos { seos rfids... } --------------------------------------------------------------------------------------- hf seos help available offline: yes help this help list list seos history --------------------------------------------------------------------------------------- hf seos info available offline: no get info from seos tags", + "description": "[=] ------ desfire tests ------ [!] no space for crc. pos: 1 [=] crc16............. passed [!] no space for crc. pos: 2 [=] crc32............. passed [=] cmac subkeys...... passed [=] an10922 aes....... passed [=] an10922 2tdea..... passed [=] an10922 3tdea..... passed [=] cmac 3tdea........ passed [=] cmac 2tdea........ passed [=] cmac des.......... passed [=] ev2 session keys.. passed [=] ev2 iv calc....... passed [=] ev2 mac calc...... passed [=] trans session key. passed [=] --------------------------- [+] tests [ ok ] ======================================================================================= hf seos { seos rfids... } --------------------------------------------------------------------------------------- hf seos help available offline: yes help this help list list seos history --------------------------------------------------------------------------------------- hf seos info available offline: no get info from seos tags", "notes": [ "hf seos info" ], @@ -4977,17 +4979,20 @@ "command": "hf mfdes write", "description": "write data from file. key needs to be provided or flag --no-auth set (depend on file settings).", "notes": [ + "in the mode with commitreaderid to decode previous reader id command needs to read transaction counter via dump/read command and specify --trkey", + "", "hf mfdes write --aid 123456 --fid 01 -d 01020304 -> write file: app=123456, file=01, offset=0, get file type from card. use default channel settings from `default` command", "hf mfdes write --aid 123456 --fid 01 --type data -d 01020304 --0ffset 000100 -> write data to std file with offset 0x100", "hf mfdes write --aid 123456 --fid 01 --type data -d 01020304 --commit -> write data to backup file with commit", "hf mfdes write --aid 123456 --fid 01 --type value -d 00000001 -> increment value file", "hf mfdes write --aid 123456 --fid 01 --type value -d 00000001 --debit -> decrement value file", - "hf mfdes write --aid 123456 --fid 01 -d 01020304 -> write data to record file with `auto` type", + "hf mfdes write --aid 123456 --fid 01 -d 01020304 -> write data to file with `auto` type", "hf mfdes write --aid 123456 --fid 01 --type record -d 01020304 -> write data to record file", "hf mfdes write --aid 123456 --fid 01 --type record -d 01020304 --updaterec 0 -> update record in the record file. record 0 - lastest record.", "hf mfdes write --aid 123456 --fid 01 --type record --offset 000000 -d 11223344 -> write record to record file. use default channel settings from `default` command", "hf mfdes write --appisoid 1234 --fileisoid 1000 --type data -c iso -d 01020304 -> write data to std/backup file via iso commandset", - "hf mfdes write --appisoid 1234 --fileisoid 2000 --type record -c iso -d 01020304 -> aend record to record file via iso commandset" + "hf mfdes write --appisoid 1234 --fileisoid 2000 --type record -c iso -d 01020304 -> aend record to record file via iso commandset", + "hf mfdes write --aid 123456 --fid 01 -d 01020304 --readerid 010203 -> write data to file with commitreaderid command before write and committransaction after write" ], "offline": false, "options": [ @@ -5012,9 +5017,11 @@ "--commit commit needs for backup file only. for the other file types and in the `auto` mode - command set it automatically.", "--updaterec record number for update record command. updates record instead of write. lastest record - 0", "--appisoid application iso id (iso df id) (2 hex bytes, big endian). works only for iso read commands.", - "--fileisoid file iso id (iso df id) (2 hex bytes, big endian). works only for iso read commands." + "--fileisoid file iso id (iso df id) (2 hex bytes, big endian). works only for iso read commands.", + "--readerid reader id for commitreaderid command. if present - the command issued before write command.", + "--trkey key for decode previous reader id." ], - "usage": "hf mfdes write [-hav] [-n ] [-t ] [-k ] [-f ] [-i ] [-m ] [-c ] [-s ] [--aid ] [--fid ] [--no-auth] [--type ] [-o ] [-d ] [--debit] [--commit] [--updaterec ] [--appisoid ] [--fileisoid ]" + "usage": "hf mfdes write [-hav] [-n ] [-t ] [-k ] [-f ] [-i ] [-m ] [-c ] [-s ] [--aid ] [--fid ] [--no-auth] [--type ] [-o ] [-d ] [--debit] [--commit] [--updaterec ] [--appisoid ] [--fileisoid ] [--readerid ] [--trkey ]" }, "hf mfp auth": { "command": "hf mfp auth", @@ -9952,6 +9959,6 @@ "metadata": { "commands_extracted": 589, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2021-08-12T13:03:40" + "extracted_on": "2021-08-13T09:38:47" } } \ No newline at end of file