From e65263c73be6bf057a7cffe2555438ab6dbea51c Mon Sep 17 00:00:00 2001 From: Grayson Martin Date: Sat, 11 Nov 2023 14:32:09 -0600 Subject: [PATCH] run make style --- client/src/cmdsmartcard.c | 100 +++++++++++++------------- client/src/pm3line_vocabulary.h | 1 + doc/commands.json | 19 ++++- doc/commands.md | 1 + tools/mf_nonce_brute/mf_nonce_brute.c | 14 ++-- tools/mfkey/nested_util.c | 2 +- tools/mfkey/nested_util.h | 2 +- tools/mfkey/staticnested.c | 2 +- 8 files changed, 79 insertions(+), 62 deletions(-) diff --git a/client/src/cmdsmartcard.c b/client/src/cmdsmartcard.c index 2fada5563..2d6ed052a 100644 --- a/client/src/cmdsmartcard.c +++ b/client/src/cmdsmartcard.c @@ -1205,21 +1205,21 @@ static void atsToEmulatedAtr(uint8_t *ats, uint8_t *atr, int *atrLen) { } static void atqbToEmulatedAtr(uint8_t *atqb, uint8_t cid, uint8_t *atr, int *atrLen) { - atr[0] = 0x3B; - atr[1] = 0x80 | 8; - atr[2] = 0x80; - atr[3] = 0x01; + atr[0] = 0x3B; + atr[1] = 0x80 | 8; + atr[2] = 0x80; + atr[3] = 0x01; - memcpy(atr + 4, atqb, 7); - atr[11] = cid >> 4; + memcpy(atr + 4, atqb, 7); + atr[11] = cid >> 4; - uint8_t tck = 0; - for (int i = 1; i < 12; ++i) { - tck = tck ^ atr[i]; - } - atr[12] = tck; + uint8_t tck = 0; + for (int i = 1; i < 12; ++i) { + tck = tck ^ atr[i]; + } + atr[12] = tck; - *atrLen = 13; + *atrLen = 13; } static int CmdRelay(const char *Cmd) { @@ -1263,9 +1263,9 @@ static int CmdRelay(const char *Cmd) { uint8_t cmdbuf[512] = {0}; iso14a_card_select_t selectedCard14a; - iso14b_card_select_t selectedCard14b; - isodep_state_t cardType = ISODEP_INACTIVE; - bool fieldActivated = false; + iso14b_card_select_t selectedCard14b; + isodep_state_t cardType = ISODEP_INACTIVE; + bool fieldActivated = false; do { if (cardType != ISODEP_INACTIVE) { @@ -1280,11 +1280,11 @@ static int CmdRelay(const char *Cmd) { uint8_t atr[20] = {0}; int atrLen = 0; - if (cardType == ISODEP_NFCA) { - atsToEmulatedAtr(selectedCard14a.ats, atr, &atrLen); - } else if (cardType == ISODEP_NFCB) { - atqbToEmulatedAtr(selectedCard14b.atqb, selectedCard14b.cid, atr, &atrLen); - } + if (cardType == ISODEP_NFCA) { + atsToEmulatedAtr(selectedCard14a.ats, atr, &atrLen); + } else if (cardType == ISODEP_NFCB) { + atqbToEmulatedAtr(selectedCard14b.atqb, selectedCard14b.cid, atr, &atrLen); + } uint8_t res[22] = {0}; res[1] = atrLen; @@ -1300,21 +1300,21 @@ static int CmdRelay(const char *Cmd) { PrintAndLogEx(INFO, ">> %s", sprint_hex(cmdbuf + 2, apduLen)); } - if (cardType == ISODEP_NFCA) { - if (ExchangeAPDU14a(cmdbuf + 2, apduLen, !fieldActivated, true, apduRes, sizeof(apduRes), &apduResLen) != PM3_SUCCESS) { - cardType = ISODEP_INACTIVE; - mbedtls_net_close(&netCtx); - continue; - } - } else if (cardType == ISODEP_NFCB) { - if (exchange_14b_apdu(cmdbuf + 2, apduLen, !fieldActivated, true, apduRes, sizeof(apduRes), &apduResLen, 0)) { - cardType = ISODEP_INACTIVE; - mbedtls_net_close(&netCtx); - continue; - } - } + if (cardType == ISODEP_NFCA) { + if (ExchangeAPDU14a(cmdbuf + 2, apduLen, !fieldActivated, true, apduRes, sizeof(apduRes), &apduResLen) != PM3_SUCCESS) { + cardType = ISODEP_INACTIVE; + mbedtls_net_close(&netCtx); + continue; + } + } else if (cardType == ISODEP_NFCB) { + if (exchange_14b_apdu(cmdbuf + 2, apduLen, !fieldActivated, true, apduRes, sizeof(apduRes), &apduResLen, 0)) { + cardType = ISODEP_INACTIVE; + mbedtls_net_close(&netCtx); + continue; + } + } - fieldActivated = true; + fieldActivated = true; if (verbose) { PrintAndLogEx(INFO, "<< %s", sprint_hex(apduRes, apduResLen)); @@ -1328,22 +1328,22 @@ static int CmdRelay(const char *Cmd) { } } } else { - if (IfPm3Iso14443a() && SelectCard14443A_4(false, false, &selectedCard14a) == PM3_SUCCESS) { - cardType = ISODEP_NFCA; - } else if (IfPm3Iso14443b() && select_card_14443b_4(false, &selectedCard14b) == PM3_SUCCESS) { - cardType = ISODEP_NFCB; - } - if (cardType != ISODEP_INACTIVE) { - fieldActivated = false; - 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; - } - } - msleep(300); + if (IfPm3Iso14443a() && SelectCard14443A_4(false, false, &selectedCard14a) == PM3_SUCCESS) { + cardType = ISODEP_NFCA; + } else if (IfPm3Iso14443b() && select_card_14443b_4(false, &selectedCard14b) == PM3_SUCCESS) { + cardType = ISODEP_NFCB; + } + if (cardType != ISODEP_INACTIVE) { + fieldActivated = false; + 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; + } + } + msleep(300); } } while (!kbd_enter_pressed()); diff --git a/client/src/pm3line_vocabulary.h b/client/src/pm3line_vocabulary.h index 46c33389d..48a2ecb91 100644 --- a/client/src/pm3line_vocabulary.h +++ b/client/src/pm3line_vocabulary.h @@ -791,6 +791,7 @@ const static vocabulary_t vocabulary[] = { { 1, "smart help" }, { 1, "smart list" }, { 0, "smart info" }, + { 0, "smart relay" }, { 0, "smart reader" }, { 0, "smart raw" }, { 1, "smart upgrade" }, diff --git a/doc/commands.json b/doc/commands.json index 03751cbe2..3320a9c5d 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -11790,6 +11790,21 @@ ], "usage": "smart reader [-hv]" }, + "smart relay": { + "command": "smart relay", + "description": "Make pm3 available to host OS smartcard driver via vpcd to enable use with other software such as GlobalPlatform Pro", + "notes": [ + "Requires the virtual smartcard daemon to be installed and running, see https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html" + ], + "offline": false, + "options": [ + "-h, --help This help", + "--host vpcd socket host (default: localhost)", + "-p, --port vpcd socket port (default: 35963)", + "-v, --verbose display APDU transactions between OS and card" + ], + "usage": "smart relay [-hv] [--host ] [-p ]" + }, "smart setclock": { "command": "smart setclock", "description": "Set clock speed for smart card interface.", @@ -12049,8 +12064,8 @@ } }, "metadata": { - "commands_extracted": 698, + "commands_extracted": 699, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2023-11-09T16:29:08" + "extracted_on": "2023-11-11T20:31:02" } } \ No newline at end of file diff --git a/doc/commands.md b/doc/commands.md index 94c3aa8ee..ef9dac251 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -1424,6 +1424,7 @@ Check column "offline" for their availability. |`smart help `|Y |`This help` |`smart list `|Y |`List ISO 7816 history` |`smart info `|N |`Tag information` +|`smart relay `|N |`Turn pm3 into pcsc reader and relay to host OS via vpcd` |`smart reader `|N |`Act like an IS07816 reader` |`smart raw `|N |`Send raw hex data to tag` |`smart upgrade `|Y |`Upgrade sim module firmware` diff --git a/tools/mf_nonce_brute/mf_nonce_brute.c b/tools/mf_nonce_brute/mf_nonce_brute.c index 63572da0d..1c00f4eef 100644 --- a/tools/mf_nonce_brute/mf_nonce_brute.c +++ b/tools/mf_nonce_brute/mf_nonce_brute.c @@ -525,7 +525,7 @@ static void *brute_thread(void *arguments) { free(revstate); continue; } - + // lock this section to avoid interlacing prints from different threats pthread_mutex_lock(&print_lock); if (args->ev1) { @@ -533,11 +533,11 @@ static void *brute_thread(void *arguments) { } #if 0 - printf("thread #%d idx %d %s\n", args->thread, args->idx, (args->ev1) ? "(Ev1)" : ""); - printf("current nt(%08x) ar_enc(%08x) at_enc(%08x)\n", nt, ar_enc, at_enc); - printf("ks2:%08x\n", ks2); - printf("ks3:%08x\n", ks3); - printf("ks4:%08x\n", ks4); + printf("thread #%d idx %d %s\n", args->thread, args->idx, (args->ev1) ? "(Ev1)" : ""); + printf("current nt(%08x) ar_enc(%08x) at_enc(%08x)\n", nt, ar_enc, at_enc); + printf("ks2:%08x\n", ks2); + printf("ks3:%08x\n", ks3); + printf("ks4:%08x\n", ks4); #endif if (cmd_enc) { uint32_t decrypted = ks4 ^ cmd_enc; @@ -681,7 +681,7 @@ int main(int argc, const char *argv[]) { // next encrypted command + a full read/write int enc_len = 0; - uint8_t enc[ENC_LEN] = {0}; + uint8_t enc[ENC_LEN] = {0}; if (argc > 9) { param_gethex_to_eol(argv[9], 0, enc, sizeof(enc), &enc_len); cmd_enc = (enc[0] << 24 | enc[1] << 16 | enc[2] << 8 | enc[3]); diff --git a/tools/mfkey/nested_util.c b/tools/mfkey/nested_util.c index 239fe5d88..4b2b86c4c 100644 --- a/tools/mfkey/nested_util.c +++ b/tools/mfkey/nested_util.c @@ -235,7 +235,7 @@ uint64_t *nested(NtpKs1 *pNK, uint32_t sizePNK, uint32_t authuid, uint32_t *keyC free(pRPs); return NULL; } - + for (i = 0; i < TRY_KEYS; i++) { // We don't known this key, try to break it // This key can be found here two or more times diff --git a/tools/mfkey/nested_util.h b/tools/mfkey/nested_util.h index fa0e1552d..140d99414 100644 --- a/tools/mfkey/nested_util.h +++ b/tools/mfkey/nested_util.h @@ -12,4 +12,4 @@ typedef struct { uint8_t valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t *parity); uint64_t *nested(NtpKs1 *pNK, uint32_t sizePNK, uint32_t authuid, uint32_t *keyCount); -#endif \ No newline at end of file +#endif diff --git a/tools/mfkey/staticnested.c b/tools/mfkey/staticnested.c index 70bade540..164dcaaa1 100644 --- a/tools/mfkey/staticnested.c +++ b/tools/mfkey/staticnested.c @@ -233,4 +233,4 @@ int main(int argc, char *const argv[]) { exit(EXIT_SUCCESS); error: exit(EXIT_FAILURE); -} \ No newline at end of file +}