make style

This commit is contained in:
Philippe Teuwen 2023-01-14 22:22:04 +01:00
commit 5d5d9d9be0
14 changed files with 262 additions and 529 deletions

View file

@ -30,11 +30,11 @@
#define MODULE_LONG_NAME "LF Nedap simple simulator" #define MODULE_LONG_NAME "LF Nedap simple simulator"
typedef struct _NEDAP_TAG { typedef struct _NEDAP_TAG {
uint8_t subType; uint8_t subType;
uint16_t customerCode; uint16_t customerCode;
uint32_t id; uint32_t id;
uint8_t bIsLong; uint8_t bIsLong;
} NEDAP_TAG, *PNEDAP_TAG; } NEDAP_TAG, *PNEDAP_TAG;
const NEDAP_TAG Tag = {.subType = 0x5, .customerCode = 0x123, .id = 42424, .bIsLong = 1}; const NEDAP_TAG Tag = {.subType = 0x5, .customerCode = 0x123, .id = 42424, .bIsLong = 1};
@ -46,78 +46,67 @@ static uint8_t isEven_64_63(const uint8_t *data);
static inline uint32_t bitcount32(uint32_t a); static inline uint32_t bitcount32(uint32_t a);
static void bytes_to_bytebits(const void *src, const size_t srclen, void *dest); static void bytes_to_bytebits(const void *src, const size_t srclen, void *dest);
void ModInfo(void) void ModInfo(void) {
{
DbpString(" " MODULE_LONG_NAME); DbpString(" " MODULE_LONG_NAME);
} }
void RunMod(void) void RunMod(void) {
{ int n;
int n;
StandAloneMode(); StandAloneMode();
Dbprintf("[=] " MODULE_LONG_NAME " -- started"); Dbprintf("[=] " MODULE_LONG_NAME " -- started");
FpgaDownloadAndGo(FPGA_BITSTREAM_LF); FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
Dbprintf("[=] NEDAP (%s) - ID: " _GREEN_("%05u") " subtype: " _GREEN_("%1u") " customer code: " _GREEN_("%u / 0x%03X"), Tag.bIsLong ? "128b" : "64b", Tag.id, Tag.subType, Tag.customerCode, Tag.customerCode); Dbprintf("[=] NEDAP (%s) - ID: " _GREEN_("%05u") " subtype: " _GREEN_("%1u") " customer code: " _GREEN_("%u / 0x%03X"), Tag.bIsLong ? "128b" : "64b", Tag.id, Tag.subType, Tag.customerCode, Tag.customerCode);
n = NedapPrepareBigBuffer(&Tag); n = NedapPrepareBigBuffer(&Tag);
do do {
{
WDT_HIT(); WDT_HIT();
if (data_available()) if (data_available())
break; break;
SimulateTagLowFrequency(n, 0, true);
SimulateTagLowFrequency(n, 0, true);
} while (BUTTON_HELD(1000) == BUTTON_NO_CLICK); } while (BUTTON_HELD(1000) == BUTTON_NO_CLICK);
Dbprintf("[=] " MODULE_LONG_NAME " -- exiting"); Dbprintf("[=] " MODULE_LONG_NAME " -- exiting");
LEDsoff(); LEDsoff();
} }
static int NedapPrepareBigBuffer(const NEDAP_TAG *pTag) static int NedapPrepareBigBuffer(const NEDAP_TAG *pTag) {
{ int ret = 0;
int ret = 0; uint8_t data[16], bitStream[sizeof(data) * 8], phase = 0;
uint8_t data[16], bitStream[sizeof(data) * 8], phase = 0; uint16_t i, size = pTag->bIsLong ? sizeof(data) : (sizeof(data) / 2);
uint16_t i, size = pTag->bIsLong ? sizeof(data) : (sizeof(data) / 2);
NedapGen(pTag->subType, pTag->customerCode, pTag->id, pTag->bIsLong, data);
NedapGen(pTag->subType, pTag->customerCode, pTag->id, pTag->bIsLong, data); bytes_to_bytebits(data, size, bitStream);
bytes_to_bytebits(data, size, bitStream); size <<= 3;
size <<= 3;
for (i = 0; i < size; i++) {
for (i = 0; i < size; i++) biphaseSimBitInverted(!bitStream[i], &ret, &phase);
{ }
biphaseSimBitInverted(!bitStream[i], &ret, &phase); if (phase == 1) { //run a second set inverted to keep phase in check
} for (i = 0; i < size; i++) {
if (phase == 1) //run a second set inverted to keep phase in check biphaseSimBitInverted(!bitStream[i], &ret, &phase);
{ }
for (i = 0; i < size; i++) }
{
biphaseSimBitInverted(!bitStream[i], &ret, &phase); return ret;
}
}
return ret;
} }
static void biphaseSimBitInverted(uint8_t c, int *n, uint8_t *phase) static void biphaseSimBitInverted(uint8_t c, int *n, uint8_t *phase) {
{ uint8_t *dest = BigBuf_get_addr();
uint8_t *dest = BigBuf_get_addr();
if (c) if (c) {
{ memset(dest + (*n), c ^ 1 ^ *phase, 32);
memset(dest + (*n), c ^ 1 ^ *phase, 32); memset(dest + (*n) + 32, c ^ *phase, 32);
memset(dest + (*n) + 32, c ^ *phase, 32); } else {
} memset(dest + (*n), c ^ *phase, 64);
else *phase ^= 1;
{ }
memset(dest + (*n), c ^ *phase, 64); *n += 64;
*phase ^= 1;
}
*n += 64;
} }
#define FIXED_71 0x71 #define FIXED_71 0x71
@ -190,13 +179,11 @@ static uint8_t isEven_64_63(const uint8_t *data) { // 8
return (bitcount32(tmp[0]) + (bitcount32(tmp[1] & 0xfeffffff))) & 1; return (bitcount32(tmp[0]) + (bitcount32(tmp[1] & 0xfeffffff))) & 1;
} }
static void bytes_to_bytebits(const void *src, const size_t srclen, void *dest) static void bytes_to_bytebits(const void *src, const size_t srclen, void *dest) {
{
uint8_t *s = (uint8_t *)src, *d = (uint8_t *)dest; uint8_t *s = (uint8_t *)src, *d = (uint8_t *)dest;
size_t i = srclen * 8, j = srclen; size_t i = srclen * 8, j = srclen;
while (j--) while (j--) {
{
uint8_t b = s[j]; uint8_t b = s[j];
d[--i] = (b >> 0) & 1; d[--i] = (b >> 0) & 1;
d[--i] = (b >> 1) & 1; d[--i] = (b >> 1) & 1;
@ -209,8 +196,7 @@ static void bytes_to_bytebits(const void *src, const size_t srclen, void *dest)
} }
} }
static inline uint32_t bitcount32(uint32_t a) static inline uint32_t bitcount32(uint32_t a) {
{
#if defined __GNUC__ #if defined __GNUC__
return __builtin_popcountl(a); return __builtin_popcountl(a);
#else #else

View file

@ -1964,11 +1964,11 @@ int infoHF_EMRTD_offline(const char *path) {
strncat(filepath, PATHSEP, 2); strncat(filepath, PATHSEP, 2);
strcat(filepath, dg_table[EF_COM].filename); strcat(filepath, dg_table[EF_COM].filename);
if ((loadFile_safeEx(filepath, ".BIN", (void **)&data, (size_t *)&datalen, false) != PM3_SUCCESS) && if ((loadFile_safeEx(filepath, ".BIN", (void **)&data, (size_t *)&datalen, false) != PM3_SUCCESS) &&
(loadFile_safeEx(filepath, ".bin", (void **)&data, (size_t *)&datalen, false) != PM3_SUCCESS)) { (loadFile_safeEx(filepath, ".bin", (void **)&data, (size_t *)&datalen, false) != PM3_SUCCESS)) {
PrintAndLogEx(ERR, "Failed to read EF_COM"); PrintAndLogEx(ERR, "Failed to read EF_COM");
free(filepath); free(filepath);
return PM3_ESOFT; return PM3_ESOFT;
} }
int res = emrtd_print_ef_com_info(data, datalen); int res = emrtd_print_ef_com_info(data, datalen);
@ -1999,9 +1999,9 @@ int infoHF_EMRTD_offline(const char *path) {
strcat(filepath, dg_table[EF_CardAccess].filename); strcat(filepath, dg_table[EF_CardAccess].filename);
if ((loadFile_safeEx(filepath, ".BIN", (void **)&data, (size_t *)&datalen, false) == PM3_SUCCESS) || if ((loadFile_safeEx(filepath, ".BIN", (void **)&data, (size_t *)&datalen, false) == PM3_SUCCESS) ||
(loadFile_safeEx(filepath, ".bin", (void **)&data, (size_t *)&datalen, false) == PM3_SUCCESS)) { (loadFile_safeEx(filepath, ".bin", (void **)&data, (size_t *)&datalen, false) == PM3_SUCCESS)) {
emrtd_print_ef_cardaccess_info(data, datalen); emrtd_print_ef_cardaccess_info(data, datalen);
free(data); free(data);
} else { } else {
PrintAndLogEx(HINT, "The error above this is normal. It just means that your eMRTD lacks PACE"); PrintAndLogEx(HINT, "The error above this is normal. It just means that your eMRTD lacks PACE");
} }
@ -2010,11 +2010,11 @@ int infoHF_EMRTD_offline(const char *path) {
strncat(filepath, PATHSEP, 2); strncat(filepath, PATHSEP, 2);
strcat(filepath, dg_table[EF_SOD].filename); strcat(filepath, dg_table[EF_SOD].filename);
if ((loadFile_safeEx(filepath, ".BIN", (void **)&data, (size_t *)&datalen, false) != PM3_SUCCESS) && if ((loadFile_safeEx(filepath, ".BIN", (void **)&data, (size_t *)&datalen, false) != PM3_SUCCESS) &&
(loadFile_safeEx(filepath, ".bin", (void **)&data, (size_t *)&datalen, false) != PM3_SUCCESS)) { (loadFile_safeEx(filepath, ".bin", (void **)&data, (size_t *)&datalen, false) != PM3_SUCCESS)) {
PrintAndLogEx(ERR, "Failed to read EF_SOD"); PrintAndLogEx(ERR, "Failed to read EF_SOD");
free(filepath); free(filepath);
return PM3_ESOFT; return PM3_ESOFT;
} }
// coverity scan CID 395630, // coverity scan CID 395630,
@ -2040,7 +2040,7 @@ int infoHF_EMRTD_offline(const char *path) {
strncat(filepath, PATHSEP, 2); strncat(filepath, PATHSEP, 2);
strcat(filepath, dg->filename); strcat(filepath, dg->filename);
if ((loadFile_safeEx(filepath, ".BIN", (void **)&data, (size_t *)&datalen, false) == PM3_SUCCESS) || if ((loadFile_safeEx(filepath, ".BIN", (void **)&data, (size_t *)&datalen, false) == PM3_SUCCESS) ||
(loadFile_safeEx(filepath, ".bin", (void **)&data, (size_t *)&datalen, false) == PM3_SUCCESS)) { (loadFile_safeEx(filepath, ".bin", (void **)&data, (size_t *)&datalen, false) == PM3_SUCCESS)) {
// we won't halt on parsing errors // we won't halt on parsing errors
if (dg->parser != NULL) { if (dg->parser != NULL) {
dg->parser(data, datalen); dg->parser(data, datalen);
@ -2111,7 +2111,7 @@ static int CmdHFeMRTDDump(const char *Cmd) {
if (CLIParamStrToBuf(arg_get_str(ctx, 1), docnum, 9, &slen) != 0 || slen == 0) { if (CLIParamStrToBuf(arg_get_str(ctx, 1), docnum, 9, &slen) != 0 || slen == 0) {
BAC = false; BAC = false;
} else { } else {
strn_upper((char*)docnum, slen); strn_upper((char *)docnum, slen);
if (slen != 9) { if (slen != 9) {
// Pad to 9 with < // Pad to 9 with <
memset(docnum + slen, '<', 9 - slen); memset(docnum + slen, '<', 9 - slen);
@ -2144,7 +2144,7 @@ static int CmdHFeMRTDDump(const char *Cmd) {
error = true; error = true;
} else { } else {
BAC = true; BAC = true;
strn_upper((char*)mrz, slen); strn_upper((char *)mrz, slen);
memcpy(docnum, &mrz[0], 9); memcpy(docnum, &mrz[0], 9);
memcpy(dob, &mrz[13], 6); memcpy(dob, &mrz[13], 6);
memcpy(expiry, &mrz[21], 6); memcpy(expiry, &mrz[21], 6);
@ -2213,7 +2213,7 @@ static int CmdHFeMRTDInfo(const char *Cmd) {
if (CLIParamStrToBuf(arg_get_str(ctx, 1), docnum, 9, &slen) != 0 || slen == 0) { if (CLIParamStrToBuf(arg_get_str(ctx, 1), docnum, 9, &slen) != 0 || slen == 0) {
BAC = false; BAC = false;
} else { } else {
strn_upper((char*)docnum, slen); strn_upper((char *)docnum, slen);
if (slen != 9) { if (slen != 9) {
memset(docnum + slen, '<', 9 - slen); memset(docnum + slen, '<', 9 - slen);
} }
@ -2245,7 +2245,7 @@ static int CmdHFeMRTDInfo(const char *Cmd) {
error = true; error = true;
} else { } else {
BAC = true; BAC = true;
strn_upper((char*)mrz, slen); strn_upper((char *)mrz, slen);
memcpy(docnum, &mrz[0], 9); memcpy(docnum, &mrz[0], 9);
memcpy(dob, &mrz[13], 6); memcpy(dob, &mrz[13], 6);
memcpy(expiry, &mrz[21], 6); memcpy(expiry, &mrz[21], 6);

View file

@ -569,7 +569,7 @@ static int CmdHF14AMfWrBl(const char *Cmd) {
uint8_t blockno = (uint8_t)b; uint8_t blockno = (uint8_t)b;
// Sector trailer sanity checks. // Sector trailer sanity checks.
// Warn if ACL is strict read-only, or invalid ACL. // Warn if ACL is strict read-only, or invalid ACL.
if (mfIsSectorTrailer(blockno)) { if (mfIsSectorTrailer(blockno)) {
PrintAndLogEx(INFO, "Sector trailer (ST) write detected"); PrintAndLogEx(INFO, "Sector trailer (ST) write detected");

View file

@ -1376,7 +1376,7 @@ static int mfu_fingerprint(TagTypeUL_t tagtype, bool hasAuthKey, uint8_t *authke
} }
} }
// OTP checks // OTP checks
mfu_otp_identify_t *item = mfu_match_otp_fingerprint(data); mfu_otp_identify_t *item = mfu_match_otp_fingerprint(data);
if (item) { if (item) {
PrintAndLogEx(SUCCESS, "Found " _GREEN_("%s"), item->desc); PrintAndLogEx(SUCCESS, "Found " _GREEN_("%s"), item->desc);
@ -1391,9 +1391,9 @@ static int mfu_fingerprint(TagTypeUL_t tagtype, bool hasAuthKey, uint8_t *authke
} }
} }
} }
// //
out: out:
free(data); free(data);

View file

@ -264,7 +264,7 @@ static int CmdParadoxClone(const char *Cmd) {
} }
uint32_t blocks[4]; uint32_t blocks[4];
if (raw_len != 0) { if (raw_len != 0) {
if (raw_len != 12) { if (raw_len != 12) {
PrintAndLogEx(ERR, "Data must be 12 bytes (24 HEX characters) %d", raw_len); PrintAndLogEx(ERR, "Data must be 12 bytes (24 HEX characters) %d", raw_len);
@ -280,39 +280,39 @@ static int CmdParadoxClone(const char *Cmd) {
manchester[0] = 0x0F; // preamble manchester[0] = 0x0F; // preamble
manchester[1] = 0x05; // Leading zeros - Note: from this byte on, is part of the CRC calculation manchester[1] = 0x05; // Leading zeros - Note: from this byte on, is part of the CRC calculation
manchester[2] = 0x55; // Leading zeros its 4 bits out for the CRC, so we need too move manchester[2] = 0x55; // Leading zeros its 4 bits out for the CRC, so we need too move
manchester[3] = 0x55; // Leading zeros back 4 bits once we have the crc (done below) manchester[3] = 0x55; // Leading zeros back 4 bits once we have the crc (done below)
// add FC // add FC
t1 = manchesterEncode2Bytes (fc); t1 = manchesterEncode2Bytes(fc);
manchester[4] = (t1 >> 8) & 0xFF; manchester[4] = (t1 >> 8) & 0xFF;
manchester[5] = t1 & 0xFF; manchester[5] = t1 & 0xFF;
// add cn // add cn
t1 = manchesterEncode2Bytes (cn); t1 = manchesterEncode2Bytes(cn);
manchester[6] = (t1 >> 24) & 0xFF; manchester[6] = (t1 >> 24) & 0xFF;
manchester[7] = (t1 >> 16) & 0xFF; manchester[7] = (t1 >> 16) & 0xFF;
manchester[8] = (t1 >> 8) & 0xFF; manchester[8] = (t1 >> 8) & 0xFF;
manchester[9] = t1 & 0xFF; manchester[9] = t1 & 0xFF;
uint8_t crc = (CRC8Maxim(manchester+1, 9) ^ 0x6) & 0xFF; uint8_t crc = (CRC8Maxim(manchester + 1, 9) ^ 0x6) & 0xFF;
// add crc // add crc
t1 = manchesterEncode2Bytes (crc); t1 = manchesterEncode2Bytes(crc);
manchester[10] = (t1 >> 8) & 0xFF; manchester[10] = (t1 >> 8) & 0xFF;
manchester[11] = t1 & 0xFF; manchester[11] = t1 & 0xFF;
// move left 4 bits left 4 bits - Now that we have the CRC we need to re-align the data. // move left 4 bits left 4 bits - Now that we have the CRC we need to re-align the data.
for (int i = 1; i < 12; i++) for (int i = 1; i < 12; i++)
manchester[i] = (manchester[i] << 4) + (manchester[i+1] >> 4); manchester[i] = (manchester[i] << 4) + (manchester[i + 1] >> 4);
// Add trailing 1010 (11) // Add trailing 1010 (11)
manchester[11] |= (1 << 3); manchester[11] |= (1 << 3);
manchester[11] |= (1 << 1); manchester[11] |= (1 << 1);
// move into tag blocks // move into tag blocks
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
blocks[1 + (i/4)] += (manchester[i] << (8 * (3 - i % 4))); blocks[1 + (i / 4)] += (manchester[i] << (8 * (3 - i % 4)));
} }
// Paradox - FSK2a, data rate 50, 3 data blocks // Paradox - FSK2a, data rate 50, 3 data blocks

View file

@ -66,7 +66,7 @@ static const struct piv_container PIV_CONTAINERS[] = {
{0x0100, PIV_TAG_ID("\x5F\xC1\x0A"), 3, PIV_CONDITIONAL, "X.509 Certificate for Digital Signature (key ref 9C)"}, {0x0100, PIV_TAG_ID("\x5F\xC1\x0A"), 3, PIV_CONDITIONAL, "X.509 Certificate for Digital Signature (key ref 9C)"},
{0x0102, PIV_TAG_ID("\x5F\xC1\x0B"), 3, PIV_CONDITIONAL, "X.509 Certificate for Key Management (key ref 9D)"}, {0x0102, PIV_TAG_ID("\x5F\xC1\x0B"), 3, PIV_CONDITIONAL, "X.509 Certificate for Key Management (key ref 9D)"},
{0x3001, PIV_TAG_ID("\x5F\xC1\x09"), 3, PIV_OPTIONAL, "Printed Information"}, {0x3001, PIV_TAG_ID("\x5F\xC1\x09"), 3, PIV_OPTIONAL, "Printed Information"},
{0x6050, PIV_TAG_ID( "\x7E"), 1, PIV_OPTIONAL, "Discovery Object"}, {0x6050, PIV_TAG_ID("\x7E"), 1, PIV_OPTIONAL, "Discovery Object"},
{0x6060, PIV_TAG_ID("\x5F\xC1\x0C"), 3, PIV_OPTIONAL, "Key History Object"}, {0x6060, PIV_TAG_ID("\x5F\xC1\x0C"), 3, PIV_OPTIONAL, "Key History Object"},
{0x1001, PIV_TAG_ID("\x5F\xC1\x0D"), 3, PIV_OPTIONAL, "Retired X.509 Certificate for Key Management 1 (key ref 82)"}, {0x1001, PIV_TAG_ID("\x5F\xC1\x0D"), 3, PIV_OPTIONAL, "Retired X.509 Certificate for Key Management 1 (key ref 82)"},
{0x1002, PIV_TAG_ID("\x5F\xC1\x0E"), 3, PIV_OPTIONAL, "Retired X.509 Certificate for Key Management 2 (key ref 83)"}, {0x1002, PIV_TAG_ID("\x5F\xC1\x0E"), 3, PIV_OPTIONAL, "Retired X.509 Certificate for Key Management 2 (key ref 83)"},
@ -89,7 +89,7 @@ static const struct piv_container PIV_CONTAINERS[] = {
{0x1013, PIV_TAG_ID("\x5F\xC1\x1F"), 3, PIV_OPTIONAL, "Retired X.509 Certificate for Key Management 19 (key ref 94)"}, {0x1013, PIV_TAG_ID("\x5F\xC1\x1F"), 3, PIV_OPTIONAL, "Retired X.509 Certificate for Key Management 19 (key ref 94)"},
{0x1014, PIV_TAG_ID("\x5F\xC1\x20"), 3, PIV_OPTIONAL, "Retired X.509 Certificate for Key Management 20 (key ref 95)"}, {0x1014, PIV_TAG_ID("\x5F\xC1\x20"), 3, PIV_OPTIONAL, "Retired X.509 Certificate for Key Management 20 (key ref 95)"},
{0x1015, PIV_TAG_ID("\x5F\xC1\x21"), 3, PIV_OPTIONAL, "Cardholder Iris Images"}, {0x1015, PIV_TAG_ID("\x5F\xC1\x21"), 3, PIV_OPTIONAL, "Cardholder Iris Images"},
{0x1016, PIV_TAG_ID( "\x7F\x61"), 2, PIV_OPTIONAL, "Biometric Information Templates Group Template"}, {0x1016, PIV_TAG_ID("\x7F\x61"), 2, PIV_OPTIONAL, "Biometric Information Templates Group Template"},
{0x1017, PIV_TAG_ID("\x5F\xC1\x22"), 3, PIV_OPTIONAL, "Secure Messaging Certificate Signer"}, {0x1017, PIV_TAG_ID("\x5F\xC1\x22"), 3, PIV_OPTIONAL, "Secure Messaging Certificate Signer"},
{0x1018, PIV_TAG_ID("\x5F\xC1\x23"), 3, PIV_OPTIONAL, "Pairing Code Reference Data Container"}, {0x1018, PIV_TAG_ID("\x5F\xC1\x23"), 3, PIV_OPTIONAL, "Pairing Code Reference Data Container"},
PIV_CONTAINER_FINISH, PIV_CONTAINER_FINISH,
@ -493,13 +493,13 @@ static void piv_print_cb(void *data, const struct tlv *tlv, int level, bool is_l
} }
} }
static void PrintTLV(const struct tlvdb* tlvdb) { static void PrintTLV(const struct tlvdb *tlvdb) {
if (tlvdb) { if (tlvdb) {
tlvdb_visit(tlvdb, piv_print_cb, NULL, 0); tlvdb_visit(tlvdb, piv_print_cb, NULL, 0);
} }
} }
static void PrintTLVFromBuffer(const uint8_t* buf, size_t len) { static void PrintTLVFromBuffer(const uint8_t *buf, size_t len) {
if (buf == NULL || len == 0) { if (buf == NULL || len == 0) {
return; return;
} }
@ -598,7 +598,7 @@ static int PivGetData(Iso7816CommandChannel channel, const uint8_t tag[], size_t
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int PivGetDataByCidAndPrint(Iso7816CommandChannel channel, const struct piv_container* cid, bool decodeTLV, bool verbose) { static int PivGetDataByCidAndPrint(Iso7816CommandChannel channel, const struct piv_container *cid, bool decodeTLV, bool verbose) {
struct tlvdb_root *root = NULL; struct tlvdb_root *root = NULL;
if (cid == NULL) { if (cid == NULL) {

View file

@ -258,13 +258,13 @@ static size_t path_size(savePaths_t a) {
if (a == spItemCount) { if (a == spItemCount) {
return 0; return 0;
} }
return strlen( g_session.defaultPaths[a] ); return strlen(g_session.defaultPaths[a]);
} }
char *newfilenamemcopy(const char *preferredName, const char *suffix) { char *newfilenamemcopy(const char *preferredName, const char *suffix) {
if (preferredName == NULL || suffix == NULL) { if (preferredName == NULL || suffix == NULL) {
return NULL; return NULL;
} }
uint16_t p_namelen = strlen(preferredName); uint16_t p_namelen = strlen(preferredName);
if (str_endswith(preferredName, suffix)) if (str_endswith(preferredName, suffix))
@ -328,7 +328,7 @@ int saveFileEML(const char *preferredName, uint8_t *data, size_t datalen, size_t
} }
char *fileName = newfilenamemcopy(preferredName, ".eml"); char *fileName = newfilenamemcopy(preferredName, ".eml");
if (fileName == NULL) { if (fileName == NULL) {
return PM3_EMALLOC; return PM3_EMALLOC;
} }

View file

@ -1466,7 +1466,7 @@ int convert_mfc_2_arr(uint8_t *in, uint16_t ilen, uint8_t *out, uint16_t *olen)
ilen -= MFBLOCK_SIZE; ilen -= MFBLOCK_SIZE;
*olen += MFBLOCK_SIZE; *olen += MFBLOCK_SIZE;
} }
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static const vigik_pk_t vigik_rsa_pk[] = { static const vigik_pk_t vigik_rsa_pk[] = {
@ -1502,7 +1502,7 @@ static void reverse_array(const uint8_t *src, int src_len, uint8_t *dest) {
int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature_len) { int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature_len) {
// iso9796 // iso9796
// Exponent V = 2 // Exponent V = 2
// n = The public modulus n is the product of the secret prime factors p and q. Its length is 1024 bits. // n = The public modulus n is the product of the secret prime factors p and q. Its length is 1024 bits.
if (g_debugMode == DEBUG) { if (g_debugMode == DEBUG) {
@ -1527,7 +1527,7 @@ int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature
// signature = h( C || M1 || h(M2) ) // signature = h( C || M1 || h(M2) )
// 1024 - 786 - 160 - 16 -1 // 1024 - 786 - 160 - 16 -1
// salt C // salt C
// message M = 96 bytes, 768 bits // message M = 96 bytes, 768 bits
// sha1 hash H = 20 bytes, 160 bits // sha1 hash H = 20 bytes, 160 bits
// padding = 20 bytes, 96 bits // padding = 20 bytes, 96 bits
@ -1563,18 +1563,18 @@ int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature
mbedtls_mpi_init(&sqr); mbedtls_mpi_init(&sqr);
mbedtls_mpi_init(&res); mbedtls_mpi_init(&res);
mbedtls_mpi_read_binary(&N, (const unsigned char*)n, PUBLIC_VIGIK_KEYLEN); mbedtls_mpi_read_binary(&N, (const unsigned char *)n, PUBLIC_VIGIK_KEYLEN);
//mbedtls_mpi_read_binary(&s, (const unsigned char*)signature, signature_len); //mbedtls_mpi_read_binary(&s, (const unsigned char*)signature, signature_len);
mbedtls_mpi_read_binary(&s, (const unsigned char*)rev_sig, signature_len); mbedtls_mpi_read_binary(&s, (const unsigned char *)rev_sig, signature_len);
// check is sign < (N/2) // check is sign < (N/2)
mbedtls_mpi n_2; mbedtls_mpi n_2;
mbedtls_mpi_init(&n_2); mbedtls_mpi_init(&n_2);
mbedtls_mpi_copy(&n_2, &N); mbedtls_mpi_copy(&n_2, &N);
mbedtls_mpi_shift_r(&n_2, 1); mbedtls_mpi_shift_r(&n_2, 1);
bool is_less = (mbedtls_mpi_cmp_mpi(&s, &n_2) > 0) ? false : true; bool is_less = (mbedtls_mpi_cmp_mpi(&s, &n_2) > 0) ? false : true;
PrintAndLogEx(DEBUG, "z < (N/2) ..... %s", (is_less) ? _GREEN_("YES") : _RED_("NO")); PrintAndLogEx(DEBUG, "z < (N/2) ..... %s", (is_less) ? _GREEN_("YES") : _RED_("NO"));
mbedtls_mpi_free(&n_2); mbedtls_mpi_free(&n_2);
@ -1644,10 +1644,10 @@ int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature
PrintAndLogEx(DEBUG, "LSB............ " _GREEN_("%u"), lsb); PrintAndLogEx(DEBUG, "LSB............ " _GREEN_("%u"), lsb);
if (g_debugMode == DEBUG) { if (g_debugMode == DEBUG) {
mbedtls_mpi_write_file( "[=] N.............. ", &N, 16, NULL ); mbedtls_mpi_write_file("[=] N.............. ", &N, 16, NULL);
mbedtls_mpi_write_file( "[=] signature...... ", &s, 16, NULL ); mbedtls_mpi_write_file("[=] signature...... ", &s, 16, NULL);
mbedtls_mpi_write_file( "[=] square mod n... ", &sqr, 16, NULL ); mbedtls_mpi_write_file("[=] square mod n... ", &sqr, 16, NULL);
mbedtls_mpi_write_file( "[=] n-fs........... ", &res, 16, NULL ); mbedtls_mpi_write_file("[=] n-fs........... ", &res, 16, NULL);
} }
@ -1656,9 +1656,9 @@ int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature
// xor 0xDC01 // xor 0xDC01
int count_zero = 0; int count_zero = 0;
for (int x = 0; x < sizeof(nfs); x +=2) { for (int x = 0; x < sizeof(nfs); x += 2) {
nfs[x] ^= 0xDC; nfs[x] ^= 0xDC;
nfs[x+1] ^= 0x01; nfs[x + 1] ^= 0x01;
if (nfs[x] == 0x00) if (nfs[x] == 0x00)
count_zero++; count_zero++;
@ -1689,10 +1689,10 @@ int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature
PrintAndLogEx(INFO, "Hash byte... 0x%02X", ts.hash); PrintAndLogEx(INFO, "Hash byte... 0x%02X", ts.hash);
switch(ts.rsa[126]) { switch(ts.rsa[126]) {
case 0x11: case 0x11:
PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - SHA1"); PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - SHA1");
break; break;
case 0x22: case 0x22:
PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - RIPEMD"); PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - RIPEMD");
break; break;
case 0x33: case 0x33:
PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - SHA1"); PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - SHA1");
@ -1711,7 +1711,7 @@ int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature
print_hex_noascii_break(ts.rsa, sizeof(ts.rsa) - 20, 32); print_hex_noascii_break(ts.rsa, sizeof(ts.rsa) - 20, 32);
} }
*/ */
mbedtls_mpi_free(&N); mbedtls_mpi_free(&N);
mbedtls_mpi_free(&s); mbedtls_mpi_free(&s);
mbedtls_mpi_free(&res); mbedtls_mpi_free(&res);
@ -1722,7 +1722,7 @@ int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature
PrintAndLogEx(INFO, ""); PrintAndLogEx(INFO, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Signature")); PrintAndLogEx(INFO, "--- " _CYAN_("Tag Signature"));
PrintAndLogEx(INFO, "RSA: 1024bit"); PrintAndLogEx(INFO, "RSA: 1024bit");
if (is_valid == false || i == ARRAYLEN(vigik_rsa_pk)) { if (is_valid == false || i == ARRAYLEN(vigik_rsa_pk)) {
PrintAndLogEx(INFO, "Signature:"); PrintAndLogEx(INFO, "Signature:");
print_hex_noascii_break(signature, signature_len, MFBLOCK_SIZE * 2); print_hex_noascii_break(signature, signature_len, MFBLOCK_SIZE * 2);
@ -1736,7 +1736,7 @@ int vigik_verify(uint8_t *uid, uint8_t uidlen, uint8_t *signature, int signature
PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n + 64); PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n + 64);
PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n + 128); PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n + 128);
PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n + 192); PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n + 192);
PrintAndLogEx(INFO, "Signature:"); PrintAndLogEx(INFO, "Signature:");
print_hex_noascii_break(signature, signature_len, MFBLOCK_SIZE * 2); print_hex_noascii_break(signature, signature_len, MFBLOCK_SIZE * 2);
@ -1749,7 +1749,7 @@ int vigik_annotate(uint8_t *d) {
if (d == NULL) if (d == NULL)
return PM3_EINVARG; return PM3_EINVARG;
mfc_vigik_t *foo = (mfc_vigik_t*)d; mfc_vigik_t *foo = (mfc_vigik_t *)d;
PrintAndLogEx(INFO, "Manufacture......... %s", sprint_hex(foo->b0, sizeof(foo->b0))); PrintAndLogEx(INFO, "Manufacture......... %s", sprint_hex(foo->b0, sizeof(foo->b0)));
PrintAndLogEx(INFO, "MAD................. %s", sprint_hex(foo->mad, sizeof(foo->mad))); PrintAndLogEx(INFO, "MAD................. %s", sprint_hex(foo->mad, sizeof(foo->mad)));
@ -1773,4 +1773,4 @@ int vigik_annotate(uint8_t *d) {
PrintAndLogEx(INFO, ""); PrintAndLogEx(INFO, "");
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -244,11 +244,11 @@ const static vocabulory_t vocabulory[] = {
{ 1, "hf gallagher diversifykey" }, { 1, "hf gallagher diversifykey" },
{ 1, "hf gallagher decode" }, { 1, "hf gallagher decode" },
{ 1, "hf ksx6924 help" }, { 1, "hf ksx6924 help" },
{ 0, "hf ksx6924 select" },
{ 0, "hf ksx6924 info" },
{ 0, "hf ksx6924 balance" }, { 0, "hf ksx6924 balance" },
{ 0, "hf ksx6924 init" }, { 0, "hf ksx6924 info" },
{ 0, "hf ksx6924 initialize" },
{ 0, "hf ksx6924 prec" }, { 0, "hf ksx6924 prec" },
{ 0, "hf ksx6924 select" },
{ 1, "hf jooki help" }, { 1, "hf jooki help" },
{ 0, "hf jooki clone" }, { 0, "hf jooki clone" },
{ 1, "hf jooki decode" }, { 1, "hf jooki decode" },
@ -347,10 +347,6 @@ const static vocabulory_t vocabulory[] = {
{ 0, "hf mf gen3uid" }, { 0, "hf mf gen3uid" },
{ 0, "hf mf gen3blk" }, { 0, "hf mf gen3blk" },
{ 0, "hf mf gen3freeze" }, { 0, "hf mf gen3freeze" },
{ 0, "hf mf ggetblk" },
{ 0, "hf mf gload" },
{ 0, "hf mf gsave" },
{ 0, "hf mf gsetblk" },
{ 0, "hf mf gview" }, { 0, "hf mf gview" },
{ 0, "hf mf ndefformat" }, { 0, "hf mf ndefformat" },
{ 0, "hf mf ndefread" }, { 0, "hf mf ndefread" },
@ -380,7 +376,6 @@ const static vocabulory_t vocabulory[] = {
{ 1, "hf mfu view" }, { 1, "hf mfu view" },
{ 0, "hf mfu wrbl" }, { 0, "hf mfu wrbl" },
{ 0, "hf mfu eload" }, { 0, "hf mfu eload" },
{ 0, "hf mfu esave" },
{ 0, "hf mfu eview" }, { 0, "hf mfu eview" },
{ 0, "hf mfu sim" }, { 0, "hf mfu sim" },
{ 0, "hf mfu setpwd" }, { 0, "hf mfu setpwd" },
@ -589,7 +584,6 @@ const static vocabulory_t vocabulory[] = {
{ 0, "lf idteck clone" }, { 0, "lf idteck clone" },
{ 0, "lf idteck sim" }, { 0, "lf idteck sim" },
{ 1, "lf indala help" }, { 1, "lf indala help" },
{ 0, "lf indala brute" },
{ 1, "lf indala demod" }, { 1, "lf indala demod" },
{ 1, "lf indala altdemod" }, { 1, "lf indala altdemod" },
{ 0, "lf indala reader" }, { 0, "lf indala reader" },
@ -737,11 +731,6 @@ const static vocabulory_t vocabulory[] = {
{ 0, "nfc barcode read" }, { 0, "nfc barcode read" },
{ 0, "nfc barcode sim" }, { 0, "nfc barcode sim" },
{ 1, "nfc barcode help" }, { 1, "nfc barcode help" },
{ 1, "piv help" },
{ 0, "piv select" },
{ 0, "piv getdata" },
{ 0, "piv scan" },
{ 1, "piv list" },
{ 1, "smart help" }, { 1, "smart help" },
{ 1, "smart list" }, { 1, "smart list" },
{ 0, "smart info" }, { 0, "smart info" },

View file

@ -62,9 +62,9 @@ pthread_mutex_t g_print_lock = PTHREAD_MUTEX_INITIALIZER;
static void fPrintAndLog(FILE *stream, const char *fmt, ...); static void fPrintAndLog(FILE *stream, const char *fmt, ...);
#ifdef _WIN32 #ifdef _WIN32
#define MKDIR_CHK _mkdir(path) #define MKDIR_CHK _mkdir(path)
#else #else
#define MKDIR_CHK mkdir(path, 0700) #define MKDIR_CHK mkdir(path, 0700)
#endif #endif
@ -107,8 +107,7 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam
if ((result != 0) && create_home) { if ((result != 0) && create_home) {
if (MKDIR_CHK) if (MKDIR_CHK) {
{
fprintf(stderr, "Could not create user directory %s\n", path); fprintf(stderr, "Could not create user directory %s\n", path);
free(path); free(path);
return PM3_EFILE; return PM3_EFILE;
@ -140,8 +139,7 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam
if ((result != 0) && create_home) { if ((result != 0) && create_home) {
if (MKDIR_CHK) if (MKDIR_CHK) {
{
fprintf(stderr, "Could not create user directory %s\n", path); fprintf(stderr, "Could not create user directory %s\n", path);
free(path); free(path);
return PM3_EFILE; return PM3_EFILE;
@ -155,7 +153,7 @@ int searchHomeFilePath(char **foundpath, const char *subdir, const char *filenam
} }
pathlen += strlen(filename); pathlen += strlen(filename);
char *tmp = realloc(path, pathlen *sizeof(char)); char *tmp = realloc(path, pathlen * sizeof(char));
if (tmp == NULL) { if (tmp == NULL) {
//free(path); //free(path);
return PM3_EMALLOC; return PM3_EMALLOC;

File diff suppressed because it is too large Load diff

View file

@ -367,11 +367,11 @@ Check column "offline" for their availability.
|command |offline |description |command |offline |description
|------- |------- |----------- |------- |------- |-----------
|`hf ksx6924 help `|Y |`This help` |`hf ksx6924 help `|Y |`This help`
|`hf ksx6924 select `|N |`Select application, and leave field up`
|`hf ksx6924 info `|N |`Get info about a KS X 6924 (T-Money, Snapper+) transit card`
|`hf ksx6924 balance `|N |`Get current purse balance` |`hf ksx6924 balance `|N |`Get current purse balance`
|`hf ksx6924 init `|N |`Perform transaction initialization with Mpda` |`hf ksx6924 info `|N |`Get info about a KS X 6924 (T-Money, Snapper+) transit card`
|`hf ksx6924 initialize `|N |`Perform transaction initialization (Mpda)`
|`hf ksx6924 prec `|N |`Send proprietary get record command (CLA=90, INS=4C)` |`hf ksx6924 prec `|N |`Send proprietary get record command (CLA=90, INS=4C)`
|`hf ksx6924 select `|N |`Select application, and leave field up`
### hf jooki ### hf jooki
@ -510,10 +510,6 @@ Check column "offline" for their availability.
|`hf mf gen3uid `|N |`Set UID without changing manufacturer block` |`hf mf gen3uid `|N |`Set UID without changing manufacturer block`
|`hf mf gen3blk `|N |`Overwrite manufacturer block` |`hf mf gen3blk `|N |`Overwrite manufacturer block`
|`hf mf gen3freeze `|N |`Perma lock UID changes. irreversible` |`hf mf gen3freeze `|N |`Perma lock UID changes. irreversible`
|`hf mf ggetblk `|N |`Read block from card`
|`hf mf gload `|N |`Load dump to card`
|`hf mf gsave `|N |`Save dump from card into file or emulator`
|`hf mf gsetblk `|N |`Write block to card`
|`hf mf gview `|N |`View card` |`hf mf gview `|N |`View card`
|`hf mf ndefformat `|N |`Format MIFARE Classic Tag as NFC Tag` |`hf mf ndefformat `|N |`Format MIFARE Classic Tag as NFC Tag`
|`hf mf ndefread `|N |`Read and print NDEF records from card` |`hf mf ndefread `|N |`Read and print NDEF records from card`
@ -558,8 +554,7 @@ Check column "offline" for their availability.
|`hf mfu restore `|N |`Restore a dump onto a MFU MAGIC tag` |`hf mfu restore `|N |`Restore a dump onto a MFU MAGIC tag`
|`hf mfu view `|Y |`Display content from tag dump file` |`hf mfu view `|Y |`Display content from tag dump file`
|`hf mfu wrbl `|N |`Write block` |`hf mfu wrbl `|N |`Write block`
|`hf mfu eload `|N |`Load Ultralight dump file into emulator memory` |`hf mfu eload `|N |`Load Ultralight .eml dump file into emulator memory`
|`hf mfu esave `|N |`Save Ultralight dump file from emulator memory`
|`hf mfu eview `|N |`View emulator memory` |`hf mfu eview `|N |`View emulator memory`
|`hf mfu sim `|N |`Simulate MIFARE Ultralight from emulator memory` |`hf mfu sim `|N |`Simulate MIFARE Ultralight from emulator memory`
|`hf mfu setpwd `|N |`Set 3DES key - Ultralight-C` |`hf mfu setpwd `|N |`Set 3DES key - Ultralight-C`
@ -976,7 +971,6 @@ Check column "offline" for their availability.
|command |offline |description |command |offline |description
|------- |------- |----------- |------- |------- |-----------
|`lf indala help `|Y |`This help` |`lf indala help `|Y |`This help`
|`lf indala brute `|N |`Demodulate an Indala tag (PSK1) from the GraphBuffer`
|`lf indala demod `|Y |`Demodulate an Indala tag (PSK1) from the GraphBuffer` |`lf indala demod `|Y |`Demodulate an Indala tag (PSK1) from the GraphBuffer`
|`lf indala altdemod `|Y |`Alternative method to demodulate samples for Indala 64 bit UID (option '224' for 224 bit)` |`lf indala altdemod `|Y |`Alternative method to demodulate samples for Indala 64 bit UID (option '224' for 224 bit)`
|`lf indala reader `|N |`Read an Indala tag from the antenna` |`lf indala reader `|N |`Read an Indala tag from the antenna`
@ -1334,19 +1328,6 @@ Check column "offline" for their availability.
|`nfc barcode help `|Y |`This help` |`nfc barcode help `|Y |`This help`
### piv
{ PIV commands... }
|command |offline |description
|------- |------- |-----------
|`piv help `|Y |`This help`
|`piv select `|N |`Select the PIV applet`
|`piv getdata `|N |`Gets a container on a PIV card`
|`piv scan `|N |`Scan PIV card for known containers`
|`piv list `|Y |`List ISO7816 history`
### reveng ### reveng
{ CRC calculations from RevEng software... } { CRC calculations from RevEng software... }

View file

@ -42,4 +42,4 @@ typedef struct vigik_pk_s {
const char *n; const char *n;
} vigik_pk_t; } vigik_pk_t;
#endif #endif

View file

@ -506,7 +506,7 @@ ISO 7816-4 Basic interindustry commands. For command APDU's.
#define ISO7816_LC_TLV_CONFLICT 0x6A85 // LC / TLV conlict #define ISO7816_LC_TLV_CONFLICT 0x6A85 // LC / TLV conlict
#define ISO7816_INCORRECT_P1P2 0x6A86 // Incorrect parameters (P1,P2) #define ISO7816_INCORRECT_P1P2 0x6A86 // Incorrect parameters (P1,P2)
#define ISO7816_FILE_EXISTS 0x6A89 // File exists #define ISO7816_FILE_EXISTS 0x6A89 // File exists
#define ISO7816_NOT_IMPLEMENTED 0x6AFF // #define ISO7816_NOT_IMPLEMENTED 0x6AFF //
// 6x 00 // 6x 00
#define ISO7816_WRONG_P1P2 0x6B00 // Incorrect parameters (P1,P2) #define ISO7816_WRONG_P1P2 0x6B00 // Incorrect parameters (P1,P2)