make style

This commit is contained in:
merlokk committed 2022-02-04 15:39:26 +02:00
1 parent f323237091
commit 4814dc5bfb
5 files changed
+275 -130

No files matched your search

+32 -28
View File
@@ -378,7 +378,7 @@ void CIPURSEPrintDGI(uint8_t *dgi, size_t dgilen) {
PrintAndLogEx(WARNING, "DGI too small. Length: %zu", dgilen);
return;
}
uint8_t len = dgi[2];
if (len + 3 != dgilen) {
PrintAndLogEx(ERR, "DGI size does not match with record size. Length of record: %zu, DGI size: %d", dgilen, len);
@@ -446,10 +446,14 @@ static void CIPURSEPrintKeyAttribDGI(uint8_t *attr) {
const char *CIPURSEGetSMR(uint8_t smr) {
switch (smr) {
case 0x00: return "plain";
case 0x01: return "mac";
case 0x02: return "enc";
default: return "unknown";
case 0x00:
return "plain";
case 0x01:
return "mac";
case 0x02:
return "enc";
default:
return "unknown";
}
return "unknown";
}
@@ -481,35 +485,35 @@ void CIPURSEPrintART(uint8_t *artrec, size_t artlen) {
}
void CIPURSEPrintEFFileAttr(uint8_t *attr, size_t len) {
CIPURSEPrintFileDescriptor(attr[0]);
CIPURSEPrintFileDescriptor(attr[0]);
if (attr[1] == 0)
PrintAndLogEx(INFO, "SFI.... not assigned");
else
PrintAndLogEx(INFO, "SFI.... 0x%02x", attr[1]);
if (attr[1] == 0)
PrintAndLogEx(INFO, "SFI.... not assigned");
else
PrintAndLogEx(INFO, "SFI.... 0x%02x", attr[1]);
PrintAndLogEx(INFO, "File ID... 0x%02x%02x", attr[2], attr[3]);
PrintAndLogEx(INFO, "File ID... 0x%02x%02x", attr[2], attr[3]);
if (attr[0] == 0x01 || attr[0] == 0x11)
PrintAndLogEx(INFO, "File size... %d", (attr[4] << 8) + attr[5]);
else
PrintAndLogEx(INFO, "Record num " _YELLOW_("%d") " record size " _YELLOW_("%d"), attr[4], attr[5]);
if (attr[0] == 0x01 || attr[0] == 0x11)
PrintAndLogEx(INFO, "File size... %d", (attr[4] << 8) + attr[5]);
else
PrintAndLogEx(INFO, "Record num " _YELLOW_("%d") " record size " _YELLOW_("%d"), attr[4], attr[5]);
PrintAndLogEx(INFO, "Keys assigned... %d", attr[6]);
PrintAndLogEx(INFO, "Keys assigned... %d", attr[6]);
if (len >= 9) {
PrintAndLogEx(INFO, "SMR entries... %02x%02x", attr[7], attr[8]);
CIPURSEPrintSMR(&attr[7]);
}
if (len >= 9) {
PrintAndLogEx(INFO, "SMR entries... %02x%02x", attr[7], attr[8]);
CIPURSEPrintSMR(&attr[7]);
}
if (len >= 10) {
PrintAndLogEx(INFO, "ART... %s", sprint_hex(&attr[9], len - 9));
CIPURSEPrintART(&attr[9], len - 9);
if (len >= 10) {
PrintAndLogEx(INFO, "ART... %s", sprint_hex(&attr[9], len - 9));
CIPURSEPrintART(&attr[9], len - 9);
if (attr[6] + 1 != len - 9) {
PrintAndLogEx(WARNING, "ART length is wrong");
}
if (attr[6] + 1 != len - 9) {
PrintAndLogEx(WARNING, "ART length is wrong");
}
}
}
void CIPURSEPrintFileAttrEx(uint8_t *attr, size_t len, bool isDGI) {
@@ -559,7 +563,7 @@ void CIPURSEPrintFileAttrEx(uint8_t *attr, size_t len, bool isDGI) {
PrintAndLogEx(INFO, "Keys assigned... %d", keynum);
int idx = 7;
if ( keynum > 0) {
if (keynum > 0) {
if (len >= idx + 2) {
PrintAndLogEx(INFO, "SMR entries... %02x%02x", attr[idx], attr[idx + 1]);
CIPURSEPrintSMR(&attr[idx]);
@@ -620,7 +624,7 @@ void CIPURSEPrintFileUpdateAttr(uint8_t *attr, size_t len) {
PrintAndLogEx(INFO, "Keys assigned... %d", keynum);
size_t idx = 1;
if ( keynum > 0) {
if (keynum > 0) {
if (len >= idx + 2) {
PrintAndLogEx(INFO, "SMR entries... %02x%02x", attr[idx], attr[idx + 1]);
CIPURSEPrintSMR(&attr[idx]);
+42 -43
View File
@@ -187,9 +187,9 @@ static int CmdHFCipurseInfo(const char *Cmd) {
return PM3_SUCCESS;
}
static int CLIParseCommandParametersEx(CLIParserContext *ctx, size_t keyid, size_t aidid, size_t fidid, size_t chfidid, size_t sreqid, size_t srespid,
uint8_t *key, uint8_t *aid, size_t *aidlen, bool *useaid, uint16_t *fid, bool *usefid, uint16_t *chfid, bool *usechfid,
CipurseChannelSecurityLevel *sreq, CipurseChannelSecurityLevel *sresp) {
static int CLIParseCommandParametersEx(CLIParserContext *ctx, size_t keyid, size_t aidid, size_t fidid, size_t chfidid, size_t sreqid, size_t srespid,
uint8_t *key, uint8_t *aid, size_t *aidlen, bool *useaid, uint16_t *fid, bool *usefid, uint16_t *chfid, bool *usechfid,
CipurseChannelSecurityLevel *sreq, CipurseChannelSecurityLevel *sresp) {
uint8_t hdata[250] = {0};
int hdatalen = sizeof(hdata);
if (keyid) {
@@ -224,7 +224,7 @@ static int CLIParseCommandParametersEx(CLIParserContext *ctx, size_t keyid, size
*useaid = true;
} else {
memcpy(aid, defaultAID, defaultAIDLength);
*aidlen = defaultAIDLength;
*aidlen = defaultAIDLength;
}
}
@@ -312,16 +312,16 @@ static int CLIParseCommandParametersEx(CLIParserContext *ctx, size_t keyid, size
return PM3_SUCCESS;
}
static int CLIParseCommandParameters(CLIParserContext *ctx, size_t keyid, size_t aidid, size_t fidid, size_t sreqid, size_t srespid,
uint8_t *key, uint8_t *aid, size_t *aidlen, bool *useaid, uint16_t *fid, bool *usefid,
CipurseChannelSecurityLevel *sreq, CipurseChannelSecurityLevel *sresp) {
return CLIParseCommandParametersEx(ctx, keyid, aidid, fidid, 0, sreqid, srespid,
key, aid, aidlen, useaid, fid, usefid, NULL, NULL, sreq, sresp);
static int CLIParseCommandParameters(CLIParserContext *ctx, size_t keyid, size_t aidid, size_t fidid, size_t sreqid, size_t srespid,
uint8_t *key, uint8_t *aid, size_t *aidlen, bool *useaid, uint16_t *fid, bool *usefid,
CipurseChannelSecurityLevel *sreq, CipurseChannelSecurityLevel *sresp) {
return CLIParseCommandParametersEx(ctx, keyid, aidid, fidid, 0, sreqid, srespid,
key, aid, aidlen, useaid, fid, usefid, NULL, NULL, sreq, sresp);
}
static int SelectCommandEx(bool selectDefaultFile, bool useAID, uint8_t *aid, size_t aidLen, bool useFID, uint16_t fileId,
bool selChildFile, uint16_t childFileId, bool verbose,
uint8_t *buf, size_t bufSize, size_t *len, uint16_t *sw) {
static int SelectCommandEx(bool selectDefaultFile, bool useAID, uint8_t *aid, size_t aidLen, bool useFID, uint16_t fileId,
bool selChildFile, uint16_t childFileId, bool verbose,
uint8_t *buf, size_t bufSize, size_t *len, uint16_t *sw) {
int res = 0;
if (verbose && selChildFile)
PrintAndLogEx(INFO, "Select top level application/file");
@@ -381,7 +381,7 @@ static int SelectCommandEx(bool selectDefaultFile, bool useAID, uint8_t *aid, si
}
static int SelectCommand(bool selectDefaultFile, bool useAID, uint8_t *aid, size_t aidLen, bool useFID, uint16_t fileId, bool verbose,
uint8_t *buf, size_t bufSize, size_t *len, uint16_t *sw) {
uint8_t *buf, size_t bufSize, size_t *len, uint16_t *sw) {
return SelectCommandEx(selectDefaultFile, useAID, aid, aidLen, useFID, fileId, false, 0, verbose, buf, bufSize, len, sw);
}
@@ -852,9 +852,9 @@ static int CmdHFCipurseReadFileAttr(const char *Cmd) {
if (!noAuth)
PrintAndLogEx(INFO, "Key id " _YELLOW_("%d") " key " _YELLOW_("%s")
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
}
if (noAuth == false) {
@@ -989,9 +989,9 @@ static int CmdHFCipurseWriteFileAttr(const char *Cmd) {
if (!noAuth)
PrintAndLogEx(INFO, "Key id " _YELLOW_("%d") " key " _YELLOW_("%s")
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
}
if (noAuth == false) {
@@ -1085,9 +1085,9 @@ static int CmdHFCipurseFormatAll(const char *Cmd) {
PrintAndLogEx(WARNING, _YELLOW_("FORMAT erases all the data at this card!!!"));
if (!noauth)
PrintAndLogEx(INFO, "key id " _YELLOW_("%d") " key " _YELLOW_("%s")
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
}
if (!noauth) {
@@ -1121,7 +1121,7 @@ static int CmdHFCipurseCreateDGI(const char *Cmd) {
"Create application/file/key by provide appropriate DGI. If no key is supplied, default key of 737373...7373 will be used",
"hf cipurse create -d 9200123F00200008000062098407A0000005070100 -> create PTSE file with FID 0x2000 and space for 8 AIDs\n"
"hf cipurse create -d 92002438613F010A050200004040FF021009021009621084054144204631D407A0000005070100A00F28"
"73737373737373737373737373737373015FD67B000102030405060708090A0B0C0D0E0F01C6A13B -> create default file with FID 3F01 and 2 keys\n"
"73737373737373737373737373737373015FD67B000102030405060708090A0B0C0D0E0F01C6A13B -> create default file with FID 3F01 and 2 keys\n"
"hf cipurse create --aid 4144204631 -d 92010C010001020030020000FFFFFF -> create 0x0102 binary data EF under application 4144204631\n");
void *argtable[] = {
@@ -1208,9 +1208,9 @@ static int CmdHFCipurseCreateDGI(const char *Cmd) {
if (verbose) {
if (!noauth)
PrintAndLogEx(INFO, "key id " _YELLOW_("%d") " key " _YELLOW_("%s")
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
}
if (!noauth) {
@@ -1228,8 +1228,8 @@ static int CmdHFCipurseCreateDGI(const char *Cmd) {
res = CIPURSECreateFile(hdata, hdatalen, buf, sizeof(buf), &len, &sw);
if (res != 0 || sw != 0x9000) {
PrintAndLogEx(ERR, "Create file command " _RED_("ERROR") ". Card returns:\n 0x%04x - %s", sw,
GetSpecificAPDUCodeDesc(SelectAPDUCodeDescriptions, ARRAYLEN(SelectAPDUCodeDescriptions), sw));
PrintAndLogEx(ERR, "Create file command " _RED_("ERROR") ". Card returns:\n 0x%04x - %s", sw,
GetSpecificAPDUCodeDesc(SelectAPDUCodeDescriptions, ARRAYLEN(SelectAPDUCodeDescriptions), sw));
DropField();
return PM3_ESOFT;
}
@@ -1282,7 +1282,7 @@ static int CmdHFCipurseDeleteFile(const char *Cmd) {
CipurseChannelSecurityLevel sreq = CPSMACed;
CipurseChannelSecurityLevel sresp = CPSMACed;
uint8_t key[CIPURSE_AES_KEY_LENGTH] = {0};
uint8_t aid[16] = {0};
size_t aidLen = 0;
bool useAID = false;
@@ -1314,9 +1314,9 @@ static int CmdHFCipurseDeleteFile(const char *Cmd) {
if (!noauth)
PrintAndLogEx(INFO, "key id " _YELLOW_("%d") " key " _YELLOW_("%s")
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
, keyId
, sprint_hex(key, CIPURSE_AES_KEY_LENGTH)
);
}
uint8_t buf[APDU_RES_LEN] = {0};
@@ -1331,7 +1331,7 @@ static int CmdHFCipurseDeleteFile(const char *Cmd) {
return PM3_ESOFT;
}
} else {
res = CIPURSESelectMFEx(true, true, buf, sizeof(buf), &len, &sw);
res = CIPURSESelectMFEx(true, true, buf, sizeof(buf), &len, &sw);
if (res != 0 || sw != 0x9000) {
PrintAndLogEx(ERR, "Cipurse masterfile select " _RED_("error") ". Card returns 0x%04x", sw);
DropField();
@@ -1355,8 +1355,8 @@ static int CmdHFCipurseDeleteFile(const char *Cmd) {
if (useChildFID) {
res = CIPURSEDeleteFile(childFileId, buf, sizeof(buf), &len, &sw);
if (res != 0 || sw != 0x9000) {
PrintAndLogEx(ERR, "Delete child file " _CYAN_("%04x ") _RED_("ERROR") ". Card returns:\n 0x%04x - %s", childFileId, sw,
GetSpecificAPDUCodeDesc(DeleteAPDUCodeDescriptions, ARRAYLEN(DeleteAPDUCodeDescriptions), sw));
PrintAndLogEx(ERR, "Delete child file " _CYAN_("%04x ") _RED_("ERROR") ". Card returns:\n 0x%04x - %s", childFileId, sw,
GetSpecificAPDUCodeDesc(DeleteAPDUCodeDescriptions, ARRAYLEN(DeleteAPDUCodeDescriptions), sw));
DropField();
return PM3_ESOFT;
}
@@ -1364,8 +1364,8 @@ static int CmdHFCipurseDeleteFile(const char *Cmd) {
} else if (useFID) {
res = CIPURSEDeleteFile(fileId, buf, sizeof(buf), &len, &sw);
if (res != 0 || sw != 0x9000) {
PrintAndLogEx(ERR, "Delete file " _CYAN_("%04x ") _RED_("ERROR") ". Card returns:\n 0x%04x - %s", fileId, sw,
GetSpecificAPDUCodeDesc(DeleteAPDUCodeDescriptions, ARRAYLEN(DeleteAPDUCodeDescriptions), sw));
PrintAndLogEx(ERR, "Delete file " _CYAN_("%04x ") _RED_("ERROR") ". Card returns:\n 0x%04x - %s", fileId, sw,
GetSpecificAPDUCodeDesc(DeleteAPDUCodeDescriptions, ARRAYLEN(DeleteAPDUCodeDescriptions), sw));
DropField();
return PM3_ESOFT;
}
@@ -1373,10 +1373,10 @@ static int CmdHFCipurseDeleteFile(const char *Cmd) {
} else {
res = CIPURSEDeleteFileAID(aid, aidLen, buf, sizeof(buf), &len, &sw);
if (res != 0 || sw != 0x9000) {
PrintAndLogEx(ERR, "Delete application " _CYAN_("%s ") _RED_("ERROR") ". Card returns:\n 0x%04x - %s",
sprint_hex_inrow(aid, aidLen),
sw,
GetSpecificAPDUCodeDesc(DeleteAPDUCodeDescriptions, ARRAYLEN(DeleteAPDUCodeDescriptions), sw));
PrintAndLogEx(ERR, "Delete application " _CYAN_("%s ") _RED_("ERROR") ". Card returns:\n 0x%04x - %s",
sprint_hex_inrow(aid, aidLen),
sw,
GetSpecificAPDUCodeDesc(DeleteAPDUCodeDescriptions, ARRAYLEN(DeleteAPDUCodeDescriptions), sw));
DropField();
return PM3_ESOFT;
}
@@ -1464,14 +1464,13 @@ static int CmdHFCipurseDefault(const char *Cmd) {
CLIParserFree(ctx);
PrintAndLogEx(INFO, "------------------- " _CYAN_("Default parameters") " -------------------");
PrintAndLogEx(INFO, "Key ID : %d", defaultKeyId);
PrintAndLogEx(INFO, "Key : %s", sprint_hex(defaultKey, sizeof(defaultKey)));
PrintAndLogEx(INFO, "AID : %s", sprint_hex(defaultAID, defaultAIDLength));
PrintAndLogEx(INFO, "File ID: 0x%04x", defaultFileId);
return PM3_SUCCESS;
}
+3 -3
View File
@@ -467,7 +467,7 @@ static void emv_tag_dump_bitmask(const struct tlv *tlv, const struct emv_tag *ta
unsigned char val = tlv->value[byte - 1];
PrintAndLogEx(INFO, "%*s" NOLF, (level * 4), " ");
PrintAndLogEx(NORMAL, " Byte %u (%02x)", byte, val);
for (bit = 8; bit > 0; bit--, val <<= 1) {
if (val & 0x80) {
PrintAndLogEx(INFO, "%*s" NOLF, (level * 4), " ");
@@ -491,7 +491,7 @@ static void emv_tag_dump_dol(const struct tlv *tlv, const struct emv_tag *tag, i
const struct emv_tag *doltag;
if (!tlv_parse_tl(&buf, &left, &doltlv)) {
PrintAndLogEx(INFO, "%*sInvalid Tag-Len" , (level * 4), " ");
PrintAndLogEx(INFO, "%*sInvalid Tag-Len", (level * 4), " ");
continue;
}
@@ -557,7 +557,7 @@ static uint32_t emv_get_binary(const unsigned char *S) {
// https://github.com/binaryfoo/emv-bertlv/blob/master/src/main/resources/fields/visa-cvr.txt
static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, int level) {
if (tlv == NULL || tlv->len < 1) {
PrintAndLogEx(INFO, "%*s INVALID length!" , (level * 4), " ");
PrintAndLogEx(INFO, "%*s INVALID length!", (level * 4), " ");
return;
}