Skip to content

Commit

Permalink
works... massive cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
n-hutton committed Nov 21, 2024
1 parent 5f1b2b4 commit aa19ce8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 321 deletions.
281 changes: 29 additions & 252 deletions armsrc/emvsim.c

Large diffs are not rendered by default.

19 changes: 1 addition & 18 deletions armsrc/emvsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,8 @@

#include "common.h"

#ifndef CheckCrc14A
# define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len))
#endif

#define AC_DATA_READ 0
#define AC_DATA_WRITE 1
#define AC_DATA_INC 2
#define AC_DATA_DEC_TRANS_REST 3
#define AC_KEYA_READ 0
#define AC_KEYA_WRITE 1
#define AC_KEYB_READ 2
#define AC_KEYB_WRITE 3
#define AC_AC_READ 4
#define AC_AC_WRITE 5

#define AUTHKEYA 0
#define AUTHKEYB 1
#define AUTHKEYNONE 0xff

void EMVsim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint16_t atqa, uint8_t sak);

#endif
#endif
37 changes: 0 additions & 37 deletions client/src/emv/cmdemv.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
#include "crypto/libpcrypto.h"
#include "iso4217.h" // currency lookup

//static uint8_t PIV_APPLET[9] = "\xA0\x00\x00\x03\x08\x00\x00\x10\x00";

static int CmdHelp(const char *Cmd);

#define TLV_ADD(tag, value)( tlvdb_change_or_add_node(tlvRoot, tag, sizeof(value) - 1, (const unsigned char *)value) )
Expand Down Expand Up @@ -633,9 +631,6 @@ static int CmdEMVSelect(const char *Cmd) {

// hutton
static int CmdEMVSmartToNFC(const char *Cmd) {
//uint8_t data[APDU_AID_LEN] = {0}; // todo: consider removing/cleaning unused vars
//int datalen = 0;

CLIParserContext *ctx;
CLIParserInit(&ctx, "emv smart2nfc",
"Executes ISO14443a payment, TX using ISO7816 interface for authentication",
Expand All @@ -644,11 +639,6 @@ static int CmdEMVSmartToNFC(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_lit0("t", "test", "test that the attached card is working (must be VISA)"),
//arg_lit0("k", "keep", "Keep field for next command"),
//arg_lit0("a", "apdu", "Show APDU requests and responses"),
//arg_lit0("t", "tlv", "TLV decode results"),
//arg_lit0("w", "wired", "Send data via contact (iso7816) interface. (def: Contactless interface)"),
//arg_str1(NULL, NULL, "<hex>", "Choose a UID"),
arg_str0("u", "uid", "<hex>", "optional 7 hex bytes UID"),
arg_param_end
};
Expand All @@ -660,8 +650,6 @@ static int CmdEMVSmartToNFC(const char *Cmd) {

if (uid_len == 0) {
PrintAndLogEx(SUCCESS, "No UID provided, using default.");
//memcpy(applet_id, DEFAULT_UID, sizeof(DEFAULT_UID));
//aid_len = sizeof(DEFAULT_UID);
uint8_t default_uid[7] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77};
memcpy(uid, default_uid, sizeof(default_uid));
uid_len = sizeof(default_uid);
Expand All @@ -681,35 +669,11 @@ static int CmdEMVSmartToNFC(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Test mode disabled.");
}

//bool activateField = arg_get_lit(ctx, 1);
//bool leaveSignalON = arg_get_lit(ctx, 2);
//bool show_apdu = arg_get_lit(ctx, 3);
//bool decodeTLV = arg_get_lit(ctx, 4);
//Iso7816CommandChannel channel = CC_CONTACTLESS;
//if (arg_get_lit(ctx, 5))
// channel = CC_CONTACT;
//PrintChannel(channel);
//CLIGetHexWithReturn(ctx, 6, data, &datalen);
CLIParserFree(ctx);

// todo: check this is relevant for us.
SetAPDULogging(show_apdu);

//int res = EMVSmartToNFC(testMode);

//if (!res) {
// PrintAndLogEx(SUCCESS, "EMVSmartToNFC completed successfully.");
//} else {
// PrintAndLogEx(FAILED, "EMVSmartToNFC failed.");
//}

//struct {
// uint8_t tagtype;
// uint16_t flags;
// uint8_t uid[10];
// uint8_t exitAfter;
//} PACKED payload;

struct {
uint16_t flags;
uint8_t exitAfter;
Expand All @@ -725,7 +689,6 @@ static int CmdEMVSmartToNFC(const char *Cmd) {
payload.sak = 0x20;

clearCommandBuffer();
//SendCommandNG(CMD_HF_ISO14443A_EMV_SIMULATE, (uint8_t *)&payload, sizeof(payload));
SendCommandNG(0x0386, (uint8_t *)&payload, sizeof(payload));

PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " to abort simulation");
Expand Down
4 changes: 0 additions & 4 deletions client/src/emv/emvcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,6 @@ int EMVInternalAuthenticate(Iso7816CommandChannel channel, bool LeaveFieldON, ui
return EMVExchangeEx(channel, false, LeaveFieldON, (sAPDU_t) {0x00, 0x88, 0x00, 0x00, DDOLLen, DDOL}, true, Result, MaxResultLen, ResultLen, sw, tlv);
}

//int EMVSmartToNFC(bool TestMode) {
// return Iso7816SimulateTag(TestMode);
//}

int MSCComputeCryptoChecksum(Iso7816CommandChannel channel, bool LeaveFieldON, uint8_t *UDOL, uint8_t UDOLlen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv) {
int res = EMVExchangeEx(channel, false, LeaveFieldON, (sAPDU_t) {0x80, 0x2a, 0x8e, 0x80, UDOLlen, UDOL}, true, Result, MaxResultLen, ResultLen, sw, tlv);
if (*sw == 0x6700 || *sw == 0x6f00) {
Expand Down
2 changes: 0 additions & 2 deletions client/src/emv/emvcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ int EMVGenerateChallenge(Iso7816CommandChannel channel, bool LeaveFieldON, uint8
int EMVAC(Iso7816CommandChannel channel, bool LeaveFieldON, uint8_t RefControl, uint8_t *CDOL, size_t CDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
// DDA
int EMVInternalAuthenticate(Iso7816CommandChannel channel, bool LeaveFieldON, uint8_t *DDOL, size_t DDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
// Simulation of proxmark as a tag
//int EMVSmartToNFC(bool TestMode); // todo: probs delete...
// Mastercard
int MSCComputeCryptoChecksum(Iso7816CommandChannel channel, bool LeaveFieldON, uint8_t *UDOL, uint8_t UDOLlen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
// Auth
Expand Down
5 changes: 0 additions & 5 deletions client/src/iso7816/iso7816core.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "ui.h"
#include "cmdhf14a.h"
#include "cmdhf14b.h"
//#include "evmsim.h" // todo: remove
#include "iso14b.h" // iso14b_raw_cmd_t
#include "util_posix.h"
#include "protocols.h" // ISO7816 APDU return codes
Expand Down Expand Up @@ -217,7 +216,3 @@ int Iso7816Select(Iso7816CommandChannel channel, bool activate_field, bool leave
, sw
);
}

//int Iso7816SimulateTag(bool testing) {
// return Evmsim(testing);
//}
3 changes: 0 additions & 3 deletions client/src/iso7816/iso7816core.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,4 @@ int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool activate_field, bool l
int Iso7816Select(Iso7816CommandChannel channel, bool activate_field, bool leave_field_on, uint8_t *aid, size_t aid_len,
uint8_t *result, size_t max_result_len, size_t *result_len, uint16_t *sw);

// simulate being a contactless smart card using ISO7816 interface
//int Iso7816SimulateTag(bool activate_field);

#endif

0 comments on commit aa19ce8

Please sign in to comment.