make style

This commit is contained in:
Grayson Martin 2023-07-11 15:42:30 -05:00
commit 8af75cb220
No known key found for this signature in database
GPG key ID: 4914C62F2696A273
4 changed files with 128 additions and 127 deletions

View file

@ -1151,43 +1151,43 @@ static int CmdSmartBruteforceSFI(const char *Cmd) {
}
static void atsToEmulatedAtr(uint8_t *ats, uint8_t *atr, int *atrLen) {
int historicalLen = 0;
int offset = 2;
int historicalLen = 0;
int offset = 2;
if (ats[0] < 2) {
historicalLen = 0;
} else {
if (ats[0] < 2) {
historicalLen = 0;
} else {
if ((ats[1] & 64) != 0) {
offset++;
}
if ((ats[1] & 32) != 0) {
offset++;
}
if ((ats[1] & 16) != 0) {
offset++;
}
if ((ats[1] & 64) != 0) {
offset++;
}
if ((ats[1] & 32) != 0) {
offset++;
}
if ((ats[1] & 16) != 0) {
offset++;
}
if (offset >= ats[0]) {
historicalLen = 0;
} else {
historicalLen = ats[0] - offset;
}
}
if (offset >= ats[0]) {
historicalLen = 0;
} else {
historicalLen = ats[0] - offset;
}
}
atr[0] = 0x3B;
atr[1] = 0x80 | historicalLen;
atr[2] = 0x80;
atr[3] = 0x01;
uint8_t tck = 0;
for (int i = 0; i < historicalLen; ++i) {
atr[4 + i] = ats[offset + i];
tck = tck ^ ats[offset + i];
}
atr[4 + historicalLen] = tck;
atr[0] = 0x3B;
atr[1] = 0x80 | historicalLen;
atr[2] = 0x80;
atr[3] = 0x01;
*atrLen = 5 + historicalLen;
uint8_t tck = 0;
for (int i = 0; i < historicalLen; ++i) {
atr[4 + i] = ats[offset + i];
tck = tck ^ ats[offset + i];
}
atr[4 + historicalLen] = tck;
*atrLen = 5 + historicalLen;
}
static int CmdRelay(const char *Cmd) {
@ -1199,113 +1199,113 @@ static int CmdRelay(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str0(NULL, "host", "<str>", "vpcd socket host (default: localhost)"),
arg_str0(NULL, "host", "<str>", "vpcd socket host (default: localhost)"),
arg_str0("p", "port", "<int>", "vpcd socket port (default: 35963)"),
arg_lit0("v", "verbose", "display APDU transactions between OS and card"),
arg_lit0("v", "verbose", "display APDU transactions between OS and card"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
uint8_t host[100] = {0};
int hostLen = sizeof(host);
CLIGetStrWithReturn(ctx, 1, host, &hostLen);
if (hostLen == 0) {
strcpy((char *) host, "localhost");
}
uint8_t host[100] = {0};
int hostLen = sizeof(host);
CLIGetStrWithReturn(ctx, 1, host, &hostLen);
if (hostLen == 0) {
strcpy((char *) host, "localhost");
}
uint8_t port[6] = {0};
int portLen = sizeof(port);
CLIGetStrWithReturn(ctx, 2, port, &portLen);
if (portLen == 0) {
strcpy((char *) port, "35963");
}
uint8_t port[6] = {0};
int portLen = sizeof(port);
CLIGetStrWithReturn(ctx, 2, port, &portLen);
if (portLen == 0) {
strcpy((char *) port, "35963");
}
bool verbose = arg_get_lit(ctx, 3);
bool verbose = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
CLIParserFree(ctx);
mbedtls_net_context netCtx;
mbedtls_net_init(&netCtx);
mbedtls_net_context netCtx;
mbedtls_net_init(&netCtx);
PrintAndLogEx(INFO, "Relaying pm3 to host OS pcsc daemon. Press " _GREEN_("Enter") " to exit");
PrintAndLogEx(INFO, "Relaying pm3 to host OS pcsc daemon. Press " _GREEN_("Enter") " to exit");
uint8_t cmdbuf[512] = {0};
bool haveCard = false;
iso14a_card_select_t selectedCard;
uint8_t cmdbuf[512] = {0};
bool haveCard = false;
iso14a_card_select_t selectedCard;
do {
if (haveCard) {
int bytesRead = mbedtls_net_recv_timeout(&netCtx, cmdbuf, sizeof(cmdbuf), 100);
do {
if (haveCard) {
int bytesRead = mbedtls_net_recv_timeout(&netCtx, cmdbuf, sizeof(cmdbuf), 100);
if (bytesRead == MBEDTLS_ERR_SSL_TIMEOUT || bytesRead == MBEDTLS_ERR_SSL_WANT_READ) {
continue;
}
if (bytesRead == MBEDTLS_ERR_SSL_TIMEOUT || bytesRead == MBEDTLS_ERR_SSL_WANT_READ) {
continue;
}
if (bytesRead > 0) {
if (cmdbuf[1] == 0x01 && cmdbuf[2] == 0x04) { // vpcd GET ATR
uint8_t atr[20] = {0};
int atrLen = 0;
atsToEmulatedAtr(selectedCard.ats, atr, &atrLen);
if (bytesRead > 0) {
if (cmdbuf[1] == 0x01 && cmdbuf[2] == 0x04) { // vpcd GET ATR
uint8_t atr[20] = {0};
int atrLen = 0;
atsToEmulatedAtr(selectedCard.ats, atr, &atrLen);
uint8_t res[22] = {0};
res[1] = atrLen;
memcpy(res + 2, atr, atrLen);
mbedtls_net_send(&netCtx, res, 2 + atrLen);
} else if (cmdbuf[1] != 0x01) { // vpcd APDU
int apduLen = (cmdbuf[0] << 8) + cmdbuf[1];
uint8_t res[22] = {0};
res[1] = atrLen;
memcpy(res + 2, atr, atrLen);
mbedtls_net_send(&netCtx, res, 2 + atrLen);
} else if (cmdbuf[1] != 0x01) { // vpcd APDU
int apduLen = (cmdbuf[0] << 8) + cmdbuf[1];
uint8_t apduRes[APDU_RES_LEN] = {0};
int apduResLen = 0;
if (verbose) {
PrintAndLogEx(INFO, ">> %s", sprint_hex(cmdbuf + 2, apduLen));
}
uint8_t apduRes[APDU_RES_LEN] = {0};
int apduResLen = 0;
if (ExchangeAPDU14a(cmdbuf + 2, apduLen, true, true, apduRes, sizeof(apduRes), &apduResLen) != PM3_SUCCESS) {
haveCard = false;
mbedtls_net_close(&netCtx);
continue;
}
if (verbose) {
PrintAndLogEx(INFO, ">> %s", sprint_hex(cmdbuf + 2, apduLen));
}
if (verbose) {
PrintAndLogEx(INFO, "<< %s", sprint_hex(apduRes, apduResLen));
}
if (ExchangeAPDU14a(cmdbuf + 2, apduLen, true, true, apduRes, sizeof(apduRes), &apduResLen) != PM3_SUCCESS) {
haveCard = false;
mbedtls_net_close(&netCtx);
continue;
}
uint8_t res[APDU_RES_LEN + 2] = {0};
res[0] = (apduResLen >> 8) & 0xFF;
res[1] = apduResLen & 0xFF;
memcpy(res + 2, apduRes, apduResLen);
mbedtls_net_send(&netCtx, res, 2 + apduResLen);
}
}
} else {
if (SelectCard14443A_4(false, false, &selectedCard) == PM3_SUCCESS) {
if (mbedtls_net_connect(&netCtx, (char *) host, (char *) port, MBEDTLS_NET_PROTO_TCP)) {
PrintAndLogEx(FAILED, "Failed to connect to vpcd socket. Ensure you have vpcd installed and running");
mbedtls_net_close(&netCtx);
mbedtls_net_free(&netCtx);
DropField();
return PM3_EINVARG;
}
if (verbose) {
PrintAndLogEx(INFO, "<< %s", sprint_hex(apduRes, apduResLen));
}
haveCard = true;
}
msleep(300);
}
} while (!kbd_enter_pressed());
uint8_t res[APDU_RES_LEN + 2] = {0};
res[0] = (apduResLen >> 8) & 0xFF;
res[1] = apduResLen & 0xFF;
memcpy(res + 2, apduRes, apduResLen);
mbedtls_net_send(&netCtx, res, 2 + apduResLen);
}
}
} else {
if (SelectCard14443A_4(false, false, &selectedCard) == PM3_SUCCESS) {
if (mbedtls_net_connect(&netCtx, (char *) host, (char *) port, MBEDTLS_NET_PROTO_TCP)) {
PrintAndLogEx(FAILED, "Failed to connect to vpcd socket. Ensure you have vpcd installed and running");
mbedtls_net_close(&netCtx);
mbedtls_net_free(&netCtx);
DropField();
return PM3_EINVARG;
}
mbedtls_net_close(&netCtx);
mbedtls_net_free(&netCtx);
DropField();
haveCard = true;
}
msleep(300);
}
} while (!kbd_enter_pressed());
return PM3_SUCCESS;
mbedtls_net_close(&netCtx);
mbedtls_net_free(&netCtx);
DropField();
return PM3_SUCCESS;
}
static command_t CommandTable[] = {
{"help", CmdHelp, AlwaysAvailable, "This help"},
{"list", CmdSmartList, AlwaysAvailable, "List ISO 7816 history"},
{"info", CmdSmartInfo, IfPm3Smartcard, "Tag information"},
{"relay", CmdRelay, IfPm3Iso14443a, "Turn pm3 into pcsc reader and relay to host OS via vpcd"},
{"relay", CmdRelay, IfPm3Iso14443a, "Turn pm3 into pcsc reader and relay to host OS via vpcd"},
{"reader", CmdSmartReader, IfPm3Smartcard, "Act like an IS07816 reader"},
{"raw", CmdSmartRaw, IfPm3Smartcard, "Send raw hex data to tag"},
{"upgrade", CmdSmartUpgrade, AlwaysAvailable, "Upgrade sim module firmware"},

View file

@ -75,7 +75,7 @@ static void PrintChannel(Iso7816CommandChannel channel) {
}
}
static int emv_parse_track1(const uint8_t *d, size_t n, bool verbose){
static int emv_parse_track1(const uint8_t *d, size_t n, bool verbose) {
if (d == NULL || n < 10) {
return PM3_EINVARG;
}
@ -89,20 +89,20 @@ static int emv_parse_track1(const uint8_t *d, size_t n, bool verbose){
}
// decoder
char *tmp = str_ndup((const char*)d, n);
char *tmp = str_ndup((const char *)d, n);
uint8_t i = 0;
char delim[2] = "^";
char *token = strtok(tmp, delim);
while (token != NULL) {
switch(i) {
switch (i) {
case 0:
PrintAndLogEx(INFO, "PAN...................... %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c",
token[1], token[2],token[3], token[4],
token[5], token[6],token[7], token[8],
token[9], token[10],token[11], token[12],
token[13], token[14],token[15], token[16]
);
token[1], token[2], token[3], token[4],
token[5], token[6], token[7], token[8],
token[9], token[10], token[11], token[12],
token[13], token[14], token[15], token[16]
);
break;
case 1:
PrintAndLogEx(INFO, "CardHolder............... %s", token);
@ -121,7 +121,7 @@ static int emv_parse_track1(const uint8_t *d, size_t n, bool verbose){
token += 4;
PrintAndLogEx(INFO, "CVV / iCvv............... %.*s", 3, token);
token +=3;
token += 3;
PrintAndLogEx(INFO, "Trailing................. %s", token);
break;
@ -152,11 +152,11 @@ static int emv_parse_track2(const uint8_t *d, size_t n, bool verbose) {
tmp++;
PrintAndLogEx(INFO, "PAN...................... %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c",
tmp[0], tmp[1], tmp[2],tmp[3],
tmp[4], tmp[5], tmp[6],tmp[7],
tmp[8], tmp[9], tmp[10],tmp[11],
tmp[12],tmp[13], tmp[14],tmp[15]
);
tmp[0], tmp[1], tmp[2], tmp[3],
tmp[4], tmp[5], tmp[6], tmp[7],
tmp[8], tmp[9], tmp[10], tmp[11],
tmp[12], tmp[13], tmp[14], tmp[15]
);
tmp += 16;
if (tmp[0] == '=' || tmp[0] == 'D')
@ -172,7 +172,7 @@ static int emv_parse_track2(const uint8_t *d, size_t n, bool verbose) {
tmp += 4;
PrintAndLogEx(INFO, "CVV / iCvv............... %.*s", 3, tmp);
tmp +=3;
tmp += 3;
PrintAndLogEx(INFO, "Trailing................. %s", tmp);

View file

@ -1050,7 +1050,7 @@ static int ndefDecodePayload(NDEFHeader_t *ndef, bool verbose) {
if (str_startswith(begin, NDEF_BLUEAPPL_EP)) {
ndefDecodeMime_bt(ndef);
ndefDecodeMime_bt(ndef);
}
if (str_startswith(begin, NDEF_BLUEAPPL_SECURE_LE)) {
ndefDecodeMime_bt_secure_le_oob(ndef);

View file

@ -771,6 +771,7 @@ const static vocabulory_t vocabulory[] = {
{ 1, "smart help" },
{ 1, "smart list" },
{ 0, "smart info" },
{ 0, "smart relay" },
{ 0, "smart reader" },
{ 0, "smart raw" },
{ 1, "smart upgrade" },