From 57234ba459a81c6a128750635b100c8c5bd10a1f Mon Sep 17 00:00:00 2001 From: klks Date: Mon, 25 May 2026 14:27:48 +0800 Subject: [PATCH] Merge down other commands, and update docs --- client/src/cmdhffmcos.c | 209 +++++++++----------------------- doc/fmcos.md | 154 ++++++++++++------------ doc/fmcos_example.md | 260 ++++++++++++++++++++-------------------- 3 files changed, 266 insertions(+), 357 deletions(-) diff --git a/client/src/cmdhffmcos.c b/client/src/cmdhffmcos.c index 646b3a244..6912c3043 100644 --- a/client/src/cmdhffmcos.c +++ b/client/src/cmdhffmcos.c @@ -713,7 +713,7 @@ static int CmdHFFmcosInfo(const char *Cmd) { } PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf fmcos select --id 3f00") "` to navigate the file system"); - PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf fmcos auth external --id 0 --key ffffffffffffffff") "` to authenticate"); + PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf fmcos authexternal --id 0 --key ffffffffffffffff") "` to authenticate"); PrintAndLogEx(NORMAL, ""); DropField(); @@ -829,17 +829,17 @@ static bool fmcos_parse_hex_int(const char *s, int *out) { } // --------------------------------------------------------------------------- -// hf fmcos auth external (Phase 2) +// hf fmcos authexternal (Phase 2) // --------------------------------------------------------------------------- static int CmdHFFmcosAuthExternal(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos auth external", + CLIParserInit(&ctx, "hf fmcos authexternal", "EXTERNAL AUTHENTICATE.\n" "Requests a challenge from the card, encrypts it with the provided\n" "DES (8-byte) or 3DES (16-byte) key, then sends EXTERNAL AUTHENTICATE.", - "hf fmcos auth external --id 0 --key ffffffffffffffff\n" - "hf fmcos auth external --id 1 --key 0102030405060708090a0b0c0d0e0f10"); + "hf fmcos authexternal --id 0 --key ffffffffffffffff\n" + "hf fmcos authexternal --id 1 --key 0102030405060708090a0b0c0d0e0f10"); void *argtable[] = { arg_param_begin, @@ -942,15 +942,15 @@ static int CmdHFFmcosAuthExternal(const char *Cmd) { } // --------------------------------------------------------------------------- -// hf fmcos auth internal (Phase 2) +// hf fmcos authinternal (Phase 2) // --------------------------------------------------------------------------- static int CmdHFFmcosAuthInternal(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos auth internal", + CLIParserInit(&ctx, "hf fmcos authinternal", "INTERNAL AUTHENTICATE.\n" "Sends a challenge to the card and the card proves it knows the key.", - "hf fmcos auth internal --p1 00 --p2 00 --data 0102030405060708"); + "hf fmcos authinternal --p1 00 --p2 00 --data 0102030405060708"); void *argtable[] = { arg_param_begin, @@ -1030,28 +1030,9 @@ static int CmdHFFmcosAuthInternal(const char *Cmd) { } // --------------------------------------------------------------------------- -// hf fmcos auth - sub-dispatcher (Phase 2) +// hf fmcos authexternal / authinternal (Phase 2) // --------------------------------------------------------------------------- -static int CmdHFFmcosAuthHelp(const char *Cmd); - -static command_t AuthCommandTable[] = { - {"help", CmdHFFmcosAuthHelp, AlwaysAvailable, "This help"}, - {"external", CmdHFFmcosAuthExternal, IfPm3Iso14443a, "EXTERNAL AUTHENTICATE using DES/3DES key"}, - {"internal", CmdHFFmcosAuthInternal, IfPm3Iso14443a, "INTERNAL AUTHENTICATE (card proves key knowledge)"}, - {NULL, NULL, NULL, NULL} -}; - -static int CmdHFFmcosAuthHelp(const char *Cmd) { - (void)Cmd; - CmdsHelp(AuthCommandTable); - return PM3_SUCCESS; -} - -static int CmdHFFmcosAuth(const char *Cmd) { - clearCommandBuffer(); - return CmdsParse(AuthCommandTable, Cmd); -} // --------------------------------------------------------------------------- // Phase 4 - File management @@ -1296,9 +1277,9 @@ static int CmdHFFmcosErase(const char *Cmd) { static int CmdHFFmcosCreateDir(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos create dir", + CLIParserInit(&ctx, "hf fmcos createdir", "CREATE DIRECTORY (DF) inside the currently selected directory", - "hf fmcos create dir --id 3F01 --space 200 --cperm F0 --eperm F0 --appid 95 --name 77616C6C6574546573740A"); + "hf fmcos createdir --id 3F01 --space 200 --cperm F0 --eperm F0 --appid 95 --name 77616C6C6574546573740A"); void *argtable[] = { arg_param_begin, arg_str1(NULL, "id", "<4hex>", "2-byte file ID"), @@ -1428,15 +1409,15 @@ static const CLIParserOption g_fmcos_baltype_opts[] = { static int CmdHFFmcosCreateFile(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos create file", + CLIParserInit(&ctx, "hf fmcos createfile", "CREATE EF in the current DF\n" "Types: bin(0x28) fix(0x2A) var(0x2C) loop(0x2E) wallet(0x2F)\n" "Prot: none mac(0x80) enc(0xC0) -- ORed into the type byte\n" "For wallet/passbook type: --rperm=usage rights, --wperm ignored (EDEP write always 0x00),\n" "--access=loop file link (low byte of the linked loop EF's file ID)", - "hf fmcos create file --id 0101 --type bin --size 32 --rperm FF --wperm FF --access 00\n" - "hf fmcos create file --id 0018 --type loop --size 0517 --rperm F0 --wperm EF --access FF\n" - "hf fmcos create file --id 0002 --type wallet --size 0208 --rperm F0 --wperm 00 --access 18"); + "hf fmcos createfile --id 0101 --type bin --size 32 --rperm FF --wperm FF --access 00\n" + "hf fmcos createfile --id 0018 --type loop --size 0517 --rperm F0 --wperm EF --access FF\n" + "hf fmcos createfile --id 0002 --type wallet --size 0208 --rperm F0 --wperm 00 --access 18"); void *argtable[] = { arg_param_begin, arg_str1(NULL, "id", "<4hex>", "2-byte file ID"), @@ -1550,9 +1531,9 @@ static int CmdHFFmcosCreateFile(const char *Cmd) { static int CmdHFFmcosCreateKeyfile(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos create keyfile", + CLIParserInit(&ctx, "hf fmcos createkeyfile", "CREATE KEYFILE in the current DF", - "hf fmcos create keyfile --id 0000 --space 200 --dfsid 95 --perm F0"); + "hf fmcos createkeyfile --id 0000 --space 200 --dfsid 95 --perm F0"); void *argtable[] = { arg_param_begin, arg_str1(NULL, "id", "<4hex>", "2-byte file ID (usually 0000)"), @@ -1640,39 +1621,18 @@ static int CmdHFFmcosCreateKeyfile(const char *Cmd) { return (sw1 == 0x90 && sw2 == 0x00) ? PM3_SUCCESS : PM3_ESOFT; } -static int CmdHFFmcosCreateHelp(const char *Cmd); - -static command_t CreateCommandTable[] = { - {"help", CmdHFFmcosCreateHelp, AlwaysAvailable, "This help"}, - {"dir", CmdHFFmcosCreateDir, IfPm3Iso14443a, "CREATE DIRECTORY (DF)"}, - {"file", CmdHFFmcosCreateFile, IfPm3Iso14443a, "CREATE EF (binary / fixed / variable / loop / wallet)"}, - {"keyfile", CmdHFFmcosCreateKeyfile, IfPm3Iso14443a, "CREATE KEYFILE"}, - {NULL, NULL, NULL, NULL} -}; - -static int CmdHFFmcosCreateHelp(const char *Cmd) { - (void)Cmd; - CmdsHelp(CreateCommandTable); - return PM3_SUCCESS; -} - -static int CmdHFFmcosCreate(const char *Cmd) { - clearCommandBuffer(); - return CmdsParse(CreateCommandTable, Cmd); -} - // --------------------------------------------------------------------------- // Phase 5 - Data access // --------------------------------------------------------------------------- static int CmdHFFmcosReadBinary(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos read binary", + CLIParserInit(&ctx, "hf fmcos readbinary", "READ BINARY from the current transparent EF\n" "p1/p2 encode the file offset (p1=offset_hi, p2=offset_lo).\n" "Protection: none(def) mac enc", - "hf fmcos read binary --p1 00 --p2 00 --len 16\n" - "hf fmcos read binary --p1 00 --p2 00 --len 16 --prot mac --key aabbccddeeff0011"); + "hf fmcos readbinary --p1 00 --p2 00 --len 16\n" + "hf fmcos readbinary --p1 00 --p2 00 --len 16 --prot mac --key aabbccddeeff0011"); void *argtable[] = { arg_param_begin, arg_str1(NULL, "p1", "", "P1 byte (offset high)"), @@ -1738,13 +1698,13 @@ static int CmdHFFmcosReadBinary(const char *Cmd) { static int CmdHFFmcosReadRecord(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos read record", + CLIParserInit(&ctx, "hf fmcos readrecord", "READ RECORD from the current record-based EF\n" "Protection: none(def) mac enc\n" "Use --tlv for variable-length (VAR) files: requests 2 extra bytes and strips the 00[len] TLV prefix from the response.", - "hf fmcos read record --rec 01 --fid 01 --len 20\n" - "hf fmcos read record --rec 01 --fid 06 --len 16 --tlv\n" - "hf fmcos read record --rec 01 --fid 01 --len 20 --prot mac --key aabbccddeeff0011"); + "hf fmcos readrecord --rec 01 --fid 01 --len 20\n" + "hf fmcos readrecord --rec 01 --fid 06 --len 16 --tlv\n" + "hf fmcos readrecord --rec 01 --fid 01 --len 20 --prot mac --key aabbccddeeff0011"); void *argtable[] = { arg_param_begin, arg_int1(NULL, "rec", "", "record number (1-based)"), @@ -1825,33 +1785,14 @@ static int CmdHFFmcosReadRecord(const char *Cmd) { return res; } -static int CmdHFFmcosReadHelp(const char *Cmd); - -static command_t ReadCommandTable[] = { - {"help", CmdHFFmcosReadHelp, AlwaysAvailable, "This help"}, - {"binary", CmdHFFmcosReadBinary, IfPm3Iso14443a, "READ BINARY from transparent EF"}, - {"record", CmdHFFmcosReadRecord, IfPm3Iso14443a, "READ RECORD from record-based EF"}, - {NULL, NULL, NULL, NULL} -}; - -static int CmdHFFmcosReadHelp(const char *Cmd) { - (void)Cmd; - CmdsHelp(ReadCommandTable); - return PM3_SUCCESS; -} - -static int CmdHFFmcosRead(const char *Cmd) { - clearCommandBuffer(); - return CmdsParse(ReadCommandTable, Cmd); -} static int CmdHFFmcosWriteBinary(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos write binary", + CLIParserInit(&ctx, "hf fmcos writebinary", "UPDATE BINARY in the current transparent EF\n" "Protection: none(def) mac enc", - "hf fmcos write binary --p1 00 --p2 00 --data 0102030405060708\n" - "hf fmcos write binary --p1 00 --p2 00 --data 01020304 --prot mac --key aabbccddeeff0011"); + "hf fmcos writebinary --p1 00 --p2 00 --data 0102030405060708\n" + "hf fmcos writebinary --p1 00 --p2 00 --data 01020304 --prot mac --key aabbccddeeff0011"); void *argtable[] = { arg_param_begin, arg_str1(NULL, "p1", "", "P1 byte (offset high)"), @@ -1934,13 +1875,13 @@ static int CmdHFFmcosWriteBinary(const char *Cmd) { static int CmdHFFmcosWriteRecord(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos write record", + CLIParserInit(&ctx, "hf fmcos writerecord", "UPDATE RECORD in the current record-based EF\n" "Protection: none(def) mac enc\n" "Use --tlv for variable-length (VAR) files: wraps data as 00[len][data] before sending.", - "hf fmcos write record --rec 01 --fid 01 --data 0102030405060708\n" - "hf fmcos write record --rec 01 --fid 06 --data 0102030405060708 --tlv\n" - "hf fmcos write record --rec 01 --fid 01 --data 01020304 --prot mac --key aabbccddeeff0011"); + "hf fmcos writerecord --rec 01 --fid 01 --data 0102030405060708\n" + "hf fmcos writerecord --rec 01 --fid 06 --data 0102030405060708 --tlv\n" + "hf fmcos writerecord --rec 01 --fid 01 --data 01020304 --prot mac --key aabbccddeeff0011"); void *argtable[] = { arg_param_begin, arg_int1(NULL, "rec", "", "record number (1-based)"), @@ -2043,25 +1984,6 @@ static int CmdHFFmcosWriteRecord(const char *Cmd) { return (sw1 == 0x90 && sw2 == 0x00) ? PM3_SUCCESS : PM3_ESOFT; } -static int CmdHFFmcosWriteHelp(const char *Cmd); - -static command_t WriteCommandTable[] = { - {"help", CmdHFFmcosWriteHelp, AlwaysAvailable, "This help"}, - {"binary", CmdHFFmcosWriteBinary, IfPm3Iso14443a, "UPDATE BINARY in transparent EF"}, - {"record", CmdHFFmcosWriteRecord, IfPm3Iso14443a, "UPDATE RECORD in record-based EF"}, - {NULL, NULL, NULL, NULL} -}; - -static int CmdHFFmcosWriteHelp(const char *Cmd) { - (void)Cmd; - CmdsHelp(WriteCommandTable); - return PM3_SUCCESS; -} - -static int CmdHFFmcosWrite(const char *Cmd) { - clearCommandBuffer(); - return CmdsParse(WriteCommandTable, Cmd); -} static int CmdHFFmcosAppend(const char *Cmd) { CLIParserContext *ctx; @@ -2284,7 +2206,7 @@ static int CmdHFFmcosWriteKey(const char *Cmd) { data[data_len++] = change_b[0]; data[data_len++] = version_b[0]; data[data_len++] = algo_b[0]; - // Group B-extauth: extauth + // Group B-extauth: extauth } else if (ktype == 0x39) { if (change_len != 1 || followup_len != 1 || errcnt_len != 1) { PrintAndLogEx(ERR, "extauth key type needs --change --followup --errcount"); @@ -2293,7 +2215,7 @@ static int CmdHFFmcosWriteKey(const char *Cmd) { data[data_len++] = change_b[0]; data[data_len++] = followup_b[0]; data[data_len++] = errcnt_b[0]; - // Group B-pin: pin + // Group B-pin: pin } else if (ktype == 0x3A) { if (followup_len != 1 || errcnt_len != 1) { PrintAndLogEx(ERR, "pin key type needs --followup --errcount"); @@ -2302,7 +2224,7 @@ static int CmdHFFmcosWriteKey(const char *Cmd) { data[data_len++] = 0xEF; data[data_len++] = followup_b[0]; data[data_len++] = errcnt_b[0]; - // Group C: lineprotect unlockpin changepin + // Group C: lineprotect unlockpin changepin } else if (ktype == 0x36 || ktype == 0x37 || ktype == 0x38) { if (change_len != 1 || errcnt_len != 1) { PrintAndLogEx(ERR, "This key type needs --change --errcount"); @@ -2361,10 +2283,10 @@ static int CmdHFFmcosWriteKey(const char *Cmd) { // VERIFY PIN (INS=20): present the PIN to the card. static int CmdHFFmcosPinVerify(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos pin verify", + CLIParserInit(&ctx, "hf fmcos pinverify", "VERIFY PIN (INS 20) - present PIN to the card", - "hf fmcos pin verify --id 00 --pin 123456\n" - "hf fmcos pin verify --id 00 --pin 1234"); + "hf fmcos pinverify --id 00 --pin 123456\n" + "hf fmcos pinverify --id 00 --pin 1234"); void *argtable[] = { arg_param_begin, arg_str1(NULL, "id", "", "key slot (P2), 1 byte"), @@ -2439,10 +2361,10 @@ static int CmdHFFmcosPinVerify(const char *Cmd) { // CHANGE PIN (INS=5E P1=01): present old PIN and new PIN. static int CmdHFFmcosPinChange(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos pin change", + CLIParserInit(&ctx, "hf fmcos pinchange", "CHANGE PIN (INS 5E P1=01) - change PIN with old PIN authorization\n" "Data sent: old_pin + 0xFF + new_pin", - "hf fmcos pin change --id 00 --old 123456 --new 13371337"); + "hf fmcos pinchange --id 00 --old 123456 --new 13371337"); void *argtable[] = { arg_param_begin, arg_str1(NULL, "id", "", "key slot (P2), 1 byte"), @@ -2532,10 +2454,10 @@ static int CmdHFFmcosPinChange(const char *Cmd) { // MAC = DES-MAC(new_pin, XOR(key_left, key_right)) static int CmdHFFmcosPinReset(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos pin reset", + CLIParserInit(&ctx, "hf fmcos pinreset", "RESET PIN (INS 5E P1=00) - set new PIN using change-PIN key\n" "Appends DES-MAC(new_pin, key_left XOR key_right) to the data.", - "hf fmcos pin reset --id 00 --pin 123456 --key aabbccddeeff001122334455667788aa"); + "hf fmcos pinreset --id 00 --pin 123456 --key aabbccddeeff001122334455667788aa"); void *argtable[] = { arg_param_begin, arg_str1(NULL, "id", "", "key slot (P2), 1 byte"), @@ -2635,10 +2557,10 @@ static int CmdHFFmcosPinReset(const char *Cmd) { // Data = encrypt([len|new_pin], unlock_key) + packet_mac(cla, ins, p1, p2, enc_data, chal_iv, unlock_key) static int CmdHFFmcosPinUnblock(const char *Cmd) { CLIParserContext *ctx; - CLIParserInit(&ctx, "hf fmcos pin unblock", + CLIParserInit(&ctx, "hf fmcos pinunblock", "UNBLOCK PIN (INS 24) - unblock a locked PIN using the unlock-PIN key\n" "Data = encrypt([len|new_pin], unlock_key) + packet_MAC", - "hf fmcos pin unblock --id 00 --pin 123456 --key aabbccddeeff001122334455667788aa"); + "hf fmcos pinunblock --id 00 --pin 123456 --key aabbccddeeff001122334455667788aa"); void *argtable[] = { arg_param_begin, arg_str1(NULL, "id", "", "PIN key slot (P1), 1 byte"), @@ -2744,27 +2666,6 @@ static int CmdHFFmcosPinUnblock(const char *Cmd) { return (sw1 == 0x90 && sw2 == 0x00) ? PM3_SUCCESS : PM3_ESOFT; } -static int CmdHFFmcosPinHelp(const char *Cmd); - -static command_t PinCommandTable[] = { - {"help", CmdHFFmcosPinHelp, AlwaysAvailable, "This help"}, - {"verify", CmdHFFmcosPinVerify, IfPm3Iso14443a, "VERIFY PIN (present PIN to card)"}, - {"change", CmdHFFmcosPinChange, IfPm3Iso14443a, "CHANGE PIN (old + new, requires old PIN)"}, - {"reset", CmdHFFmcosPinReset, IfPm3Iso14443a, "RESET PIN (new PIN + change-PIN key MAC)"}, - {"unblock", CmdHFFmcosPinUnblock, IfPm3Iso14443a, "UNBLOCK PIN (encrypted new PIN + MAC)"}, - {NULL, NULL, NULL, NULL} -}; - -static int CmdHFFmcosPinHelp(const char *Cmd) { - (void)Cmd; - CmdsHelp(PinCommandTable); - return PM3_SUCCESS; -} - -static int CmdHFFmcosPin(const char *Cmd) { - clearCommandBuffer(); - return CmdsParse(PinCommandTable, Cmd); -} // --------------------------------------------------------------------------- // Phase 7 helpers @@ -4250,7 +4151,7 @@ static int CmdHFFmcosTidCreateDF(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf fmcos tidcreatedf", "CREATE sub-DF using TID format (P1=01, FID in data).\n" - "Note: TID CREATE DF has a different layout from standard 'hf fmcos create dir'.", + "Note: TID CREATE DF has a different layout from standard 'hf fmcos createdir'.", "hf fmcos tidcreatedf --id 3f01 --size 0f00 --sfi 96 --name 44444630 31"); void *argtable[] = { arg_param_begin, @@ -4338,7 +4239,7 @@ static int CmdHFFmcosTidCreateBin(const char *Cmd) { CLIParserInit(&ctx, "hf fmcos tidcreatebin", "CREATE binary EF or KEYFILE using TID format (P1=02, FID in data, fixed Lc=11).\n" "Use --type keyfile to create the fixed TID keyfile in the currently selected DF.\n" - "Note: TID CREATE EF has a different layout from standard 'hf fmcos create file'.", + "Note: TID CREATE EF has a different layout from standard 'hf fmcos createfile'.", "hf fmcos tidcreatebin --id 0001 --size 0100 --sfi 01\n" "hf fmcos tidcreatebin --id 0002 --size 0040 --sfi 02 --rperm 20 --wperm f0\n" "hf fmcos tidcreatebin --type keyfile"); @@ -4450,7 +4351,7 @@ static int CmdHFFmcosTidCreateRec(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf fmcos tidcreaterec", "CREATE fixed-length record EF using TID format (P1=02, subtype=01, FID in data, fixed Lc=11).\n" - "Note: TID CREATE EF has a different layout from standard 'hf fmcos create file'.", + "Note: TID CREATE EF has a different layout from standard 'hf fmcos createfile'.", "hf fmcos tidcreaterec --id 0003 --count 04 --reclen 08 --sfi 03\n" "hf fmcos tidcreaterec --id 0003 --count 04 --reclen 10 --sfi 03 --rperm 20 --wperm f0"); void *argtable[] = { @@ -4556,16 +4457,24 @@ static command_t CommandTable[] = { {"select", CmdHFFmcosSelect, IfPm3Iso14443a, "SELECT FILE by 2-byte ID or AID name"}, {"--------", CmdHelp, AlwaysAvailable, "--------- " _CYAN_("File management") " ----------"}, {"erase", CmdHFFmcosErase, IfPm3Iso14443a, "ERASE DF contents"}, - {"create", CmdHFFmcosCreate, IfPm3Iso14443a, "{ Create directory / EF / keyfile... }"}, + {"createdir", CmdHFFmcosCreateDir, IfPm3Iso14443a, "CREATE DIRECTORY (DF)"}, + {"createfile", CmdHFFmcosCreateFile, IfPm3Iso14443a, "CREATE EF (binary / fixed / variable / loop / wallet)"}, + {"createkeyfile", CmdHFFmcosCreateKeyfile, IfPm3Iso14443a, "CREATE KEYFILE"}, {"--------", CmdHelp, AlwaysAvailable, "--------- " _CYAN_("Data access") " --------------"}, - {"read", CmdHFFmcosRead, IfPm3Iso14443a, "{ Read binary / record... }"}, - {"write", CmdHFFmcosWrite, IfPm3Iso14443a, "{ Write binary / record... }"}, + {"readbinary", CmdHFFmcosReadBinary, IfPm3Iso14443a, "READ BINARY from transparent EF"}, + {"readrecord", CmdHFFmcosReadRecord, IfPm3Iso14443a, "READ RECORD from record-based EF"}, + {"writebinary", CmdHFFmcosWriteBinary, IfPm3Iso14443a, "UPDATE BINARY in transparent EF"}, + {"writerecord", CmdHFFmcosWriteRecord, IfPm3Iso14443a, "UPDATE RECORD in record-based EF"}, {"append", CmdHFFmcosAppend, IfPm3Iso14443a, "APPEND RECORD to cyclic / linear EF"}, {"--------", CmdHelp, AlwaysAvailable, "--------- " _CYAN_("Authentication") " -----------"}, - {"auth", CmdHFFmcosAuth, IfPm3Iso14443a, "{ External / internal authenticate... }"}, + {"authexternal", CmdHFFmcosAuthExternal, IfPm3Iso14443a, "EXTERNAL AUTHENTICATE using DES/3DES key"}, + {"authinternal", CmdHFFmcosAuthInternal, IfPm3Iso14443a, "INTERNAL AUTHENTICATE (card proves key knowledge)"}, {"key", CmdHFFmcosWriteKey, IfPm3Iso14443a, "WRITE KEY to keyfile"}, {"--------", CmdHelp, AlwaysAvailable, "--------- " _CYAN_("PIN management") " -----------"}, - {"pin", CmdHFFmcosPin, IfPm3Iso14443a, "{ Verify / change / reset / unblock PIN }"}, + {"pinverify", CmdHFFmcosPinVerify, IfPm3Iso14443a, "VERIFY PIN (present PIN to card)"}, + {"pinchange", CmdHFFmcosPinChange, IfPm3Iso14443a, "CHANGE PIN (old + new, requires old PIN)"}, + {"pinreset", CmdHFFmcosPinReset, IfPm3Iso14443a, "RESET PIN (new PIN + change-PIN key MAC)"}, + {"pinunblock", CmdHFFmcosPinUnblock, IfPm3Iso14443a, "UNBLOCK PIN (encrypted new PIN + MAC)"}, {"--------", CmdHelp, AlwaysAvailable, "--------- " _CYAN_("Financial") " ----------------"}, {"balance", CmdHFFmcosBalance, IfPm3Iso14443a, "GET BALANCE (wallet or passbook)"}, {"credit", CmdHFFmcosCredit, IfPm3Iso14443a, "ADD CREDIT to wallet or passbook"}, diff --git a/doc/fmcos.md b/doc/fmcos.md index 1eb2047d6..0316f4678 100644 --- a/doc/fmcos.md +++ b/doc/fmcos.md @@ -15,24 +15,24 @@ All commands in this family are reachable via `hf fmcos `. - [select](#select) - [File Management](#file-management) - [erase](#erase) - - [create dir](#create-dir) - - [create file](#create-file) - - [create keyfile](#create-keyfile) + - [createdir](#createdir) + - [createfile](#createfile) + - [createkeyfile](#createkeyfile) - [Data Access](#data-access) - - [read binary](#read-binary) - - [read record](#read-record) - - [write binary](#write-binary) - - [write record](#write-record) + - [readbinary](#readbinary) + - [readrecord](#readrecord) + - [writebinary](#writebinary) + - [writerecord](#writerecord) - [append](#append) - [key (write key)](#key-write-key) - [Authentication](#authentication) - - [auth external](#auth-external) - - [auth internal](#auth-internal) + - [authexternal](#authexternal) + - [authinternal](#authinternal) - [PIN Management](#pin-management) - - [pin verify](#pin-verify) - - [pin change](#pin-change) - - [pin reset](#pin-reset) - - [pin unblock](#pin-unblock) + - [pinverify](#pinverify) + - [pinchange](#pinchange) + - [pinreset](#pinreset) + - [pinunblock](#pinunblock) - [Financial Operations](#financial-operations) - [balance](#balance) - [credit](#credit) @@ -102,12 +102,12 @@ hf fmcos select --id 3f00 hf fmcos erase ``` -### create dir +### createdir CREATE DF (directory / application directory). ``` -hf fmcos create dir --id 3f01 --space 1500 --cperm f0 --eperm f0 --appid 95 --name 77616C6C657454657374 +hf fmcos createdir --id 3f01 --space 1500 --cperm f0 --eperm f0 --appid 95 --name 77616C6C657454657374 ``` | Flag | Description | @@ -119,22 +119,22 @@ hf fmcos create dir --id 3f01 --space 1500 --cperm f0 --eperm f0 --appid 95 --na | `--appid ` | 1-byte application SID / AID tag | | `--name ` | Optional DF name bytes as hex (up to 16 bytes, enables select-by-name) | -### create file +### createfile CREATE EF (elementary file) in the currently selected DF. ``` # Unprotected binary file -hf fmcos create file --id 0002 --type bin --size 50 --rperm f0 --wperm f0 --access ff +hf fmcos createfile --id 0002 --type bin --size 50 --rperm f0 --wperm f0 --access ff # Variable-length record file with MAC-only line protection -hf fmcos create file --id 0006 --type var --size 50 --rperm f0 --wperm f0 --access 7f --prot mac +hf fmcos createfile --id 0006 --type var --size 50 --rperm f0 --wperm f0 --access 7f --prot mac # Loop (cyclic) file with MAC+encryption -hf fmcos create file --id 000a --type loop --size 210 --rperm f0 --wperm f0 --access 7f --prot enc +hf fmcos createfile --id 000a --type loop --size 210 --rperm f0 --wperm f0 --access 7f --prot enc # Wallet/passbook balance file (EDEP) linked to loop file 0x0018 -hf fmcos create file --id 0002 --type wallet --size 0208 --rperm f0 --wperm 00 --access 18 +hf fmcos createfile --id 0002 --type wallet --size 0208 --rperm f0 --wperm 00 --access 18 ``` | Flag | Description | @@ -231,13 +231,13 @@ have its low nibble set to `4` (`0x04` plain, `0x84` for ISO-secure) when line p | `loop` | 0x2E | Cyclic (loop) file -- used for transaction logs | | `wallet` | 0x2F | E-purse wallet / passbook balance file | -### create keyfile +### createkeyfile CREATE KEYFILE in the currently selected DF. A DF must have a keyfile before any keys can be written to it. ``` -hf fmcos create keyfile --id 0000 --space 200 --dfsid 95 --perm f0 +hf fmcos createkeyfile --id 0000 --space 200 --dfsid 95 --perm f0 ``` | Flag | Description | @@ -278,19 +278,19 @@ Common values: ## Data Access -### read binary +### readbinary READ BINARY from the currently selected transparent (bin) EF. ``` # Plain read -hf fmcos read binary --p1 00 --p2 00 --len 10 +hf fmcos readbinary --p1 00 --p2 00 --len 10 # With MAC line-protection (verifies response MAC) -hf fmcos read binary --p1 00 --p2 00 --len 10 --prot mac --key 36363636363636363636363636363636 +hf fmcos readbinary --p1 00 --p2 00 --len 10 --prot mac --key 36363636363636363636363636363636 # With MAC+encryption (decrypts response) -hf fmcos read binary --p1 00 --p2 00 --len 10 --prot enc --key 36363636363636363636363636363636 +hf fmcos readbinary --p1 00 --p2 00 --len 10 --prot enc --key 36363636363636363636363636363636 ``` | Flag | Description | @@ -301,19 +301,19 @@ hf fmcos read binary --p1 00 --p2 00 --len 10 --prot enc --key 36363636363636363 | `--prot ` | `none`, `mac`, or `enc` | | `--key ` | Line-protection key (8 or 16 bytes, required when `--prot` is mac/enc) | -### read record +### readrecord READ RECORD from the currently selected record or cyclic EF. ``` # Read record 1 from var file 0x06 (plain) -hf fmcos read record --rec 01 --fid 06 --len 10 +hf fmcos readrecord --rec 01 --fid 06 --len 10 # Read with MAC verification -hf fmcos read record --rec 01 --fid 07 --len 10 --prot mac --key 36363636363636363636363636363636 +hf fmcos readrecord --rec 01 --fid 07 --len 10 --prot mac --key 36363636363636363636363636363636 # Read with decryption -hf fmcos read record --rec 01 --fid 08 --len 10 --prot enc --key 36363636363636363636363636363636 +hf fmcos readrecord --rec 01 --fid 08 --len 10 --prot enc --key 36363636363636363636363636363636 ``` | Flag | Description | @@ -324,20 +324,20 @@ hf fmcos read record --rec 01 --fid 08 --len 10 --prot enc --key 363636363636363 | `--prot ` | `none`, `mac`, or `enc` | | `--key ` | Line-protection key when prot is mac/enc | -### write binary +### writebinary UPDATE BINARY -- write data to the currently selected transparent EF. ``` # Plain write -hf fmcos write binary --p1 00 --p2 00 --data 11121314151617181910 +hf fmcos writebinary --p1 00 --p2 00 --data 11121314151617181910 # Write with MAC -hf fmcos write binary --p1 00 --p2 00 --data 21222324252627282920 \ +hf fmcos writebinary --p1 00 --p2 00 --data 21222324252627282920 \ --prot mac --key 36363636363636363636363636363636 # Write with MAC+encryption (data is encrypted before sending) -hf fmcos write binary --p1 00 --p2 00 --data 31323334353637383930 \ +hf fmcos writebinary --p1 00 --p2 00 --data 31323334353637383930 \ --prot enc --key 36363636363636363636363636363636 ``` @@ -349,20 +349,20 @@ hf fmcos write binary --p1 00 --p2 00 --data 31323334353637383930 \ | `--prot ` | `none`, `mac`, or `enc` | | `--key ` | Line-protection key | -### write record +### writerecord UPDATE RECORD -- write a record into the currently selected EF. ``` # Plain record write (P1=record number, P2=file-id<<3|04) -hf fmcos write record --rec 01 --fid 06 --data 5152535455565758595a +hf fmcos writerecord --rec 01 --fid 06 --data 5152535455565758595a # With MAC -hf fmcos write record --rec 01 --fid 07 --data 6162636465666768696a \ +hf fmcos writerecord --rec 01 --fid 07 --data 6162636465666768696a \ --prot mac --key 36363636363636363636363636363636 # With MAC+encryption -hf fmcos write record --rec 01 --fid 08 --data 7172737475767778797a \ +hf fmcos writerecord --rec 01 --fid 08 --data 7172737475767778797a \ --prot enc --key 36363636363636363636363636363636 ``` @@ -477,13 +477,13 @@ hf fmcos key --op 01 --id 00 --type changepin \ ## Authentication -### auth external +### authexternal EXTERNAL AUTHENTICATE -- authenticate the reader to the card. The card issues a challenge, the reader encrypts it with the external-auth key, and sends the response back. ``` -hf fmcos auth external --id 00 --key f49dc1ba1b4deb5264718bc559106c0d +hf fmcos authexternal --id 00 --key f49dc1ba1b4deb5264718bc559106c0d ``` | Flag | Description | @@ -491,14 +491,14 @@ hf fmcos auth external --id 00 --key f49dc1ba1b4deb5264718bc559106c0d | `--id ` | Key slot ID | | `--key ` | External-auth key (8 or 16 bytes) | -### auth internal +### authinternal INTERNAL AUTHENTICATE -- authenticate the card to the reader. The reader sends an 8-byte challenge (`--data`); the card responds with a DES-encrypted value that the reader verifies offline. ``` -hf fmcos auth internal --p1 00 --p2 00 --data 0102030405060708 +hf fmcos authinternal --p1 00 --p2 00 --data 0102030405060708 ``` | Flag | Description | @@ -511,13 +511,13 @@ hf fmcos auth internal --p1 00 --p2 00 --data 0102030405060708 ## PIN Management -### pin verify +### pinverify VERIFY PIN -- present the PIN code to the card to unlock PIN-gated operations. PIN is 2-6 raw bytes. ``` -hf fmcos pin verify --id 00 --pin 123456 +hf fmcos pinverify --id 00 --pin 123456 ``` | Flag | Description | @@ -525,12 +525,12 @@ hf fmcos pin verify --id 00 --pin 123456 | `--id ` | PIN key slot ID | | `--pin ` | PIN bytes (2-6 bytes) | -### pin change +### pinchange CHANGE PIN -- change the PIN using the current (old) PIN for authorization. ``` -hf fmcos pin change --id 00 --old 123456 --new 13371337 +hf fmcos pinchange --id 00 --old 123456 --new 13371337 ``` | Flag | Description | @@ -539,13 +539,13 @@ hf fmcos pin change --id 00 --old 123456 --new 13371337 | `--old ` | Current PIN (2-6 bytes) | | `--new ` | New PIN (2-6 bytes) | -### pin reset +### pinreset RESET PIN -- set a new PIN using the change-PIN key MAC for authorization (no old PIN needed). The command computes a MAC over the new PIN using the change-PIN key and sends it to the card. ``` -hf fmcos pin reset --id 00 --pin 13371337 \ +hf fmcos pinreset --id 00 --pin 13371337 \ --key fb487a6d1b7cbf1bf84c666b8338376e ``` @@ -555,13 +555,13 @@ hf fmcos pin reset --id 00 --pin 13371337 \ | `--pin ` | New PIN (2-6 bytes) | | `--key ` | Change-PIN key (16 bytes); MAC = DES-MAC(new_pin, XOR_halves(key)) | -### pin unblock +### pinunblock UNBLOCK PIN -- clear the PIN blocked state and set a new PIN. The new PIN is encrypted with the unlock-PIN key and a GET CHALLENGE IV. ``` -hf fmcos pin unblock --id 00 --pin 123456 \ +hf fmcos pinunblock --id 00 --pin 123456 \ --key d8f60fa2d791f3a658d27c054582430e ``` @@ -974,7 +974,7 @@ over `CLA|INS|P1|P2|Lc[|data]` with a GET CHALLENGE response as the CBC IV. ## Access Rights Byte -The access-rights byte passed to `create file` controls whether line protection is needed +The access-rights byte passed to `createfile` controls whether line protection is needed and which key slot guards read / write access. ``` @@ -1001,7 +1001,7 @@ allows custom UID. These commands below allow a TID tag to be provisioned - UID, auth key, and file system, these commands are not the same as the standard fmcos commands. These cards can often be found on taobao by searching for "CPU TID card". -When hf fmcos auth external is called with any key, the card will always return +When hf fmcos authexternal is called with any key, the card will always return [+] SW: 9000 - Success [+] External authentication successful @@ -1123,13 +1123,13 @@ hf fmcos tidprovision --uid 13371337 --key 1122334455667788 --lock | `-k` / `--keep` | Keep field on after completion | After `tidprovision`, use `tidcreatedf` / `tidcreatebin` / `tidcreaterec` to build -the file structure, then `hf fmcos write binary` / `hf fmcos write record` to populate data. +the file structure, then `hf fmcos writebinary` / `hf fmcos writerecord` to populate data. --- ### tidcreatedf -CREATE a sub-DF using the TID APDU format. The standard `hf fmcos create dir` uses a +CREATE a sub-DF using the TID APDU format. The standard `hf fmcos createdir` uses a different data layout (FID in P1/P2, leading `0x38` byte); this command uses the TID layout where P1=`0x01` and the FID is the first field in the data. @@ -1151,7 +1151,7 @@ hf fmcos tidcreatedf --id 3f01 --size 0f00 --sfi 96 --name 444446303133 ### tidcreatebin -CREATE a binary EF or KEYFILE using the TID APDU format. The standard `hf fmcos create file --type bin` +CREATE a binary EF or KEYFILE using the TID APDU format. The standard `hf fmcos createfile --type bin` uses a different layout (FID in P1/P2, 7-byte payload); this command uses the TID layout where P1=`0x02` and the FID is in the data with a fixed 11-byte payload. @@ -1182,7 +1182,7 @@ hf fmcos tidcreatebin --type keyfile ### tidcreaterec -CREATE a fixed-length record EF using the TID APDU format. The standard `hf fmcos create file --type fix` +CREATE a fixed-length record EF using the TID APDU format. The standard `hf fmcos createfile --type fix` uses a different layout; this command uses the TID layout where P1=`0x02`, subtype=`0x01`, and count+reclen replace the size field. @@ -1203,8 +1203,8 @@ hf fmcos tidcreaterec --id 0003 --count 04 --reclen 10 --sfi 03 --rperm 20 --wpe **APDU:** `80 E0 02 00 0B 01 [fid_hi][fid_lo] [count][reclen] [rperm][wperm] [sfi] 00 FF 00` -> **Note**: To write data into TID EFs after creation, use the standard `hf fmcos write binary` -> and `hf fmcos write record` - those APDUs (`00 D6` / `00 DC`) are identical in TID and standard FMCOS. +> **Note**: To write data into TID EFs after creation, use the standard `hf fmcos writebinary` +> and `hf fmcos writerecord` - those APDUs (`00 D6` / `00 DC`) are identical in TID and standard FMCOS. --- @@ -1220,7 +1220,7 @@ normally provided when you buy these TID cards. command finishes without `-k` the field drops and the card resets to MF context on the next activation. - Each sub-DF requires a TID-format keyfile created immediately after selecting it. Use - `hf fmcos tidcreatebin --type keyfile` - the standard `hf fmcos create keyfile` uses a + `hf fmcos tidcreatebin --type keyfile` - the standard `hf fmcos createkeyfile` uses a different APDU layout and cannot create TID keyfiles. --- @@ -1239,12 +1239,12 @@ hf fmcos tidcreatedf --id 7572 --size 0200 --sfi 02 --name 390130990807 -k hf fmcos select --id 7572 -k hf fmcos tidcreatebin --type keyfile -k hf fmcos tidcreaterec --id 0001 --count 06 --reclen 10 --sfi 03 -k -hf fmcos write record --rec 01 --fid 03 --data 018609DD110000000000010100000000 -k -hf fmcos write record --rec 02 --fid 03 --data 00000000000000000000000000000000 -k -hf fmcos write record --rec 03 --fid 03 --data 0000000000070A0D1707120000008800 -k -hf fmcos write record --rec 04 --fid 03 --data 00000000000000000000000000000000 -k -hf fmcos write record --rec 05 --fid 03 --data 00000000000000000000000000000000 -k -hf fmcos write record --rec 06 --fid 03 --data 00000000000000000000000000000000 +hf fmcos writerecord --rec 01 --fid 03 --data 018609DD110000000000010100000000 -k +hf fmcos writerecord --rec 02 --fid 03 --data 00000000000000000000000000000000 -k +hf fmcos writerecord --rec 03 --fid 03 --data 0000000000070A0D1707120000008800 -k +hf fmcos writerecord --rec 04 --fid 03 --data 00000000000000000000000000000000 -k +hf fmcos writerecord --rec 05 --fid 03 --data 00000000000000000000000000000000 -k +hf fmcos writerecord --rec 06 --fid 03 --data 00000000000000000000000000000000 ``` --- @@ -1265,10 +1265,10 @@ hf fmcos select --id 1001 -k hf fmcos tidcreatebin --type keyfile -k hf fmcos tidcreatebin --id 0018 --size 008C --sfi 18 -k hf fmcos select --id 0018 -k -hf fmcos write binary --p1 00 --p2 00 --data 001FD921090700000001000023590000000000E0FFFFFF7F0700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -k +hf fmcos writebinary --p1 00 --p2 00 --data 001FD921090700000001000023590000000000E0FFFFFF7F0700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -k hf fmcos tidcreatebin --id 0019 --size 008C --sfi 19 -k hf fmcos select --id 0019 -k -hf fmcos write binary --p1 00 --p2 00 --data 001FD921090700000001000023590000FFFFFFFFFFFF010000000000E0FFFFFF0F0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +hf fmcos writebinary --p1 00 --p2 00 --data 001FD921090700000001000023590000FFFFFFFFFFFF010000000000E0FFFFFF0F0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ``` --- @@ -1288,7 +1288,7 @@ hf fmcos select --id 4A54 -k hf fmcos tidcreatebin --type keyfile -k hf fmcos tidcreatebin --id 4200 --size 0270 --sfi 01 -k hf fmcos select --id 4200 -k -hf fmcos write binary --p1 02 --p2 50 --data 530030FFFFFFFFFFFFFF3A2B0000000022012200002403081106000000007F00 +hf fmcos writebinary --p1 02 --p2 50 --data 530030FFFFFFFFFFFFFF3A2B0000000022012200002403081106000000007F00 ``` --- @@ -1314,19 +1314,19 @@ hf fmcos tidcreatebin --type keyfile -k hf fmcos tidcreatebin --id 0001 --size 0001 --sfi 01 -k hf fmcos tidcreatebin --id 0003 --size 001C --sfi 03 -k hf fmcos select --id 0003 -k -hf fmcos write binary --p1 00 --p2 00 --data FE937B922D7EDEF50000000000000000000000000000000000000000 -k +hf fmcos writebinary --p1 00 --p2 00 --data FE937B922D7EDEF50000000000000000000000000000000000000000 -k hf fmcos tidcreatebin --id 0004 --size 0078 --sfi 04 -k hf fmcos select --id 0004 -k -hf fmcos write binary --p1 00 --p2 00 --data 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -k +hf fmcos writebinary --p1 00 --p2 00 --data 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -k hf fmcos tidcreatebin --id 0005 --size 0024 --sfi 05 -k hf fmcos select --id 0005 -k -hf fmcos write binary --p1 00 --p2 00 --data 6403FE9C7434FCBC6E00FC9F2802F1448F06F3BA8CF6F0B98DF7F1B84D0BF60000000000 -k +hf fmcos writebinary --p1 00 --p2 00 --data 6403FE9C7434FCBC6E00FC9F2802F1448F06F3BA8CF6F0B98DF7F1B84D0BF60000000000 -k hf fmcos tidcreatebin --id 0006 --size 0084 --sfi 06 -k hf fmcos select --id 0006 -k -hf fmcos write binary --p1 00 --p2 00 --data 616BEACE7705FCBD7604FDBC7107F2BB7006F3BA7309F0B97208F1B84D0B09B74C0AF7494F0DF4B5B10CF5B449F0EAB3480E14B24B31E84E4A30E9B0BA33EEAF44CDEFAE473513AD4634ED534137E2ABBF36E3AA43C6E0A942381EA85D3BE6585C3AE7A6A03DE4A55E000000000000000000000000000000000000000000000000000000 -k +hf fmcos writebinary --p1 00 --p2 00 --data 616BEACE7705FCBD7604FDBC7107F2BB7006F3BA7309F0B97208F1B84D0B09B74C0AF7494F0DF4B5B10CF5B449F0EAB3480E14B24B31E84E4A30E9B0BA33EEAF44CDEFAE473513AD4634ED534137E2ABBF36E3AA43C6E0A942381EA85D3BE6585C3AE7A6A03DE4A55E000000000000000000000000000000000000000000000000000000 -k hf fmcos tidcreatebin --id 0007 --size 0066 --sfi 07 -k hf fmcos select --id 0007 -k -hf fmcos write binary --p1 00 --p2 00 --data 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +hf fmcos writebinary --p1 00 --p2 00 --data 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ``` --- @@ -1348,13 +1348,13 @@ hf fmcos select --id D0F1 -k hf fmcos tidcreatebin --type keyfile -k hf fmcos tidcreatebin --id 0005 --size 0040 --sfi 05 -k hf fmcos select --id 0005 -k -hf fmcos write binary --p1 00 --p2 00 --data 0200FC20006200000000000000000000000000272E2C6A0000000000000000080000000000000000000000000000000000000000000000000000000000000000 +hf fmcos writebinary --p1 00 --p2 00 --data 0200FC20006200000000000000000000000000272E2C6A0000000000000000080000000000000000000000000000000000000000000000000000000000000000 hf fmcos tidcreatedf --id D0F2 --size 0100 --sfi 02 --name 584C343536 -k hf fmcos select --id D0F2 -k hf fmcos tidcreatebin --type keyfile -k hf fmcos tidcreatebin --id 0005 --size 0040 --sfi 05 -k hf fmcos select --id 0005 -k -hf fmcos write binary --p1 00 --p2 00 --data 0200FC20006200000000000000000000000000272E2C6A0000000000000000080000000000000000000000000000000000000000000000000000000000000000 +hf fmcos writebinary --p1 00 --p2 00 --data 0200FC20006200000000000000000000000000272E2C6A0000000000000000080000000000000000000000000000000000000000000000000000000000000000 ``` --- @@ -1374,6 +1374,6 @@ hf fmcos select --id 3F01 -k hf fmcos tidcreatebin --type keyfile -k hf fmcos tidcreatebin --id 0003 --size 00FA --sfi 03 -k hf fmcos select --id 0003 -k -hf fmcos write binary --p1 00 --p2 00 --data D15190D7E1E379732295C97D62A3172BE3BBA1D1B32CE32FED72CB3DCDB115E7DC2670978E241822F298C9951260FC55D54F9988C7FCAC5032F94281DFC39C973E570101764D5BBF367F84EBDA1B012ABD4568F35D5BC08BAFD76B988CA916C985692337FCF02C9FD2C8BDD583BC05EF55582C3921FA2CAFAE26308FBADE0598DB750EE1F0522D29EAB6FA5D0F3971F785692337FCF02C9FD2C8BDD583BC05EF55582C3921FA2CAFAE26308FBADE0598DB750EE1F0522D29EAB6FA5D0F3971F7EA545FC5B27B7F40DF6D0F71FCEE2A1BCED2DEDE67BB57B1C1F98C8CDA5259CC7BD83158086F215F5E1E0246EE0504760000000000 -k -hf fmcos write binary --p1 00 --p2 F5 --data 0000000000 +hf fmcos writebinary --p1 00 --p2 00 --data D15190D7E1E379732295C97D62A3172BE3BBA1D1B32CE32FED72CB3DCDB115E7DC2670978E241822F298C9951260FC55D54F9988C7FCAC5032F94281DFC39C973E570101764D5BBF367F84EBDA1B012ABD4568F35D5BC08BAFD76B988CA916C985692337FCF02C9FD2C8BDD583BC05EF55582C3921FA2CAFAE26308FBADE0598DB750EE1F0522D29EAB6FA5D0F3971F785692337FCF02C9FD2C8BDD583BC05EF55582C3921FA2CAFAE26308FBADE0598DB750EE1F0522D29EAB6FA5D0F3971F7EA545FC5B27B7F40DF6D0F71FCEE2A1BCED2DEDE67BB57B1C1F98C8CDA5259CC7BD83158086F215F5E1E0246EE0504760000000000 -k +hf fmcos writebinary --p1 00 --p2 F5 --data 0000000000 ``` diff --git a/doc/fmcos_example.md b/doc/fmcos_example.md index 9dda57ff5..3f000cf0e 100644 --- a/doc/fmcos_example.md +++ b/doc/fmcos_example.md @@ -26,7 +26,7 @@ Add `-k` (keep field on) to every command in a chain except the last one. --- -## 1. reset — select MF and erase DF +## 1. reset - select MF and erase DF Select the Master File then erase the application directory from a previous run: @@ -41,7 +41,7 @@ itself cannot be erased this way). --- -## 2. setup — create directory, keyfile, keys, loop files, balance files +## 2. setup - create directory, keyfile, keys, loop files, balance files ### 2a. Create the application directory (ADF) @@ -52,7 +52,7 @@ itself cannot be erased this way). ``` hf fmcos select --id 3f00 -k -hf fmcos create dir --id 3F01 --space 1500 --cperm F0 --eperm F0 --appid 95 --name 77616C6C657454657374 -k +hf fmcos createdir --id 3F01 --space 1500 --cperm F0 --eperm F0 --appid 95 --name 77616C6C657454657374 -k ``` ### 2b. Select the new ADF by name @@ -66,7 +66,7 @@ All subsequent setup commands assume this DF remains selected (field stays on). ### 2c. Create the keyfile ``` -hf fmcos create keyfile --id 0000 --space 200 --dfsid 95 --perm F0 -k +hf fmcos createkeyfile --id 0000 --space 200 --dfsid 95 --perm F0 -k ``` ### 2d. Write keys @@ -77,74 +77,74 @@ hf fmcos create keyfile --id 0000 --space 200 --dfsid 95 --perm F0 -k All key writes continue in the same session so every command carries `-k`. -**Key 0 — DES Encrypt (int_enc)** +**Key 0 - DES Encrypt (int_enc)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type desenc --change F4 --version 05 --algo 98 --key c4608b786af1992343e91a076670ae7c -k ``` -**Key 1 — DES Decrypt (int_dec)** +**Key 1 - DES Decrypt (int_dec)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type desdec --change F4 --version 05 --algo 98 --key b8d4190c76856901fc686f36ab9b1ce0 -k ``` -**Key 2 — DES MAC (int_mac)** +**Key 2 - DES MAC (int_mac)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type desmac --change F4 --version 05 --algo 98 --key 46a3ea8b254ee2749cc681050fd0dbcc -k ``` -**Key 3 — Internal Key (internal_key)** +**Key 3 - Internal Key (internal_key)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type internal --change 02 --version 00 --algo 01 --key 2b8a438742c851566f02d881b09d58c0 -k ``` -**Key 4 — File Line Protection Key (line_protection_key)** +**Key 4 - File Line Protection Key (line_protection_key)** -Group C type — uses `--change` and `--errcount`. +Group C type - uses `--change` and `--errcount`. ``` hf fmcos key --op 01 --id 00 --usage F0 --type lineprotect --change 02 --errcount 33 --key 8a021972bfec9d152ca9eb82d7d12c09 -k ``` -**Key 5 — Unlock PIN Key (unlock_pin_key)** +**Key 5 - Unlock PIN Key (unlock_pin_key)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type unlockpin --change 02 --errcount 33 --key d8f60fa2d791f3a658d27c05458243ed -k ``` -**Key 6 — Change PIN Key (change_pin_key)** +**Key 6 - Change PIN Key (change_pin_key)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type changepin --change 02 --errcount 33 --key fb487a6d1b7cbf1bf84c666b8338376e -k ``` -**Key 7 — External Authentication Key (external_auth_key)** +**Key 7 - External Authentication Key (external_auth_key)** -Group B type with `--change` — uses `--change`, `--followup`, and `--errcount`. +Group B type with `--change` - uses `--change`, `--followup`, and `--errcount`. ``` hf fmcos key --op 01 --id 00 --usage F0 --type extauth --change 02 --followup 44 --errcount 33 --key f49dc1ba1b4deb52647186bc59106c0d -k ``` -**Key 8 — Purchase Key (purchase_key)** +**Key 8 - Purchase Key (purchase_key)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type purchase --change 02 --version 00 --algo 01 --key eb18ce6986c820970e876219052ce0cf -k ``` -**Key 9 — Credit Key (credit_key)** +**Key 9 - Credit Key (credit_key)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type credit --change 02 --version 00 --algo 01 --key a9e6e145f5df09500a58eef8575d49db -k ``` -**Key 10 — Debit Key (debit_key)** +**Key 10 - Debit Key (debit_key)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type debit --change 02 --version 00 --algo 01 --key 97fb4eda4b5237035946ee62d325d909 -k ``` -**Key 11 — Overdraw Limit Key (overdraw_limit_key)** +**Key 11 - Overdraw Limit Key (overdraw_limit_key)** ``` hf fmcos key --op 01 --id 00 --usage F0 --type overdraft --change 02 --version 00 --algo 01 --key 94f63c4fae5e4977d749928ad12bc128 -k ``` -**Key 12 — PIN Key (pin_code)** +**Key 12 - PIN Key (pin_code)** The PIN `\x12\x34\x56` is 3 raw BCD bytes. -Group B type — uses `--followup` and `--errcount`. +Group B type - uses `--followup` and `--errcount`. ``` hf fmcos key --op 01 --id 00 --usage F0 --type pin --followup 01 --errcount 33 --key 123456 -k ``` @@ -153,46 +153,46 @@ hf fmcos key --op 01 --id 00 --usage F0 --type pin --followup 01 --errcount 33 - Loop file 0x0018 (to be linked to the wallet balance file): ``` -hf fmcos create file --id 0018 --type loop --size 0517 --rperm F0 --wperm EF --access FF -k +hf fmcos createfile --id 0018 --type loop --size 0517 --rperm F0 --wperm EF --access FF -k ``` Loop file 0x0019 (to be linked to the passbook balance file): ``` -hf fmcos create file --id 0019 --type loop --size 0517 --rperm F0 --wperm EF --access FF -k +hf fmcos createfile --id 0019 --type loop --size 0517 --rperm F0 --wperm EF --access FF -k ``` ### 2f. Create wallet and passbook balance files Wallet balance file (EF 0x0002, linked to loop file 0x0018): ``` -hf fmcos create file --id 0002 --type wallet --size 0208 --rperm F0 --wperm 00 --access 18 -k +hf fmcos createfile --id 0002 --type wallet --size 0208 --rperm F0 --wperm 00 --access 18 -k ``` Passbook balance file (EF 0x0001, linked to loop file 0x0019): ``` -hf fmcos create file --id 0001 --type wallet --size 0208 --rperm F0 --wperm 00 --access 19 +hf fmcos createfile --id 0001 --type wallet --size 0208 --rperm F0 --wperm 00 --access 19 ``` The last command drops the field to end the setup session. --- -## 3. verify_pin — verify the PIN +## 3. verify_pin - verify the PIN The PIN `\x12\x34\x56` is 3 raw BCD bytes. ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 +hf fmcos pinverify --id 00 --pin 123456 ``` --- -## 4. get_balance — read wallet and passbook balances +## 4. get_balance - read wallet and passbook balances ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos balance --type wallet -k hf fmcos balance --type passbook ``` @@ -201,16 +201,16 @@ The command prints the 4-byte big-endian balance in decimal and hex. --- -## 5. add_money — credit (load funds) +## 5. add_money - credit (load funds) Credit key index is 9 (written ninth in step 2d, 0-based index = 9 = 0x09). Credit 1000 units to the wallet, then 2000 to the passbook in one session: ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos credit --type wallet --id 09 --amount 1000 --terminal 666666666666 --key a9e6e145f5df09500a58eef8575d49db --ikey 2b8a438742c851566f02d881b09d58c0 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos credit --type passbook --id 09 --amount 2000 --terminal 666666666666 --key a9e6e145f5df09500a58eef8575d49db --ikey 2b8a438742c851566f02d881b09d58c0 ``` @@ -223,21 +223,21 @@ hf fmcos credit --type passbook --id 09 --amount 2000 --terminal 666666666666 -- --- -## 6. spend_wallet / spend_passbook — purchase (deduct funds) +## 6. spend_wallet / spend_passbook - purchase (deduct funds) Purchase key index is 8 (0-based index = 8 = 0x08). Purchase (deduct) 50 units from the wallet: ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos purchase --type wallet --id 08 --amount 50 --terminal 666666666666 --key eb18ce6986c820970e876219052ce0cf --ikey 2b8a438742c851566f02d881b09d58c0 ``` Purchase 50 units from the passbook: ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos purchase --type passbook --id 08 --amount 50 --terminal 666666666666 --key eb18ce6986c820970e876219052ce0cf --ikey 2b8a438742c851566f02d881b09d58c0 ``` @@ -246,21 +246,21 @@ hf fmcos purchase --type passbook --id 08 --amount 50 --terminal 666666666666 -- --- -## 7. withdraw_money — cash withdrawal (NOT SUPPORTED) +## 7. withdraw_money - cash withdrawal (NOT SUPPORTED) Cash withdrawal uses INS=0x50 P1=0x02. There is currently no `hf fmcos` command for this operation. --- -## 8. pin_block — deliberately block the PIN +## 8. pin_block - deliberately block the PIN ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 11223344 -k -hf fmcos pin verify --id 00 --pin 11223344 -k -hf fmcos pin verify --id 00 --pin 11223344 -k -hf fmcos pin verify --id 00 --pin 11223344 +hf fmcos pinverify --id 00 --pin 11223344 -k +hf fmcos pinverify --id 00 --pin 11223344 -k +hf fmcos pinverify --id 00 --pin 11223344 -k +hf fmcos pinverify --id 00 --pin 11223344 ``` After the error counter reaches zero the card blocks the PIN and returns @@ -268,31 +268,31 @@ SW=`6983`. --- -## 9. pin_unblock — restore a blocked PIN +## 9. pin_unblock - restore a blocked PIN Unlock PIN key index is 5 (0-based index = 5 = 0x05). ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin unblock --id 00 --pin 123456 --key d8f60fa2d791f3a658d27c05458243ed +hf fmcos pinunblock --id 00 --pin 123456 --key d8f60fa2d791f3a658d27c05458243ed ``` --- -## 10. online_debit — online transfer (NOT SUPPORTED) +## 10. online_debit - online transfer (NOT SUPPORTED) Online debit uses INS=0x50 P1=0x05 (initialize) and INS=0x54 P1=0x03 (commit). There is currently no `hf fmcos` command for this operation. --- -## 11. update_overdraft — set the overdraft limit +## 11. update_overdraft - set the overdraft limit Overdraft key index is 11 (0-based index = 11 = 0x0B). ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos overdraft --id 0B --limit 1000 --terminal 666666666666 --key 94f63c4fae5e4977d749928ad12bc128 --ikey 2b8a438742c851566f02d881b09d58c0 ``` @@ -304,7 +304,7 @@ verified using DES-CBC-MAC with `tac_key = XOR(ikey[0:8], ikey[8:16])` over: --- -## 12. get_history — read transaction history +## 12. get_history - read transaction history Read the most recent 10 records from the wallet loop file (SFI 0x18): @@ -335,30 +335,30 @@ always the most recently written entry. --- -## 13. pin_change — change PIN using old PIN authorization +## 13. pin_change - change PIN using old PIN authorization ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k -hf fmcos pin change --id 00 --old 123456 --new 13371337 -k -hf fmcos pin verify --id 00 --pin 13371337 -k -hf fmcos pin change --id 00 --old 13371337 --new 123456 -k -hf fmcos pin verify --id 00 --pin 123456 +hf fmcos pinverify --id 00 --pin 123456 -k +hf fmcos pinchange --id 00 --old 123456 --new 13371337 -k +hf fmcos pinverify --id 00 --pin 13371337 -k +hf fmcos pinchange --id 00 --old 13371337 --new 123456 -k +hf fmcos pinverify --id 00 --pin 123456 ``` --- -## 14. pin_reset — set new PIN using change-PIN key (no old PIN needed) +## 14. pin_reset - set new PIN using change-PIN key (no old PIN needed) Change PIN key index is 6 (0-based index = 6 = 0x06). ``` hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k -hf fmcos pin reset --id 00 --pin 13371337 --key fb487a6d1b7cbf1bf84c666b8338376e -k -hf fmcos pin verify --id 00 --pin 13371337 -k -hf fmcos pin change --id 00 --old 13371337 --new 123456 -k -hf fmcos pin verify --id 00 --pin 123456 +hf fmcos pinverify --id 00 --pin 123456 -k +hf fmcos pinreset --id 00 --pin 13371337 --key fb487a6d1b7cbf1bf84c666b8338376e -k +hf fmcos pinverify --id 00 --pin 13371337 -k +hf fmcos pinchange --id 00 --old 13371337 --new 123456 -k +hf fmcos pinverify --id 00 --pin 123456 ``` --- @@ -369,24 +369,24 @@ The following block shows a full session in order: reset, setup, load money, spend, and check balance. Each sub-section starts a new session (field activates) and ends when the last command drops the field. -> **Note**: `--space` and `--size` are hex — `--space 1500` = 5376 bytes, `--space 400` = 1024 bytes, `--size 0517` = 1303 bytes, `--size 0208` = 520 bytes. +> **Note**: `--space` and `--size` are hex - `--space 1500` = 5376 bytes, `--space 400` = 1024 bytes, `--size 0517` = 1303 bytes, `--size 0208` = 520 bytes. ``` -# ── 1. Reset ──────────────────────────────────────────────────────────────── +# -- 1. Reset ---------------------------------------------------------------- hf fmcos select --id 3f00 -k hf fmcos erase -# ── 2. Create ADF ──────────────────────────────────────────────────────────── +# -- 2. Create ADF ------------------------------------------------------------ hf fmcos select --id 3f00 -k -hf fmcos create dir --id 3F01 --space 1500 --cperm F0 --eperm F0 --appid 95 --name 77616C6C657454657374 -k +hf fmcos createdir --id 3F01 --space 1500 --cperm F0 --eperm F0 --appid 95 --name 77616C6C657454657374 -k -# ── 3. Select ADF ──────────────────────────────────────────────────────────── +# -- 3. Select ADF ------------------------------------------------------------ hf fmcos select --name 77616C6C657454657374 -k -# ── 4. Create keyfile ──────────────────────────────────────────────────────── -hf fmcos create keyfile --id 0000 --space 400 --dfsid 95 --perm F0 -k +# -- 4. Create keyfile -------------------------------------------------------- +hf fmcos createkeyfile --id 0000 --space 400 --dfsid 95 --perm F0 -k -# ── 5. Write 13 keys (indexes 0-12) ───────────────────────────────────────── +# -- 5. Write 13 keys (indexes 0-12) ----------------------------------------- hf fmcos key --op 01 --id 00 --usage F0 --type desenc --change F4 --version 05 --algo 98 --key c4608b786af1992343e91a076670ae7c -k hf fmcos key --op 01 --id 00 --usage F0 --type desdec --change F4 --version 05 --algo 98 --key b8d4190c76856901fc686f36ab9b1ce0 -k hf fmcos key --op 01 --id 00 --usage F0 --type desmac --change F4 --version 05 --algo 98 --key 46a3ea8b254ee2749cc681050fd0dbcc -k @@ -401,50 +401,50 @@ hf fmcos key --op 01 --id 00 --usage F0 --type debit --change 02 --version 00 hf fmcos key --op 01 --id 00 --usage F0 --type overdraft --change 02 --version 00 --algo 01 --key 94f63c4fae5e4977d749928ad12bc128 -k hf fmcos key --op 01 --id 00 --usage F0 --type pin --followup 01 --errcount 33 --key 123456 -k -# ── 6. Create loop files ───────────────────────────────────────────────────── -hf fmcos create file --id 0018 --type loop --size 0517 --rperm F0 --wperm EF --access FF -k -hf fmcos create file --id 0019 --type loop --size 0517 --rperm F0 --wperm EF --access FF -k +# -- 6. Create loop files ----------------------------------------------------- +hf fmcos createfile --id 0018 --type loop --size 0517 --rperm F0 --wperm EF --access FF -k +hf fmcos createfile --id 0019 --type loop --size 0517 --rperm F0 --wperm EF --access FF -k -# ── 7. Create balance files ────────────────────────────────────────────────── -hf fmcos create file --id 0002 --type wallet --size 0208 --rperm F0 --wperm 00 --access 18 -k -hf fmcos create file --id 0001 --type wallet --size 0208 --rperm F0 --wperm 00 --access 19 +# -- 7. Create balance files -------------------------------------------------- +hf fmcos createfile --id 0002 --type wallet --size 0208 --rperm F0 --wperm 00 --access 18 -k +hf fmcos createfile --id 0001 --type wallet --size 0208 --rperm F0 --wperm 00 --access 19 -# ── 8. Verify PIN ──────────────────────────────────────────────────────────── +# -- 8. Verify PIN ------------------------------------------------------------ hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 +hf fmcos pinverify --id 00 --pin 123456 -# ── 9. Credit wallet +1000, passbook +2000 ─────────────────────────────────── +# -- 9. Credit wallet +1000, passbook +2000 ----------------------------------- hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos credit --type wallet --id 09 --amount 1000 --terminal 666666666666 --key a9e6e145f5df09500a58eef8575d49db --ikey 2b8a438742c851566f02d881b09d58c0 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos credit --type passbook --id 09 --amount 2000 --terminal 666666666666 --key a9e6e145f5df09500a58eef8575d49db --ikey 2b8a438742c851566f02d881b09d58c0 -# ── 10. Check balances ─────────────────────────────────────────────────────── +# -- 10. Check balances ------------------------------------------------------- hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos balance --type wallet -k hf fmcos balance --type passbook -# ── 11. Purchase (spend) from wallet then passbook ─────────────────────────── +# -- 11. Purchase (spend) from wallet then passbook --------------------------- hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos purchase --type wallet --id 08 --amount 50 --terminal 666666666666 --key eb18ce6986c820970e876219052ce0cf --ikey 2b8a438742c851566f02d881b09d58c0 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos purchase --type passbook --id 08 --amount 50 --terminal 666666666666 --key eb18ce6986c820970e876219052ce0cf --ikey 2b8a438742c851566f02d881b09d58c0 -# ── 12. Check balances again ───────────────────────────────────────────────── +# -- 12. Check balances again ------------------------------------------------- hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos balance --type wallet -k hf fmcos balance --type passbook -# ── 13. Update overdraft limit to 1000 ────────────────────────────────────── +# -- 13. Update overdraft limit to 1000 -------------------------------------- hf fmcos select --name 77616C6C657454657374 -k -hf fmcos pin verify --id 00 --pin 123456 -k +hf fmcos pinverify --id 00 --pin 123456 -k hf fmcos overdraft --id 0B --limit 1000 --terminal 666666666666 --key 94f63c4fae5e4977d749928ad12bc128 --ikey 2b8a438742c851566f02d881b09d58c0 -# ── 14. Read transaction history ───────────────────────────────────────────── +# -- 14. Read transaction history --------------------------------------------- hf fmcos select --name 77616C6C657454657374 -k hf fmcos history --fid 18 -k hf fmcos history --fid 19 @@ -457,8 +457,8 @@ hf fmcos history --fid 19 That script demos binary/variable/loop file creation with line protection (none, MAC, MAC+enc), plus application block/unblock. Two DFs are created on the same card: -- **blockTest** (DF 3FFF, appid 0x94) — block/unblock target -- **fileTest** (DF 3F01, appid 0x95) — file read/write target +- **blockTest** (DF 3FFF, appid 0x94) - block/unblock target +- **fileTest** (DF 3F01, appid 0x95) - file read/write target ### Keys used @@ -485,36 +485,36 @@ hf fmcos erase --- -### setup — create both DFs +### setup - create both DFs #### blockTest DF (3FFF) ``` hf fmcos select --id 3f00 -k -hf fmcos create dir --id 3FFF --space 500 --cperm F0 --eperm F0 --appid 94 --name 626c6f636b54657374 -k +hf fmcos createdir --id 3FFF --space 500 --cperm F0 --eperm F0 --appid 94 --name 626c6f636b54657374 -k hf fmcos select --name 626c6f636b54657374 -k -hf fmcos create keyfile --id 0001 --space 200 --dfsid 94 --perm F0 -k +hf fmcos createkeyfile --id 0001 --space 200 --dfsid 94 --perm F0 -k ``` Keys written into blockTest (keyfile 0001): ``` -# Key 0 — lineprotect (line_protection_key_1) +# Key 0 - lineprotect (line_protection_key_1) hf fmcos key --op 01 --id 00 --usage F0 --type lineprotect --change 02 --errcount 33 --key 49439874a1f623fc5e14818365d34699 -k -# Key 1 — extauth (external_auth_key_1) +# Key 1 - extauth (external_auth_key_1) hf fmcos key --op 01 --id 00 --usage F0 --type extauth --change F0 --followup AA --errcount FF --key da152a9a56def40a1386ca258788fea6 -k -# Key 2 — internal (internal_key_1) +# Key 2 - internal (internal_key_1) hf fmcos key --op 01 --id 00 --usage F0 --type internal --change F0 --version 00 --algo 01 --key bb4a314981b20ce696d6c1e1cda5820c -k ``` Seed binary file 0x0002 in blockTest: ``` -hf fmcos create file --id 0002 --type bin --size 50 --rperm F0 --wperm F0 --access FF -k +hf fmcos createfile --id 0002 --type bin --size 50 --rperm F0 --wperm F0 --access FF -k hf fmcos select --id 0002 -k -hf fmcos write binary --p1 00 --p2 00 --data 62696e66696c655f626c6f636b5f74657374 +hf fmcos writebinary --p1 00 --p2 00 --data 62696e66696c655f626c6f636b5f74657374 ``` (`62696e66696c655f626c6f636b5f74657374` = ASCII `binfile_block_test`) @@ -523,25 +523,25 @@ hf fmcos write binary --p1 00 --p2 00 --data 62696e66696c655f626c6f636b5f7465737 ``` hf fmcos select --id 3f00 -k -hf fmcos create dir --id 3F01 --space 1500 --cperm F0 --eperm F0 --appid 95 --name 66696c6554657374 -k +hf fmcos createdir --id 3F01 --space 1500 --cperm F0 --eperm F0 --appid 95 --name 66696c6554657374 -k hf fmcos select --name 66696c6554657374 -k -hf fmcos create keyfile --id 0001 --space 200 --dfsid 95 --perm F0 -k +hf fmcos createkeyfile --id 0001 --space 200 --dfsid 95 --perm F0 -k ``` Keys written into fileTest (keyfile 0001). Keys 2 and 3 are written with MAC+enc line protection (`--prot enc --authkey `): ``` -# Key 0 — extauth (external_auth_key), unprotected write +# Key 0 - extauth (external_auth_key), unprotected write hf fmcos key --op 01 --id 00 --usage F0 --type extauth --change F0 --followup AA --errcount FF --key 7c3f149ed331b11211d2fb62e2df9637 -k -# Key 1 — internal (internal_key), unprotected write +# Key 1 - internal (internal_key), unprotected write hf fmcos key --op 01 --id 00 --usage F0 --type internal --change F0 --version 00 --algo 01 --key 659a500f0f1fce35b6884bdff966576a -k -# Key 2 — lineprotect (line_protection_key), written with enc protection +# Key 2 - lineprotect (line_protection_key), written with enc protection hf fmcos key --op 01 --id 00 --usage F0 --type lineprotect --change F0 --errcount FF --key 980093b4d77ff65f7476bf9019a80892 --authkey 7c3f149ed331b11211d2fb62e2df9637 --prot enc -k -# Key 3 (slot 02) — extauth (enc_external_auth_key), written with enc protection +# Key 3 (slot 02) - extauth (enc_external_auth_key), written with enc protection hf fmcos key --op 01 --id 02 --usage F0 --type extauth --change F0 --followup AA --errcount FF --key 44ea0184094995a845b612522a8ab463 --authkey 7c3f149ed331b11211d2fb62e2df9637 --prot enc -k ``` @@ -550,20 +550,20 @@ MAC+enc (`--access 7F --prot enc`). `--access 7F` = protection required, use ke ``` # Binary files -hf fmcos create file --id 0002 --type bin --size 50 --rperm F0 --wperm F0 --access FF -k -hf fmcos create file --id 0003 --type bin --size 50 --rperm F0 --wperm F0 --access 7F --prot mac -k -hf fmcos create file --id 0004 --type bin --size 50 --rperm F0 --wperm F0 --access 7F --prot enc -k +hf fmcos createfile --id 0002 --type bin --size 50 --rperm F0 --wperm F0 --access FF -k +hf fmcos createfile --id 0003 --type bin --size 50 --rperm F0 --wperm F0 --access 7F --prot mac -k +hf fmcos createfile --id 0004 --type bin --size 50 --rperm F0 --wperm F0 --access 7F --prot enc -k # Variable-length record files -hf fmcos create file --id 0006 --type var --size 50 --rperm F0 --wperm F0 --access FF -k -hf fmcos create file --id 0007 --type var --size 50 --rperm F0 --wperm F0 --access 7F --prot mac -k -hf fmcos create file --id 0008 --type var --size 50 --rperm F0 --wperm F0 --access 7F --prot enc -k +hf fmcos createfile --id 0006 --type var --size 50 --rperm F0 --wperm F0 --access FF -k +hf fmcos createfile --id 0007 --type var --size 50 --rperm F0 --wperm F0 --access 7F --prot mac -k +hf fmcos createfile --id 0008 --type var --size 50 --rperm F0 --wperm F0 --access 7F --prot enc -k # Loop (cyclic) files --size 210 = 0x210 = 528 bytes -# space = record_count*(record_len+1)+8; e.g. 5 records × (0x50+1) + 8 = 0x19D -hf fmcos create file --id 000A --type loop --size 210 --rperm F0 --wperm F0 --access FF -k -hf fmcos create file --id 000B --type loop --size 210 --rperm F0 --wperm F0 --access 7F --prot mac -k -hf fmcos create file --id 000C --type loop --size 210 --rperm F0 --wperm F0 --access 7F --prot enc +# space = record_count*(record_len+1)+8; e.g. 5 records x (0x50+1) + 8 = 0x19D +hf fmcos createfile --id 000A --type loop --size 210 --rperm F0 --wperm F0 --access FF -k +hf fmcos createfile --id 000B --type loop --size 210 --rperm F0 --wperm F0 --access 7F --prot mac -k +hf fmcos createfile --id 000C --type loop --size 210 --rperm F0 --wperm F0 --access 7F --prot enc ``` --- @@ -573,13 +573,13 @@ hf fmcos create file --id 000C --type loop --size 210 --rperm F0 --wperm F0 --ac ``` hf fmcos select --id 3f01 -k hf fmcos select --id 0002 -k -hf fmcos write binary --p1 00 --p2 00 --data 111213141516171819101a1b1c1d1e1f -k +hf fmcos writebinary --p1 00 --p2 00 --data 111213141516171819101a1b1c1d1e1f -k hf fmcos select --id 0003 -k -hf fmcos write binary --p1 00 --p2 00 --data 212223242526272829202a2b2c2d2e2f --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k +hf fmcos writebinary --p1 00 --p2 00 --data 212223242526272829202a2b2c2d2e2f --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k hf fmcos select --id 0004 -k -hf fmcos write binary --p1 00 --p2 00 --data 313233343536373839303a3b3c3d3e3f --prot enc --key 980093b4d77ff65f7476bf9019a80892 +hf fmcos writebinary --p1 00 --p2 00 --data 313233343536373839303a3b3c3d3e3f --prot enc --key 980093b4d77ff65f7476bf9019a80892 ``` --- @@ -603,20 +603,20 @@ hf fmcos append --fid 0c --data b1b2b3b4b5b6b7b8b9b0babbbcbdbebf --prot enc --ke ### write_record (UPDATE RECORD) P2 encodes the SFI: `(file_id & 0x1F) << 3 | 4`. The CLI `--fid` takes the raw file ID byte -(1–30) and encodes P2 automatically. +(1-30) and encodes P2 automatically. Variable-length files require `--tlv` so the data is wrapped as `00[len][data]`. ``` hf fmcos select --id 3f01 -k hf fmcos select --id 0006 -k -hf fmcos write record --rec 1 --fid 06 --data 515253545556575859505a5b5c5d5e5f --tlv -k +hf fmcos writerecord --rec 1 --fid 06 --data 515253545556575859505a5b5c5d5e5f --tlv -k hf fmcos select --id 0007 -k -hf fmcos write record --rec 1 --fid 07 --data 616263646566676869606a6b6c6d6e6f --tlv --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k +hf fmcos writerecord --rec 1 --fid 07 --data 616263646566676869606a6b6c6d6e6f --tlv --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k hf fmcos select --id 0008 -k -hf fmcos write record --rec 1 --fid 08 --data 717273747576777879707a7b7c7d7e7f --tlv --prot enc --key 980093b4d77ff65f7476bf9019a80892 +hf fmcos writerecord --rec 1 --fid 08 --data 717273747576777879707a7b7c7d7e7f --tlv --prot enc --key 980093b4d77ff65f7476bf9019a80892 ``` --- @@ -628,13 +628,13 @@ For MAC-protected reads the card appends a 4-byte MAC before the SW; the CLI str ``` hf fmcos select --id 3f01 -k hf fmcos select --id 0002 -k -hf fmcos read binary --p1 00 --p2 00 --len 16 -k +hf fmcos readbinary --p1 00 --p2 00 --len 16 -k hf fmcos select --id 0003 -k -hf fmcos read binary --p1 00 --p2 00 --len 16 --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k +hf fmcos readbinary --p1 00 --p2 00 --len 16 --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k hf fmcos select --id 0004 -k -hf fmcos read binary --p1 00 --p2 00 --len 16 --prot enc --key 980093b4d77ff65f7476bf9019a80892 +hf fmcos readbinary --p1 00 --p2 00 --len 16 --prot enc --key 980093b4d77ff65f7476bf9019a80892 ``` --- @@ -645,9 +645,9 @@ Variable-length files need `--tlv`; the CLI requests 2 extra bytes and strips th ``` hf fmcos select --id 3f01 -k -hf fmcos read record --rec 01 --fid 06 --len 16 --tlv -k -hf fmcos read record --rec 01 --fid 07 --len 16 --tlv --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k -hf fmcos read record --rec 01 --fid 08 --len 16 --tlv --prot enc --key 980093b4d77ff65f7476bf9019a80892 +hf fmcos readrecord --rec 01 --fid 06 --len 16 --tlv -k +hf fmcos readrecord --rec 01 --fid 07 --len 16 --tlv --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k +hf fmcos readrecord --rec 01 --fid 08 --len 16 --tlv --prot enc --key 980093b4d77ff65f7476bf9019a80892 ``` --- @@ -658,9 +658,9 @@ Loop files use the same READ RECORD command; `--rec 01` reads the most recently ``` hf fmcos select --id 3f01 -k -hf fmcos read record --rec 01 --fid 0a --len 16 -k -hf fmcos read record --rec 01 --fid 0b --len 16 --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k -hf fmcos read record --rec 01 --fid 0c --len 16 --prot enc --key 980093b4d77ff65f7476bf9019a80892 +hf fmcos readrecord --rec 01 --fid 0a --len 16 -k +hf fmcos readrecord --rec 01 --fid 0b --len 16 --prot mac --key 980093b4d77ff65f7476bf9019a80892 -k +hf fmcos readrecord --rec 01 --fid 0c --len 16 --prot enc --key 980093b4d77ff65f7476bf9019a80892 ``` --- @@ -693,5 +693,5 @@ hf fmcos select --name 626c6f636b54657374 -k hf fmcos unblock --key 49439874a1f623fc5e14818365d34699 -k hf fmcos select --name 626c6f636b54657374 -k hf fmcos select --id 0002 -k -hf fmcos read binary --p1 00 --p2 00 --len 16 +hf fmcos readbinary --p1 00 --p2 00 --len 16 ```