From 012e90f5c8f458d3c3af751d731b09edf4efa7fe Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Fri, 23 Jul 2021 17:03:48 +0300 Subject: [PATCH] create file raw mode works --- client/src/cmdhfmfdes.c | 466 +++++++++++++++++++++++--------- client/src/mifare/desfirecore.c | 8 +- client/src/mifare/desfirecore.h | 2 +- 3 files changed, 348 insertions(+), 128 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index b9a7d175f..65d25ffb6 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -1996,7 +1996,7 @@ static int handler_desfire_create_value_file(mfdes_value_file_t *value) { return res; } -static int handler_desfire_create_std_file(mfdes_file_t *file) { +/*static int handler_desfire_create_std_file(mfdes_file_t *file) { if (file->fileno > 0x1F) return PM3_EINVARG; @@ -2011,7 +2011,7 @@ static int handler_desfire_create_std_file(mfdes_file_t *file) { return res; } return res; -} +}*/ static int handler_desfire_create_linearrecordfile(mfdes_linear_t *file) { if (file->fileno > 0x1F) @@ -2051,7 +2051,7 @@ static int handler_desfire_create_cyclicrecordfile(mfdes_linear_t *file) { return res; } -static int handler_desfire_create_backup_file(mfdes_file_t *file) { +/*static int handler_desfire_create_backup_file(mfdes_file_t *file) { if (file->fileno > 0x1F) return PM3_EINVARG; sAPDU apdu = {0x90, MFDES_CREATE_BACKUP_DATA_FILE, 0x00, 0x00, sizeof(mfdes_file_t), (uint8_t *)file}; // 0xCB @@ -2065,7 +2065,7 @@ static int handler_desfire_create_backup_file(mfdes_file_t *file) { return res; } return res; -} +}*/ static int getKeySettings(uint8_t *aid) { if (aid == NULL) return PM3_EINVARG; @@ -2379,119 +2379,6 @@ static int CmdHF14ADesClearRecordFile(const char *Cmd) { return res; } -static int CmdHF14ADesCreateFile(const char *Cmd) { - CLIParserContext *ctx; - CLIParserInit(&ctx, "hf mfdes createfile", - "Create Standard/Backup File", - "hf mfdes createfile -f 0001 -n 01 -c 0 -r EEEE -s 000100 -a 123456" - ); - - void *argtable[] = { - arg_param_begin, - arg_int0("n", "fileno", "", "File Number (0 - 31)"), - arg_strx0("f", "fileid", "", "ISO FID (2 hex bytes, big endian)"), - arg_int0("c", "com", "", "Communication setting (0 = Plain, 1 = Plain + MAC, 3 = Enciphered)"), - arg_strx0("r", "rights", "", "Access rights (2 hex bytes -> RW/Chg/R/W, 0x0 - 0xD Key, 0xE Free, 0xF Denied)"), - arg_strx0("s", "filesize", "", "File size (3 hex bytes, big endian)"), - arg_lit0("b", "backup", "Create backupfile instead of standard file"), - arg_strx0("a", "aid", "", "App ID to select as hex bytes (3 bytes, big endian)"), - arg_param_end - }; - - CLIExecWithReturn(ctx, Cmd, argtable, false); - int fno = arg_get_int_def(ctx, 1, 0); - - int fidlength = 0; - uint8_t fid[2] = {0}; - int res_flen = CLIParamHexToBuf(arg_get_str(ctx, 2), fid, 2, &fidlength); - - uint8_t comset = arg_get_int(ctx, 3); - int arlength = 0; - uint8_t ar[2] = {0}; - CLIGetHexWithReturn(ctx, 4, ar, &arlength); - - int fsizelen = 0; - uint8_t filesize[3] = {0}; - CLIGetHexWithReturn(ctx, 5, filesize, &fsizelen); - - bool isbackup = arg_get_lit(ctx, 6); - int aidlength = 3; - uint8_t aid[3] = {0}; - CLIGetHexWithReturn(ctx, 7, aid, &aidlength); - swap24(aid); - CLIParserFree(ctx); - - swap16(fid); - swap24(filesize); - - if (fno > 0x1F) { - PrintAndLogEx(ERR, "File number range is invalid (exp 0 - 31), got %d", fno); - return PM3_EINVARG; - } - if (comset != 0 && comset != 1 && comset != 3) { - PrintAndLogEx(ERR, "Communication setting must be either 0=Plain, 1=Plain+MAC or 3=Encrypt."); - return PM3_EINVARG; - } - - if (arlength != 2) { - PrintAndLogEx(ERR, "Access rights must have 2 hex bytes length."); - return PM3_EINVARG; - } - - if (fsizelen != 3) { - PrintAndLogEx(ERR, "Filesize must have 3 hex bytes length."); - return PM3_EINVARG; - } - - if (res_flen || fidlength != 2) { - PrintAndLogEx(ERR, "ISO File id must have 2 hex bytes length."); - return PM3_EINVARG; - } - - mfdes_file_t ft; - memcpy(ft.fid, fid, 2); - memcpy(ft.filesize, filesize, 3); - ft.fileno = fno; - ft.comset = comset; - memcpy(ft.access_rights, ar, 2); - - if (aidlength != 3 && aidlength != 0) { - PrintAndLogEx(ERR, _RED_(" The given aid must have 3 bytes (big endian).")); - DropFieldDesfire(); - return PM3_ESOFT; - } else if (aidlength == 0) { - if (memcmp(&tag->selected_application, aid, 3) == 0) { - PrintAndLogEx(ERR, _RED_(" You need to select an aid first.")); - DropFieldDesfire(); - return PM3_ESOFT; - } - memcpy(aid, (uint8_t *)&tag->selected_application, 3); - } - - // int res; - // a select here seems to invalidate the current authentication with AMK and create file fails if not open access. - // This will be managed when we track Authenticated or Note, so a place holder comment as a reminder. - int res = handler_desfire_select_application(aid); - if (res != PM3_SUCCESS) { - PrintAndLogEx(ERR, "Couldn't select aid. Error %d", res); - DropFieldDesfire(); - return res; - } - - if (isbackup) - res = handler_desfire_create_backup_file(&ft); - else - res = handler_desfire_create_std_file(&ft); - - if (res == PM3_SUCCESS) - PrintAndLogEx(SUCCESS, "Successfully created standard / backup file."); - else - PrintAndLogEx(ERR, "Couldn't create standard / backup file. Error %d", res); - - DropFieldDesfire(); - return res; -} - static int CmdHF14ADesGetValueData(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mfdes getvalue", @@ -6148,7 +6035,7 @@ static int CmdHF14ADesChFileSettings(const char *Cmd) { CLIParserInit(&ctx, "hf mfdes chfilesettings", "Get File Settings from file from application. Master key needs to be provided or flag --no-auth set (depend on cards settings).", "hf mfdes chfilesettings --aid 123456 --fid 01 --amode plain --rrights free --wrights free --rwrights free --chrights key0 -> change file settings app=123456, file=01 with defaults from `default` command\n" - "hf mfdes chfilesettings -n 0 -t des -k 0000000000000000 -f none --aid 123456 --fid 01 -rawdata 00EEEE -> execute with default factory setup\n" + "hf mfdes chfilesettings -n 0 -t des -k 0000000000000000 -f none --aid 123456 --fid 01 --rawdata 00EEEE -> execute with default factory setup\n" "hf mfdes chfilesettings --aid 123456 --fid 01 --rawdata 810000021f112f22 -> change file settings with additional rights for keys 1 and 2"); void *argtable[] = { @@ -6306,7 +6193,342 @@ static int CmdHF14ADesChFileSettings(const char *Cmd) { return PM3_SUCCESS; } -//{"createfile", CmdHF14ADesCreateFile, IfPm3Iso14443a, "Create Standard/Backup File"}, +static int CmdHF14ADesCreateFile(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf mfdes createfile", + "Create Standard/Backup file in the application. Application master key needs to be provided or flag --no-auth set (depend on application settings).", + "--rawtype/--rawdata have priority over the other settings. and with these parameters you can create any file\n" + "--rawrights have priority over the separate rights settings.\n" + "Key/mode/etc of the authentication depends on application settings\n" + "hf mfdes createfile --aid 123456 --fid 01 --rawtype 01 --rawdata 000100EEEE000100 -> create file via sending rawdata to the card. Can be used to create any type of file. Authentication with defaults from `default` command\n" + "hf mfdes createfile --aid 123456 --fid 01 --amode plain --rrights free --wrights free --rwrights free --chrights key0 -> create file app=123456, file=01 and mentioned rights with defaults from `default` command\n" + "hf mfdes createfile -n 0 -t des -k 0000000000000000 -f none --aid 123456 --fid 01 --rawtype 00 --rawdata 00EEEE000100 -> execute with default factory setup"); + + void *argtable[] = { + arg_param_begin, + arg_lit0("a", "apdu", "show APDU requests and responses"), + arg_lit0("v", "verbose", "show technical data"), + arg_int0("n", "keyno", "", "Key number"), + 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("f", "kdf", "", "Key Derivation Function (KDF): None, AN10922, Gallagher"), + arg_str0("i", "kdfi", "", "KDF input (HEX 1-31 bytes)"), + arg_str0("m", "cmode", "", "Communicaton mode: plain/mac/encrypt"), + arg_str0("c", "ccset", "", "Communicaton command set: native/niso/iso"), + arg_str0("s", "schann", "", "Secure channel: d40/ev1/ev2"), + arg_str0(NULL, "aid", "", "Application ID (3 hex bytes, big endian)"), + arg_str0(NULL, "fid", "", "File ID (1 hex byte)"), + arg_str0(NULL, "isofid", "", "ISO File ID (2 hex bytes)"), + arg_str0(NULL, "rawtype", "", "Raw file type (HEX 1 byte)"), + arg_str0(NULL, "rawdata", "", "Raw file settings (HEX > 5 bytes)"), + arg_str0(NULL, "amode", "", "File access mode: plain/mac/encrypt"), + arg_str0(NULL, "rawrights", "", "Access rights for file (HEX 2 byte) R/W/RW/Chg, 0x0 - 0xD Key, 0xE Free, 0xF Denied"), + arg_str0(NULL, "rrights", "", "Read file access mode: the specified key, free, deny"), + arg_str0(NULL, "wrights", "", "Write file access mode: the specified key, free, deny"), + arg_str0(NULL, "rwrights","", "Read/Write file access mode: the specified key, free, deny"), + arg_str0(NULL, "chrights","", "Change file settings access mode: the specified key, free, deny"), + arg_lit0(NULL, "no-auth", "execute without authentication"), + arg_str0(NULL, "size", "", "File size (3 hex bytes, big endian)"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + bool APDULogging = arg_get_lit(ctx, 1); + bool verbose = arg_get_lit(ctx, 2); + bool noauth = arg_get_lit(ctx, 22); + + DesfireContext dctx; + int securechann = defaultSecureChannel; + uint32_t appid = 0x000000; + int res = CmdDesGetSessionParameters(ctx, &dctx, 3, 4, 5, 6, 7, 8, 9, 10, 11, &securechann, DCMPlain, &appid); + if (res) { + CLIParserFree(ctx); + return res; + } + + if (appid == 0x000000) { + PrintAndLogEx(ERR, "Can't create files at card level."); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + uint32_t fileid = 1; + res = arg_get_u32_hexstr_def_nlen(ctx, 12, 1, &fileid, 1, true); + if (res == 2) { + PrintAndLogEx(ERR, "File ID must have 1 byte length"); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + uint32_t isofileid = 0; + res = arg_get_u32_hexstr_def_nlen(ctx, 13, 0, &isofileid, 2, true); + if (res == 2) { + PrintAndLogEx(ERR, "ISO file ID must have 2 bytes length"); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + uint8_t filetype = 0x00; // standard data file + uint8_t data[250] = {0}; + data[0] = fileid; + size_t datalen = 1; + + if (isofileid > 0) { + data[1] = (isofileid >> 8) & 0xff; + data[2] = isofileid & 0xff; + datalen += 2; + } + + uint32_t rawftype = 0x00; + res = arg_get_u32_hexstr_def_nlen(ctx, 14, 0x00, &rawftype, 1, true); + bool useraw = (res != 0); + if (res == 2) { + PrintAndLogEx(ERR, "Raw file type must have 1 byte length"); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + uint8_t sdata[250] = {0}; + int sdatalen = sizeof(sdata); + CLIGetHexWithReturn(ctx, 15, sdata, &sdatalen); + if (sdatalen > 20) { + PrintAndLogEx(ERR, "Rawdata length must be less than 20 bytes instead of %d.", sdatalen); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + if (useraw && sdatalen > 0) { + filetype = rawftype; + memcpy(&data[datalen], sdata, sdatalen); + datalen += sdatalen; + } else { + useraw = false; + } + + if (useraw == false) { + uint8_t *settings = &data[datalen]; + + // file access mode + int cmode = DCMNone; + if (CLIGetOptionList(arg_get_str(ctx, 16), DesfireCommunicationModeOpts, &cmode)) { + CLIParserFree(ctx); + return PM3_ESOFT; + } + + if (cmode == DCMPlain) + settings[0] = 0x00; + if (cmode == DCMMACed) + settings[0] = 0x01; + if (cmode == DCMEncrypted) + settings[0] = 0x03; + datalen++; + + // file rights + uint32_t frights = 0; + res = arg_get_u32_hexstr_def_nlen(ctx, 17, 0xeeee, &frights, 2, true); + bool userawfrights = (res != 0); + if (res == 2) { + PrintAndLogEx(ERR, "File rights must have 2 bytes length"); + CLIParserFree(ctx); + return PM3_EINVARG; + } + settings[1] = (frights >> 8) & 0xff; + settings[2] = frights & 0xff; + + if (userawfrights == false) { + int r_mode = 0x0e; + if (CLIGetOptionList(arg_get_str(ctx, 18), DesfireFileAccessModeOpts, &r_mode)) { + CLIParserFree(ctx); + return PM3_ESOFT; + } + int w_mode = 0x0e; + if (CLIGetOptionList(arg_get_str(ctx, 19), DesfireFileAccessModeOpts, &w_mode)) { + CLIParserFree(ctx); + return PM3_ESOFT; + } + int rw_mode = 0x0e; + if (CLIGetOptionList(arg_get_str(ctx, 20), DesfireFileAccessModeOpts, &rw_mode)) { + CLIParserFree(ctx); + return PM3_ESOFT; + } + int ch_mode = 0x0e; + if (CLIGetOptionList(arg_get_str(ctx, 21), DesfireFileAccessModeOpts, &ch_mode)) { + CLIParserFree(ctx); + return PM3_ESOFT; + } + + DesfireEncodeFileAcessMode(&settings[1], r_mode, w_mode, rw_mode, ch_mode) ; + } + datalen += 2; + + // file size + uint32_t filesize = 0; + res = arg_get_u32_hexstr_def_nlen(ctx, 22, 0, &filesize, 3, true); + if (res == 2) { + PrintAndLogEx(ERR, "File size must have 3 bytes length"); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + if (filesize == 0) { + PrintAndLogEx(ERR, "File size must be greater than 0"); + CLIParserFree(ctx); + return PM3_EINVARG; + } + + data[datalen] = (filesize >> 16) & 0xff; + data[datalen + 1] = (filesize >> 8) & 0xff; + data[datalen + 2] = filesize & 0xff; + datalen += 3; + } + + SetAPDULogging(APDULogging); + CLIParserFree(ctx); + + if (noauth) { + res = DesfireSelectAIDHex(&dctx, appid, false, 0); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Desfire select " _RED_("error") "."); + DropField(); + return res; + } + } else { + res = DesfireSelectAndAuthenticate(&dctx, securechann, appid, verbose); + if (res != PM3_SUCCESS) { + DropField(); + return res; + } + } + + if (verbose) + PrintAndLogEx(INFO, "App: %06x. File num: 0x%02x type: 0x%02x data[%d]: %s", appid, fileid, filetype, datalen, sprint_hex(data, datalen)); + + res = DesfireCreateFile(&dctx, filetype, data, datalen, useraw == false); // check length only if we nont use raw mode + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Desfire CreateFile command " _RED_("error") ". Result: %d", res); + DropField(); + return PM3_ESOFT; + } + + PrintAndLogEx(SUCCESS, "File %02x in the app %06x created " _GREEN_("successfully"), fileid, appid); + + DropField(); + return PM3_SUCCESS; + + + + /* + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf mfdes createfile", + "Create Standard/Backup File", + "hf mfdes createfile -f 0001 -n 01 -c 0 -r EEEE -s 000100 -a 123456" + ); + + void *argtable[] = { + arg_param_begin, + arg_int0("n", "fileno", "", "File Number (0 - 31)"), + arg_strx0("f", "fileid", "", "ISO FID (2 hex bytes, big endian)"), + arg_int0("c", "com", "", "Communication setting (0 = Plain, 1 = Plain + MAC, 3 = Enciphered)"), + arg_strx0("r", "rights", "", "Access rights (2 hex bytes -> RW/Chg/R/W, 0x0 - 0xD Key, 0xE Free, 0xF Denied)"), + arg_strx0("s", "filesize", "", "File size (3 hex bytes, big endian)"), + arg_lit0("b", "backup", "Create backupfile instead of standard file"), + arg_strx0("a", "aid", "", "App ID to select as hex bytes (3 bytes, big endian)"), + arg_param_end + }; + + CLIExecWithReturn(ctx, Cmd, argtable, false); + int fno = arg_get_int_def(ctx, 1, 0); + + int fidlength = 0; + uint8_t fid[2] = {0}; + int res_flen = CLIParamHexToBuf(arg_get_str(ctx, 2), fid, 2, &fidlength); + + uint8_t comset = arg_get_int(ctx, 3); + int arlength = 0; + uint8_t ar[2] = {0}; + CLIGetHexWithReturn(ctx, 4, ar, &arlength); + + int fsizelen = 0; + uint8_t filesize[3] = {0}; + CLIGetHexWithReturn(ctx, 5, filesize, &fsizelen); + + bool isbackup = arg_get_lit(ctx, 6); + int aidlength = 3; + uint8_t aid[3] = {0}; + CLIGetHexWithReturn(ctx, 7, aid, &aidlength); + swap24(aid); + CLIParserFree(ctx); + + swap16(fid); + swap24(filesize); + + if (fno > 0x1F) { + PrintAndLogEx(ERR, "File number range is invalid (exp 0 - 31), got %d", fno); + return PM3_EINVARG; + } + if (comset != 0 && comset != 1 && comset != 3) { + PrintAndLogEx(ERR, "Communication setting must be either 0=Plain, 1=Plain+MAC or 3=Encrypt."); + return PM3_EINVARG; + } + + if (arlength != 2) { + PrintAndLogEx(ERR, "Access rights must have 2 hex bytes length."); + return PM3_EINVARG; + } + + if (fsizelen != 3) { + PrintAndLogEx(ERR, "Filesize must have 3 hex bytes length."); + return PM3_EINVARG; + } + + if (res_flen || fidlength != 2) { + PrintAndLogEx(ERR, "ISO File id must have 2 hex bytes length."); + return PM3_EINVARG; + } + + mfdes_file_t ft; + memcpy(ft.fid, fid, 2); + memcpy(ft.filesize, filesize, 3); + ft.fileno = fno; + ft.comset = comset; + memcpy(ft.access_rights, ar, 2); + + if (aidlength != 3 && aidlength != 0) { + PrintAndLogEx(ERR, _RED_(" The given aid must have 3 bytes (big endian).")); + DropFieldDesfire(); + return PM3_ESOFT; + } else if (aidlength == 0) { + if (memcmp(&tag->selected_application, aid, 3) == 0) { + PrintAndLogEx(ERR, _RED_(" You need to select an aid first.")); + DropFieldDesfire(); + return PM3_ESOFT; + } + memcpy(aid, (uint8_t *)&tag->selected_application, 3); + } + + // int res; + // a select here seems to invalidate the current authentication with AMK and create file fails if not open access. + // This will be managed when we track Authenticated or Note, so a place holder comment as a reminder. + int res = handler_desfire_select_application(aid); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Couldn't select aid. Error %d", res); + DropFieldDesfire(); + return res; + } + + if (isbackup) + res = handler_desfire_create_backup_file(&ft); + else + res = handler_desfire_create_std_file(&ft); + + if (res == PM3_SUCCESS) + PrintAndLogEx(SUCCESS, "Successfully created standard / backup file."); + else + PrintAndLogEx(ERR, "Couldn't create standard / backup file. Error %d", res); + + DropFieldDesfire(); + return res;*/ +} static int CmdHF14ADesDeleteFile(const char *Cmd) { CLIParserContext *ctx; @@ -6389,8 +6611,6 @@ static int CmdHF14ADesDeleteFile(const char *Cmd) { return PM3_SUCCESS; } - - static int CmdHF14ADesTest(const char *Cmd) { DesfireTest(true); return PM3_SUCCESS; @@ -6430,10 +6650,10 @@ static command_t CommandTable[] = { {"chfilesettings", CmdHF14ADesChFileSettings, IfPm3Iso14443a, "[new]Change file settings"}, {"changevalue", CmdHF14ADesChangeValue, IfPm3Iso14443a, "Write value of a value file (credit/debit/clear)"}, {"clearfile", CmdHF14ADesClearRecordFile, IfPm3Iso14443a, "Clear record File"}, - {"createfile", CmdHF14ADesCreateFile, IfPm3Iso14443a, "Create Standard/Backup File"}, + {"createfile", CmdHF14ADesCreateFile, IfPm3Iso14443a, "[new]Create Standard/Backup File"}, {"createvaluefile", CmdHF14ADesCreateValueFile, IfPm3Iso14443a, "Create Value File"}, {"createrecordfile", CmdHF14ADesCreateRecordFile, IfPm3Iso14443a, "Create Linear/Cyclic Record File"}, - {"deletefile", CmdHF14ADesDeleteFile, IfPm3Iso14443a, "Delete File"}, + {"deletefile", CmdHF14ADesDeleteFile, IfPm3Iso14443a, "[new]Delete File"}, {"dump", CmdHF14ADesDump, IfPm3Iso14443a, "Dump all files"}, {"getvalue", CmdHF14ADesGetValueData, IfPm3Iso14443a, "Get value of file"}, {"read", CmdHF14ADesReadData, IfPm3Iso14443a, "Read data from standard/backup/record file"}, diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index 1571c2a0d..c4e863c91 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -1050,12 +1050,12 @@ int DesfireGetFileSettings(DesfireContext *dctx, uint8_t fileid, uint8_t *resp, return DesfireCommand(dctx, MFDES_GET_FILE_SETTINGS, &fileid, 1, resp, resplen, -1); } -int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen) { +int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen, bool checklen) { const DesfireCreateFileCommandsS *rcmd = GetDesfireFileCmdRec(ftype); if (rcmd == NULL) - return -10; - if (fdatalen != rcmd->len || fdatalen != (rcmd->len + (rcmd->mayHaveISOfid) ? 2 : 0)) - return -20; + return -100; + if (checklen && fdatalen != (rcmd->len + 1) && fdatalen != (rcmd->len + 1 + (rcmd->mayHaveISOfid ? 2 : 0))) + return -110; return DesfireCommandTxData(dctx, rcmd->cmd, fdata, fdatalen); } diff --git a/client/src/mifare/desfirecore.h b/client/src/mifare/desfirecore.h index 1c460afbb..d4dffdc1e 100644 --- a/client/src/mifare/desfirecore.h +++ b/client/src/mifare/desfirecore.h @@ -84,7 +84,7 @@ void DesfirePrintAccessRight(uint8_t *data); void DesfirePrintFileSettings(uint8_t *data, size_t len); void DesfirePrintSetFileSettings(uint8_t *data, size_t len); -int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen); +int DesfireCreateFile(DesfireContext *dctx, uint8_t ftype, uint8_t *fdata, size_t fdatalen, bool checklen); int DesfireDeleteFile(DesfireContext *dctx, uint8_t fid); int DesfireCommitTrqansaction(DesfireContext *dctx, bool enable_options, uint8_t options); int DesfireAbortTrqansaction(DesfireContext *dctx);