CHG: '-DWITH_EMV' - fixing some compilation errors when compiling with peter fillmore's emv code. Warning a 256kb Proxmark3 device will only have 7% memory left if you enable this

This commit is contained in:
iceman1001 2017-02-05 21:09:36 +01:00
parent e772774ba1
commit 3e83ff2159
7 changed files with 91 additions and 57 deletions

View file

@ -11,14 +11,14 @@
#include "emvcmd.h"
static emvtags currentcard; //use to hold emv tags for the reader/card during communications
static tUart Uart;
//static tUart Uart;
// The FPGA will report its internal sending delay in
uint16_t FpgaSendQueueDelay;
//variables used for timing purposes:
//these are in ssp_clk cycles:
//static uint32_t NextTransferTime;
static uint32_t LastTimeProxToAirStart;
//static uint32_t LastTimeProxToAirStart;
//static uint32_t LastProxToAirDuration;
//load individual tag into current card
@ -128,7 +128,6 @@ int EMVGetProcessingOptions(uint8_t *PDOL, uint8_t PDOLlen, emvtags* inputcard)
int EMVGetChallenge(emvtags* inputcard)
{
uint8_t receivedAnswer[MAX_FRAME_SIZE];
//uint8_t receivedAnswerPar[MAX_PARITY_SIZE];
//variables
//tlvtag inputtag; //create the tag structure
//perform select
@ -146,7 +145,6 @@ int EMVGenerateAC(uint8_t refcontrol, emvtags* inputcard)
uint8_t cdolcommandlen = 0;
tlvtag temptag;
//uint8_t receivedAnswerPar[MAX_PARITY_SIZE];
if(currentcard.tag_8C_len > 0) {
emv_generateDOL(currentcard.tag_8C, currentcard.tag_8C_len, &currentcard, cdolcommand, &cdolcommandlen); }
else{
@ -184,10 +182,9 @@ int EMV_PaywaveTransaction()
else if((currentcard.tag_9F66[0] & 0x80) == 0x80) {
if((currentcard.tag_9F66[1] & 0x80) == 1) { //CVN17
cardMode = VISA_CVN17;
}
else{
} else {
cardMode = VISA_DCVV;
}
}
}
EMVSelectAID(currentcard.tag_4F,currentcard.tag_4F_len, &currentcard); //perform second AID command
@ -243,7 +240,7 @@ int EMV_PaywaveTransaction()
EMVReadRecord(4,2,&currentcard);
}
//EMVGetChallenge(&currentcard);
//memcpy(currentcard.tag_9F4C,&responsebuffer[1],8); // ICC UN
//memcpy(currentcard.tag_9F4C,&responsebuffer[1],8); // ICC UN
EMVGenerateAC(0x81,&currentcard);
Dbprintf("CARDMODE=%i",cardMode);
@ -383,6 +380,8 @@ void EMVdumpcard(void){
//-----------------------------------------------------------------------------
void SimulateEMVcard()
{
/*
//uint8_t sak; //select ACKnowledge
uint16_t readerPacketLen = 64; //reader packet length - provided by RATS, default to 64 bytes if RATS not supported
@ -548,17 +547,17 @@ void SimulateEMVcard()
currentblock = receivedCmd[0] & 0x01;
if(receivedCmd[0] == 0x26) { // Received a REQUEST
p_response = &responses[ATR]; order = REQA;
p_response = &responses[ATR]; order = ISO14443A_CMD_REQA;
} else if(receivedCmd[0] == 0x52) { // Received a WAKEUP
p_response = &responses[ATR]; order = WUPA;
p_response = &responses[ATR]; order = ISO14443A_CMD_WUPA;
} else if(receivedCmd[1] == 0x20 && receivedCmd[0] == 0x93) { // Received request for UID (cascade 1)
p_response = &responses[UID1]; order = SELUID1;
p_response = &responses[UID1]; order = ISO14443A_CMD_ANTICOLL_OR_SELECT;
} else if(receivedCmd[1] == 0x20 && receivedCmd[0] == 0x95) { // Received request for UID (cascade 2)
p_response = &responses[UID2]; order = SELUID2;
p_response = &responses[UID2]; order = ISO14443A_CMD_ANTICOLL_OR_SELECT_2;
} else if(receivedCmd[1] == 0x70 && receivedCmd[0] == 0x93) { // Received a SELECT (cascade 1)
p_response = &responses[SELACK1]; order = SEL1;
p_response = &responses[SELACK1]; order = ISO14443A_CMD_ANTICOLL_OR_SELECT;
} else if(receivedCmd[1] == 0x70 && receivedCmd[0] == 0x95) { // Received a SELECT (cascade 2)
p_response = &responses[SELACK2]; order = SEL2;
p_response = &responses[SELACK2]; order = ISO14443A_CMD_ANTICOLL_OR_SELECT_2;
} else if((receivedCmd[0] & 0xA2) == 0xA2){ //R-Block received
if(previousblock == currentblock){ //rule 11, retransmit last block
p_response = &dynamic_response_info;
@ -731,4 +730,6 @@ void SimulateEMVcard()
Dbprintf("%x %x %x", happened, happened2, cmdsRecvd);
LED_A_OFF();
BigBuf_free_keep_EM();
*/
}

View file

@ -3,12 +3,6 @@
#include "emvdataels.h"
//Known AIDs
struct tagdescription {
uint8_t tag[2];
char description[255];
};
const uint8_t AID_VISA[] = {0xa0,0x00,0x00,0x00,0x03};
const uint8_t AID_VISA_DB[] = {0xa0,0x00,0x00,0x00,0x03,0x10,0x10};
const uint8_t AID_VISA_C[] = {0xa0,0x00,0x00,0x00,0x03,0x10,0x10,0x01};
@ -44,7 +38,7 @@ const uint8_t PIN_BLOCKED[] = {0x69,0x84};
const uint8_t PIN_BLOCKED2[] = {0x69,0x84};
const uint8_t PIN_WRONG[] = {0x63};
const tagdescription EMV_TAG_LIST[] = {
const tagdescription_t EMV_TAG_LIST[62] = {
{"\x4f\x00","Application Identifier (AID)"},
{"\x50\x00","Application Label"},
{"\x57\x00","Track 2 Equivalent Data"},

View file

@ -4,16 +4,20 @@
#include <stdint.h>
typedef struct tagdescription tagdescription;
//Known AIDs
typedef struct {
uint8_t tag[2];
char description[255];
} __attribute__((__packed__)) tagdescription_t;
//Known AIDs
extern const uint8_t AID_VISA[5];
extern const uint8_t AID_VISA_DB[7] ;
extern const uint8_t AID_VISA_C[8] ;
extern const uint8_t AID_VISA_D[8] ;
extern const uint8_t AID_VISA_E[7] ;
extern const uint8_t AID_VISA_I[7] ;
extern const uint8_t AID_VISA_P[7] ;
extern const uint8_t AID_VISA_DB[7];
extern const uint8_t AID_VISA_C[8];
extern const uint8_t AID_VISA_D[8];
extern const uint8_t AID_VISA_E[7];
extern const uint8_t AID_VISA_I[7];
extern const uint8_t AID_VISA_P[7];
extern const uint8_t AID_VISA_ATM[8];
extern const uint8_t AID_MASTERCARD[7];
extern const uint8_t AID_MAESTRO[7];
@ -21,22 +25,23 @@ extern const uint8_t AID_MAESTRO_UK[7];
extern const uint8_t AID_MAESTRO_TEST[5];
extern const uint8_t AID_SELF_SERVICE[6];
extern const uint8_t AID_AMEX[5];
extern const uint8_t AID_EXPRESSPAY[];
extern const uint8_t AID_EXPRESSPAY[8];
extern const uint8_t AID_LINK[7];
extern const uint8_t AID_ALIAS[7];
//Master data file for PSE
extern const uint8_t DF_PSE[];
extern const tagdescription EMV_TAG_LIST[62]; //SW1 return values
extern const uint8_t SW1_RESPONSE_BYTES[];
extern const uint8_t SW1_WRONG_LENGTH[] ;
extern const uint8_t SW12_OK[];
extern const uint8_t SW12_NOT_SUPPORTED[] ;
extern const uint8_t SW12_NOT_FOUND[];
extern const uint8_t SW12_COND_NOT_SAT[];
extern const uint8_t PIN_BLOCKED[] ;
extern const uint8_t PIN_BLOCKED2[] ;
extern const uint8_t PIN_WRONG[] ;
extern const uint8_t DF_PSE[14];
extern const uint8_t SW1_RESPONSE_BYTES[1];
extern const uint8_t SW1_WRONG_LENGTH[1];
extern const uint8_t SW12_OK[2];
extern const uint8_t SW12_NOT_SUPPORTED[2];
extern const uint8_t SW12_NOT_FOUND[2];
extern const uint8_t SW12_COND_NOT_SAT[2];
extern const uint8_t PIN_BLOCKED[2];
extern const uint8_t PIN_BLOCKED2[2];
extern const uint8_t PIN_WRONG[1];
extern const tagdescription_t EMV_TAG_LIST[62]; //SW1 return values
//AIP bitmasks details
#define AIP_CHIP_SUPPORTED 0x80

View file

@ -370,14 +370,18 @@ exitfunction: //goto label to exit search quickly once found
//function to
int emv_settag(uint32_t tag, uint8_t *datain, emvtags *currentcard){
char binarydata[255] = {0};
//if((strlen((const char *)datain)%2) != 0){ //must be an even string
/*
// if((strlen((const char *)datain)%2) != 0){ //must be an even string
// return -1;
//}
//if(strlen((const char *)datain) > 255) {
// }
// if(strlen((const char *)datain) > 255) {
// return -1;
//}
uint8_t datalen = strlen((const char *)datain) / 2; //length of datain
for(int i=0;i<strlen((const char *)datain);i+=2){
// }
*/
uint8_t datalen = strlen((const char *)datain) / 2; //length of datain
for(int i = 0; i < strlen((const char *)datain); i += 2){
binarydata[i/2] |= (char)hex2int(datain[i]) << 4;
binarydata[i/2] |= (char)hex2int(datain[i+1]);
}
@ -1353,7 +1357,7 @@ int emv_select(uint8_t* AID, uint8_t AID_len, void* data)
selectCmd[4] = AID_len;
memcpy(&(selectCmd[5]), AID, AID_len);
selectCmd[selectCmd_len-1] = 0x00;
return iso14_apdu(selectCmd,selectCmd_len,false, 0,data);
return iso14_apdu(selectCmd, selectCmd_len, data);
}
//perform READ RECORD
@ -1367,7 +1371,7 @@ int emv_readrecord(uint8_t recordnumber, uint8_t sfi, void* data)
readRecordCmd[2] = recordnumber;
readRecordCmd[3] = ((sfi << 3) | 0x04);
readRecordCmd[4] = 0x00;
return iso14_apdu(readRecordCmd,readRecordCmd_len,false,0,data);
return iso14_apdu(readRecordCmd, readRecordCmd_len, data);
}
int emv_getprocessingoptions(uint8_t* pdol, uint8_t pdol_len, void* data)
@ -1386,7 +1390,7 @@ int emv_getprocessingoptions(uint8_t* pdol, uint8_t pdol_len, void* data)
memcpy(&(processingCmd[7]), pdol, pdol_len);}
processingCmd[processingCmd_len] = 0x00;
//Dbhexdump(processingCmd_len, processingCmd, false);
return iso14_apdu(processingCmd,processingCmd_len,false, 0, data);
return iso14_apdu(processingCmd, processingCmd_len, data);
}
int emv_computecryptogram(uint8_t* UDOL, uint8_t UDOL_len, void *data)
@ -1402,7 +1406,7 @@ int emv_computecryptogram(uint8_t* UDOL, uint8_t UDOL_len, void *data)
memcpy(&(cryptogramCmd[5]), UDOL, UDOL_len);
cryptogramCmd[cryptogramCmd_len-1] = 0x00;
return iso14_apdu(cryptogramCmd,cryptogramCmd_len,false, 0,data);
return iso14_apdu(cryptogramCmd, cryptogramCmd_len, data);
}
int emv_getchallenge(void *data)
@ -1416,7 +1420,7 @@ int emv_getchallenge(void *data)
challengeCmd[3] = 0x00;
challengeCmd[4] = 0x00;
return iso14_apdu(challengeCmd,challengeCmd_len,false, 0,data);
return iso14_apdu(challengeCmd, challengeCmd_len, data);
}
int emv_loopback(uint8_t* transData , uint8_t transData_len, void *data)
@ -1430,7 +1434,7 @@ int emv_loopback(uint8_t* transData , uint8_t transData_len, void *data)
loopbackCmd[3] = 0x00;
loopbackCmd[4] = loopbackCmd_len;
memcpy(&(loopbackCmd[5]), transData, transData_len);
return iso14_apdu(loopbackCmd,loopbackCmd_len,false, 0,data);
return iso14_apdu(loopbackCmd, loopbackCmd_len, data);
}
//generateAC
@ -1447,12 +1451,10 @@ int emv_generateAC(uint8_t refcontrolparam, uint8_t* cdolinput, uint8_t cdolinpu
memcpy(&(acCmd[5]), cdolinput, cdolinputlen);
acCmd[acCmd_len-1] = 0x00;
Dbhexdump(acCmd_len, acCmd,false);
return iso14_apdu(acCmd,acCmd_len,false,0,data);
return iso14_apdu(acCmd, acCmd_len, data);
}
int emv_decodeAFL(uint8_t* AFL, uint8_t AFLlen )
{
int emv_decodeAFL(uint8_t* AFL, uint8_t AFLlen ){
return 0;
}

View file

@ -74,6 +74,36 @@ int32_t le24toh (uint8_t data[3]) {
return (data[2] << 16) | (data[1] << 8) | data[0];
}
//convert hex digit to integer
uint8_t hex2int(char hexchar){
switch(hexchar){
case '0': return 0; break;
case '1': return 1; break;
case '2': return 2; break;
case '3': return 3; break;
case '4': return 4; break;
case '5': return 5; break;
case '6': return 6; break;
case '7': return 7; break;
case '8': return 8; break;
case '9': return 9; break;
case 'a':
case 'A': return 10; break;
case 'b':
case 'B': return 11; break;
case 'c':
case 'C': return 12; break;
case 'd':
case 'D': return 13; break;
case 'e':
case 'E': return 14; break;
case 'f':
case 'F': return 15; break;
default:
return 0;
}
}
void LEDsoff() {
LED_A_OFF();
LED_B_OFF();

View file

@ -47,6 +47,7 @@ uint64_t bytes_to_num(uint8_t* src, size_t len);
void rol(uint8_t *data, const size_t len);
void lsl (uint8_t *data, size_t len);
int32_t le24toh (uint8_t data[3]);
uint8_t hex2int(char hexchar);
void LED(int led, int ms);
void LEDsoff();

View file

@ -98,7 +98,8 @@ static void *uart_receiver(void *targ) {
prx = rx;
if (txcmd_pending) {
if ( !uart_send(sp, (byte_t*) &txcmd, sizeof(UsbCommand))) {
bool res = uart_send(sp, (byte_t*) &txcmd, sizeof(UsbCommand));
if (!res) {
PrintAndLog("Sending bytes to proxmark failed");
}
txcmd_pending = false;