X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/d627a2fd8cf0d6c9dc670ed15fdfe1d87949d306..76a608af8e342b50718cfd0e53c0fa932304dbd9:/armsrc/emvutil.c?ds=sidebyside diff --git a/armsrc/emvutil.c b/armsrc/emvutil.c index be19d32a..e55d1e4b 100644 --- a/armsrc/emvutil.c +++ b/armsrc/emvutil.c @@ -12,12 +12,11 @@ #define DUMP(varname) Dbprintf("%s=", #varname); -int EMV_DBGLEVEL = EMV_DBG_ALL; //uint8_t PCB = 0x00; //track Protocol Control Byte externally //util functions //print detected tag name over the serial link -int emv_printtag(uint8_t* selected_tag, emvtags* inputcard, uint8_t* outputstring, uint8_t* outputlen) +int emv_printtag(uint8_t* selected_tag, emvcard* inputcard, uint8_t* outputstring, uint8_t* outputlen) { //search tag list and print the match //get the value of the tag @@ -37,12 +36,12 @@ int emv_printtag(uint8_t* selected_tag, emvtags* inputcard, uint8_t* outputstrin return 0; } -//returns the value of the emv tag in the supplied emvtags structure -int emv_lookuptag(uint8_t* tag, emvtags *currentcard, uint8_t* outputval, uint8_t* outputvallen) +//returns the value of the emv tag in the supplied emvcard structure +int emv_lookuptag(uint8_t* tag, emvcard *currentcard, uint8_t* outputval, uint8_t* outputvallen) { //loop through tag and return the appropriate value uint8_t returnedtag[255]; - uint8_t returnedlength; + uint8_t returnedlength = 0; memset(returnedtag, 0x00, sizeof(returnedtag)); if(!memcmp(tag, "\x4F\x00",2)){ memcpy(&returnedtag, currentcard->tag_4F, currentcard->tag_4F_len); @@ -201,165 +200,165 @@ int emv_lookuptag(uint8_t* tag, emvtags *currentcard, uint8_t* outputval, uint8_ } if(*tag == 0x9F) { if(*(tag+1) == 0x01){ - memcpy(&returnedtag, currentcard->tag_9F01, sizeof(currentcard->tag_9F01)); - returnedlength = sizeof(currentcard->tag_9F01);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F01, sizeof(currentcard->tag_9F01)); + returnedlength = sizeof(currentcard->tag_9F01);goto exitfunction;} else if(*(tag+1) == 0x02){ - memcpy(&returnedtag, currentcard->tag_9F02, sizeof(currentcard->tag_9F02)); - returnedlength = sizeof(currentcard->tag_9F02);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F02, sizeof(currentcard->tag_9F02)); + returnedlength = sizeof(currentcard->tag_9F02);goto exitfunction;} else if(*(tag+1) == 0x03){ - returnedlength = sizeof(currentcard->tag_9F03);goto exitfunction;} + returnedlength = sizeof(currentcard->tag_9F03);goto exitfunction;} else if(*(tag+1) == 0x04){ - memcpy(&returnedtag, currentcard->tag_9F04, sizeof(currentcard->tag_9F04)); - returnedlength = sizeof(currentcard->tag_9F04);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F04, sizeof(currentcard->tag_9F04)); + returnedlength = sizeof(currentcard->tag_9F04);goto exitfunction;} else if(*(tag+1) == 0x05){ - memcpy(&returnedtag, currentcard->tag_9F05, currentcard->tag_9F05_len); - returnedlength = currentcard->tag_9F05_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F05, currentcard->tag_9F05_len); + returnedlength = currentcard->tag_9F05_len; goto exitfunction;} else if(*(tag+1) == 0x06){ - memcpy(&returnedtag, currentcard->tag_9F06, currentcard->tag_9F06_len); - returnedlength = currentcard->tag_9F06_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F06, currentcard->tag_9F06_len); + returnedlength = currentcard->tag_9F06_len; goto exitfunction;} else if(*(tag+1) == 0x07){ - memcpy(&returnedtag, currentcard->tag_9F07, sizeof(currentcard->tag_9F07)); - returnedlength = sizeof(currentcard->tag_9F07);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F07, sizeof(currentcard->tag_9F07)); + returnedlength = sizeof(currentcard->tag_9F07);goto exitfunction;} else if(*(tag+1) == 0x08){ - memcpy(&returnedtag, currentcard->tag_9F08, sizeof(currentcard->tag_9F08)); - returnedlength = sizeof(currentcard->tag_9F08);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F08, sizeof(currentcard->tag_9F08)); + returnedlength = sizeof(currentcard->tag_9F08);goto exitfunction;} else if(*(tag+1) == 0x09){ - memcpy(&returnedtag, currentcard->tag_9F09, sizeof(currentcard->tag_9F09)); - returnedlength = sizeof(currentcard->tag_9F09);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F09, sizeof(currentcard->tag_9F09)); + returnedlength = sizeof(currentcard->tag_9F09);goto exitfunction;} else if(*(tag+1) == 0x0B){ - memcpy(&returnedtag, currentcard->tag_9F0B, currentcard->tag_9F0B_len); - returnedlength = currentcard->tag_9F0B_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F0B, currentcard->tag_9F0B_len); + returnedlength = currentcard->tag_9F0B_len; goto exitfunction;} else if(*(tag+1) == 0x0D){ - memcpy(&returnedtag, currentcard->tag_9F0D, sizeof(currentcard->tag_9F0D)); - returnedlength = sizeof(currentcard->tag_9F0D);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F0D, sizeof(currentcard->tag_9F0D)); + returnedlength = sizeof(currentcard->tag_9F0D); goto exitfunction;} else if(*(tag+1) == 0x0E){ - memcpy(&returnedtag, currentcard->tag_9F0E, sizeof(currentcard->tag_9F0E)); - returnedlength = sizeof(currentcard->tag_9F0E);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F0E, sizeof(currentcard->tag_9F0E)); + returnedlength = sizeof(currentcard->tag_9F0E); goto exitfunction;} else if(*(tag+1) == 0x0F){ - memcpy(&returnedtag, currentcard->tag_9F0F, sizeof(currentcard->tag_9F0F)); - returnedlength = sizeof(currentcard->tag_9F0F);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F0F, sizeof(currentcard->tag_9F0F)); + returnedlength = sizeof(currentcard->tag_9F0F); goto exitfunction;} else if(*(tag+1) == 0x10){ - memcpy(&returnedtag, currentcard->tag_9F10, currentcard->tag_9F10_len); - returnedlength = currentcard->tag_9F10_len;goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F10, currentcard->tag_9F10_len); + returnedlength = currentcard->tag_9F10_len; goto exitfunction;} else if(*(tag+1) == 0x11){ - memcpy(&returnedtag, currentcard->tag_9F11, sizeof(currentcard->tag_9F11)); - returnedlength = sizeof(currentcard->tag_9F11);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F11, sizeof(currentcard->tag_9F11)); + returnedlength = sizeof(currentcard->tag_9F11); goto exitfunction;} else if(*(tag+1) == 0x12){ - memcpy(&returnedtag, currentcard->tag_9F12, currentcard->tag_9F12_len); - returnedlength = currentcard->tag_9F12_len;goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F12, currentcard->tag_9F12_len); + returnedlength = currentcard->tag_9F12_len; goto exitfunction;} else if(*(tag+1) == 0x1A){ - memcpy(&returnedtag, currentcard->tag_9F1A, sizeof(currentcard->tag_9F1A)); - goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F1A, sizeof(currentcard->tag_9F1A)); + returnedlength = sizeof(currentcard->tag_9F1A); goto exitfunction;} else if(*(tag+1) == 0x1F){ - memcpy(&returnedtag, currentcard->tag_9F1F, currentcard->tag_9F1F_len); - returnedlength = currentcard->tag_9F1F_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F1F, currentcard->tag_9F1F_len); + returnedlength = currentcard->tag_9F1F_len; goto exitfunction;} else if(*(tag+1) == 0x32){ - memcpy(&returnedtag, currentcard->tag_9F32, currentcard->tag_9F32_len); - returnedlength = currentcard->tag_9F32_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F32, currentcard->tag_9F32_len); + returnedlength = currentcard->tag_9F32_len; goto exitfunction;} else if(*(tag+1) == 0x34){ - memcpy(&returnedtag, currentcard->tag_9F34, sizeof(currentcard->tag_9F34)); - returnedlength = sizeof(currentcard->tag_9F34); goto exitfunction;} -else if(*(tag+1) == 0x35){ - memcpy(&returnedtag, currentcard->tag_9F35, sizeof(currentcard->tag_9F35)); - returnedlength = sizeof(currentcard->tag_9F35); goto exitfunction;} -else if(*(tag+1) == 0x37){ - memcpy(&returnedtag, currentcard->tag_9F37, sizeof(currentcard->tag_9F37)); - returnedlength = sizeof(currentcard->tag_9F37);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F34, sizeof(currentcard->tag_9F34)); + returnedlength = sizeof(currentcard->tag_9F34); goto exitfunction;} + else if(*(tag+1) == 0x35){ + memcpy(&returnedtag, currentcard->tag_9F35, sizeof(currentcard->tag_9F35)); + returnedlength = sizeof(currentcard->tag_9F35); goto exitfunction;} + else if(*(tag+1) == 0x37){ + memcpy(&returnedtag, currentcard->tag_9F37, sizeof(currentcard->tag_9F37)); + returnedlength = sizeof(currentcard->tag_9F37);goto exitfunction;} else if(*(tag+1) == 0x38){ - memcpy(&returnedtag, currentcard->tag_9F38, currentcard->tag_9F38_len); - returnedlength = currentcard->tag_9F38_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F38, currentcard->tag_9F38_len); + returnedlength = currentcard->tag_9F38_len; goto exitfunction;} else if(*(tag+1) == 0x44){ - memcpy(&returnedtag, currentcard->tag_9F44, sizeof(currentcard->tag_9F44)); - returnedlength = sizeof(currentcard->tag_9F44);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F44, sizeof(currentcard->tag_9F44)); + returnedlength = sizeof(currentcard->tag_9F44);goto exitfunction;} else if(*(tag+1) == 0x45){ - memcpy(&returnedtag, currentcard->tag_9F45, sizeof(currentcard->tag_9F45)); - returnedlength = sizeof(currentcard->tag_9F45);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F45, sizeof(currentcard->tag_9F45)); + returnedlength = sizeof(currentcard->tag_9F45);goto exitfunction;} else if(*(tag+1) == 0x46){ - memcpy(&returnedtag, currentcard->tag_9F46, currentcard->tag_9F46_len); - returnedlength = currentcard->tag_9F46_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F46, currentcard->tag_9F46_len); + returnedlength = currentcard->tag_9F46_len; goto exitfunction;} else if(*(tag+1) == 0x47){ - memcpy(&returnedtag, currentcard->tag_9F47, currentcard->tag_9F47_len); - returnedlength = currentcard->tag_9F47_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F47, currentcard->tag_9F47_len); + returnedlength = currentcard->tag_9F47_len; goto exitfunction;} else if(*(tag+1) == 0x48){ - memcpy(&returnedtag, currentcard->tag_9F48, currentcard->tag_9F48_len); - returnedlength = currentcard->tag_9F48_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F48, currentcard->tag_9F48_len); + returnedlength = currentcard->tag_9F48_len; goto exitfunction;} else if(*(tag+1) == 0x49){ - memcpy(&returnedtag, currentcard->tag_9F49, currentcard->tag_9F49_len); - returnedlength = currentcard->tag_9F49_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F49, currentcard->tag_9F49_len); + returnedlength = currentcard->tag_9F49_len; goto exitfunction;} else if(*(tag+1) == 0x4A){ - memcpy(&returnedtag, currentcard->tag_9F4A, sizeof(currentcard->tag_9F4A)); - returnedlength = sizeof(currentcard->tag_9F4A);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F4A, sizeof(currentcard->tag_9F4A)); + returnedlength = sizeof(currentcard->tag_9F4A);goto exitfunction;} else if(*(tag+1) == 0x4B){ - memcpy(&returnedtag, currentcard->tag_9F4B, currentcard->tag_9F4B_len); - returnedlength = currentcard->tag_9F4B_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F4B, currentcard->tag_9F4B_len); + returnedlength = currentcard->tag_9F4B_len; goto exitfunction;} else if(*(tag+1) == 0x4C){ - memcpy(&returnedtag, currentcard->tag_9F4C, sizeof(currentcard->tag_9F4C)); - returnedlength = sizeof(currentcard->tag_9F4C); goto exitfunction;} -else if(*(tag+1) == 0x60){ - memcpy(&returnedtag, currentcard->tag_9F60, sizeof(currentcard->tag_9F60)); - returnedlength = sizeof(currentcard->tag_9F60);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F4C, sizeof(currentcard->tag_9F4C)); + returnedlength = sizeof(currentcard->tag_9F4C); goto exitfunction;} + else if(*(tag+1) == 0x60){ + memcpy(&returnedtag, currentcard->tag_9F60, sizeof(currentcard->tag_9F60)); + returnedlength = sizeof(currentcard->tag_9F60);goto exitfunction;} else if(*(tag+1) == 0x61){ - memcpy(&returnedtag, currentcard->tag_9F61, sizeof(currentcard->tag_9F61)); - returnedlength = sizeof(currentcard->tag_9F61);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F61, sizeof(currentcard->tag_9F61)); + returnedlength = sizeof(currentcard->tag_9F61);goto exitfunction;} else if(*(tag+1) == 0x62){ - memcpy(&returnedtag, currentcard->tag_9F62, sizeof(currentcard->tag_9F62)); - returnedlength = sizeof(currentcard->tag_9F62);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F62, sizeof(currentcard->tag_9F62)); + returnedlength = sizeof(currentcard->tag_9F62);goto exitfunction;} else if(*(tag+1) == 0x63){ - memcpy(&returnedtag, currentcard->tag_9F63, sizeof(currentcard->tag_9F63)); - returnedlength = sizeof(currentcard->tag_9F63);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F63, sizeof(currentcard->tag_9F63)); + returnedlength = sizeof(currentcard->tag_9F63);goto exitfunction;} else if(*(tag+1) == 0x64){ - memcpy(&returnedtag, currentcard->tag_9F64, sizeof(currentcard->tag_9F64)); - returnedlength = sizeof(currentcard->tag_9F64);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F64, sizeof(currentcard->tag_9F64)); + returnedlength = sizeof(currentcard->tag_9F64);goto exitfunction;} else if(*(tag+1) == 0x65){ - memcpy(&returnedtag, currentcard->tag_9F65, sizeof(currentcard->tag_9F65)); - returnedlength = sizeof(currentcard->tag_9F65);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F65, sizeof(currentcard->tag_9F65)); + returnedlength = sizeof(currentcard->tag_9F65);goto exitfunction;} else if(*(tag+1) == 0x66){ - memcpy(&returnedtag, currentcard->tag_9F66, sizeof(currentcard->tag_9F66)); - returnedlength = sizeof(currentcard->tag_9F66);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F66, sizeof(currentcard->tag_9F66)); + returnedlength = sizeof(currentcard->tag_9F66);goto exitfunction;} else if(*(tag+1) == 0x67){ - memcpy(&returnedtag, currentcard->tag_9F67, sizeof(currentcard->tag_9F67)); - returnedlength = sizeof(currentcard->tag_9F67);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F67, sizeof(currentcard->tag_9F67)); + returnedlength = sizeof(currentcard->tag_9F67);goto exitfunction;} else if(*(tag+1) == 0x68){ - memcpy(&returnedtag, currentcard->tag_9F68, currentcard->tag_9F68_len); - returnedlength = currentcard->tag_9F68_len;goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F68, currentcard->tag_9F68_len); + returnedlength = currentcard->tag_9F68_len;goto exitfunction;} else if(*(tag+1) == 0x69){ - memcpy(&returnedtag, currentcard->tag_9F69, currentcard->tag_9F69_len); - returnedlength = currentcard->tag_9F69_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F69, currentcard->tag_9F69_len); + returnedlength = currentcard->tag_9F69_len; goto exitfunction;} else if(*(tag+1) == 0x6A){ - memcpy(&returnedtag, currentcard->tag_9F6A, sizeof(currentcard->tag_9F6A)); - returnedlength = sizeof(currentcard->tag_9F6A);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F6A, sizeof(currentcard->tag_9F6A)); + returnedlength = sizeof(currentcard->tag_9F6A);goto exitfunction;} else if(*(tag+1) == 0x6B){ - memcpy(&returnedtag, currentcard->tag_9F6B, currentcard->tag_9F6B_len); - returnedlength = currentcard->tag_9F6B_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F6B, currentcard->tag_9F6B_len); + returnedlength = currentcard->tag_9F6B_len; goto exitfunction;} else if(*(tag+1) == 0x6C){ - memcpy(&returnedtag, currentcard->tag_9F6C, sizeof(currentcard->tag_9F6C)); - returnedlength = sizeof(currentcard->tag_9F6C);goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_9F6C, sizeof(currentcard->tag_9F6C)); + returnedlength = sizeof(currentcard->tag_9F6C);goto exitfunction;} } else { if(!memcmp(tag, "\x61\x00",2)){ - memcpy(&returnedtag, currentcard->tag_61, currentcard->tag_61_len); - returnedlength = currentcard->tag_61_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_61, currentcard->tag_61_len); + returnedlength = currentcard->tag_61_len; goto exitfunction;} else if(!memcmp(tag, "\x6F\x00",2)){ - memcpy(&returnedtag, currentcard->tag_6F, currentcard->tag_6F_len); - returnedlength = currentcard->tag_6F_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_6F, currentcard->tag_6F_len); + returnedlength = currentcard->tag_6F_len; goto exitfunction;} else if(!memcmp(tag, "\xAF\x00",2)){ - memcpy(&returnedtag, currentcard->tag_AF, currentcard->tag_AF_len); - returnedlength = currentcard->tag_AF_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_AF, currentcard->tag_AF_len); + returnedlength = currentcard->tag_AF_len; goto exitfunction;} else if(!memcmp(tag, "\x70\x00",2)){ - memcpy(&returnedtag, currentcard->tag_70, currentcard->tag_70_len); - returnedlength = currentcard->tag_70_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_70, currentcard->tag_70_len); + returnedlength = currentcard->tag_70_len; goto exitfunction;} else if(!memcmp(tag, "\x77\x00",2)){ - memcpy(&returnedtag, currentcard->tag_77, currentcard->tag_77_len); - returnedlength = currentcard->tag_77_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_77, currentcard->tag_77_len); + returnedlength = currentcard->tag_77_len; goto exitfunction;} else if(!memcmp(tag, "\x80\x00",2)){ - memcpy(&returnedtag, currentcard->tag_80, currentcard->tag_80_len); - returnedlength = currentcard->tag_80_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_80, currentcard->tag_80_len); + returnedlength = currentcard->tag_80_len; goto exitfunction;} else if(!memcmp(tag, "\xBF\x0C",2)){ - memcpy(&returnedtag, currentcard->tag_BF0C, currentcard->tag_BF0C_len); - returnedlength = currentcard->tag_BF0C_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_BF0C, currentcard->tag_BF0C_len); + returnedlength = currentcard->tag_BF0C_len; goto exitfunction;} else if(!memcmp(tag, "\xFF\x01",2)){ //special DF tag - memcpy(&returnedtag, currentcard->tag_DFName, currentcard->tag_DFName_len); - returnedlength = currentcard->tag_DFName_len; goto exitfunction;} + memcpy(&returnedtag, currentcard->tag_DFName, currentcard->tag_DFName_len); + returnedlength = currentcard->tag_DFName_len; goto exitfunction;} } exitfunction: //goto label to exit search quickly once found memcpy(outputval, &returnedtag, returnedlength); @@ -368,7 +367,7 @@ exitfunction: //goto label to exit search quickly once found } //function to -int emv_settag(uint32_t tag, uint8_t *datain, emvtags *currentcard){ +int emv_settag(uint32_t tag, uint8_t *datain, emvcard *currentcard){ char binarydata[255] = {0}; /* @@ -808,13 +807,13 @@ int emv_settag(uint32_t tag, uint8_t *datain, emvtags *currentcard){ } /* generates an emv template based off tag values supplied */ -int emv_generatetemplate(uint8_t* templateval,emvtags* currentcard, uint8_t* returnedval, uint8_t* returnedlen,uint8_t numtags, ...) +int emv_generatetemplate(uint8_t* templateval,emvcard* currentcard, uint8_t* returnedval, uint8_t* returnedlen,uint8_t numtags, ...) { va_list arguments; uint8_t* currenttag; //value of the current tag - uint8_t tagval[255]; //buffer to hold the extracted tag value + uint8_t tagval[256]; //buffer to hold the extracted tag value uint8_t taglen = 0; //extracted tag length - uint8_t bufferval[255]; + uint8_t bufferval[256]; uint8_t counter = 0; uint32_t encodedlen = 0; va_start(arguments, numtags); @@ -826,11 +825,12 @@ int emv_generatetemplate(uint8_t* templateval,emvtags* currentcard, uint8_t* ret } encode_ber_tlv_item(templateval, strlen((const char*) templateval), bufferval, counter, returnedval, &encodedlen); *returnedlen = encodedlen; + va_end(arguments); return 0; } //generate a valid pdol list -int emv_generateDOL(uint8_t* DOL, uint8_t DOLlen,emvtags* currentcard,uint8_t* DOLoutput, uint8_t* DOLoutputlen) +int emv_generateDOL(uint8_t* DOL, uint8_t DOLlen,emvcard* currentcard,uint8_t* DOLoutput, uint8_t* DOLoutputlen) { if(!DOL || !currentcard || !DOLoutput) // null pointer checks return 1; @@ -866,7 +866,7 @@ int emv_generateDOL(uint8_t* DOL, uint8_t DOLlen,emvtags* currentcard,uint8_t* D //decode the tag inputted and fill in the supplied structure. clean up the cleanup_passpass function -int emv_emvtags_decode_tag(tlvtag* inputtag, emvtags* currentcard) +int emv_emvtags_decode_tag(tlvtag* inputtag, emvcard* currentcard) { if(!inputtag || !currentcard) { return 1; @@ -1324,7 +1324,7 @@ else return 0; } -int emv_decode_field(uint8_t* inputfield,uint16_t inputlength, emvtags *result) +int emv_decode_field(uint8_t* inputfield,uint16_t inputlength, emvcard *result) { uint16_t lengthcounter=0; tlvtag newtag; @@ -1337,7 +1337,7 @@ int emv_decode_field(uint8_t* inputfield,uint16_t inputlength, emvtags *result) { //decode the tlv tag decode_ber_tlv_item((inputfield+lengthcounter),&newtag); - //write the emvtags strucutre + //write the emvcard strucutre emv_emvtags_decode_tag(&newtag,result); //move to next value and decode lengthcounter += newtag.fieldlength-1; @@ -1364,8 +1364,7 @@ int emv_select(uint8_t* AID, uint8_t AID_len, void* data) int emv_readrecord(uint8_t recordnumber, uint8_t sfi, void* data) { uint16_t readRecordCmd_len = 5; - uint8_t readRecordCmd[readRecordCmd_len]; - + uint8_t readRecordCmd[readRecordCmd_len]; readRecordCmd[0] = 0x00; readRecordCmd[1] = 0xB2; readRecordCmd[2] = recordnumber; @@ -1377,8 +1376,7 @@ int emv_readrecord(uint8_t recordnumber, uint8_t sfi, void* data) int emv_getprocessingoptions(uint8_t* pdol, uint8_t pdol_len, void* data) { uint16_t processingCmd_len = 4 + 1 + 2 + pdol_len + 1; - uint8_t processingCmd[processingCmd_len]; - + uint8_t processingCmd[processingCmd_len]; processingCmd[0] = 0x80; processingCmd[1] = 0xA8; processingCmd[2] = 0x00; @@ -1388,15 +1386,14 @@ int emv_getprocessingoptions(uint8_t* pdol, uint8_t pdol_len, void* data) processingCmd[6] = pdol_len; if(pdol_len > 0){ memcpy(&(processingCmd[7]), pdol, pdol_len);} - processingCmd[processingCmd_len] = 0x00; + processingCmd[processingCmd_len-1] = 0x00; return iso14_apdu(processingCmd, processingCmd_len, data); } int emv_computecryptogram(uint8_t* UDOL, uint8_t UDOL_len, void *data) { uint16_t cryptogramCmd_len = 4 + 1 + UDOL_len + 1; - uint8_t cryptogramCmd[cryptogramCmd_len]; - + uint8_t cryptogramCmd[cryptogramCmd_len]; cryptogramCmd[0] = 0x80; cryptogramCmd[1] = 0x2A; cryptogramCmd[2] = 0x8E; @@ -1404,7 +1401,6 @@ int emv_computecryptogram(uint8_t* UDOL, uint8_t UDOL_len, void *data) cryptogramCmd[4] = UDOL_len; memcpy(&(cryptogramCmd[5]), UDOL, UDOL_len); cryptogramCmd[cryptogramCmd_len-1] = 0x00; - return iso14_apdu(cryptogramCmd, cryptogramCmd_len, data); } @@ -1412,13 +1408,11 @@ int emv_getchallenge(void *data) { uint16_t challengeCmd_len = 5; uint8_t challengeCmd[challengeCmd_len]; - challengeCmd[0] = 0x00; challengeCmd[1] = 0x84; challengeCmd[2] = 0x00; challengeCmd[3] = 0x00; - challengeCmd[4] = 0x00; - + challengeCmd[4] = 0x00; return iso14_apdu(challengeCmd, challengeCmd_len, data); } @@ -1426,7 +1420,6 @@ int emv_loopback(uint8_t* transData , uint8_t transData_len, void *data) { uint16_t loopbackCmd_len = 4 + 1 + transData_len + 1; uint8_t loopbackCmd[loopbackCmd_len]; - loopbackCmd[0] = 0x00; loopbackCmd[1] = 0xEE; loopbackCmd[2] = 0x00; @@ -1440,8 +1433,7 @@ int emv_loopback(uint8_t* transData , uint8_t transData_len, void *data) int emv_generateAC(uint8_t refcontrolparam, uint8_t* cdolinput, uint8_t cdolinputlen, void* data) { uint16_t acCmd_len = 4 + 1 + cdolinputlen + 1; - uint8_t acCmd[acCmd_len]; - + uint8_t acCmd[acCmd_len]; acCmd[0] = 0x80; acCmd[1] = 0xAE; acCmd[2] = refcontrolparam; @@ -1461,22 +1453,14 @@ int emv_decodeAFL(uint8_t* AFL, uint8_t AFLlen ){ //Print out AIP Bit meanings int emv_decodeAIP(uint8_t* AIP) { - if((AIP[0] & AIP_SDA_SUPPORTED) == AIP_SDA_SUPPORTED) - Dbprintf("SDA supported"); - if((AIP[0] & AIP_DDA_SUPPORTED) == AIP_DDA_SUPPORTED) - Dbprintf("DDA supported"); - if((AIP[0] & AIP_CARDHOLDER_VERIFICATION)==AIP_CARDHOLDER_VERIFICATION) - Dbprintf("Cardholder verification is supported"); - if((AIP[0] & AIP_TERMINAL_RISK) == AIP_TERMINAL_RISK) - Dbprintf("Terminal risk management is to be performed"); - if((AIP[0] & AIP_ISSUER_AUTH) == AIP_ISSUER_AUTH) - Dbprintf("Issuer authentication is supported "); - if((AIP[0] & AIP_CDA_SUPPORTED) == AIP_CDA_SUPPORTED) - Dbprintf("CDA supported"); - if((AIP[1] & AIP_CHIP_SUPPORTED) == AIP_CHIP_SUPPORTED) - Dbprintf("Chip supported"); - if((AIP[1] & AIP_MSR_SUPPORTED) == AIP_MSR_SUPPORTED) - Dbprintf("MSR supported"); + if ((AIP[0] & AIP_SDA_SUPPORTED) == AIP_SDA_SUPPORTED) Dbprintf("SDA supported"); + if ((AIP[0] & AIP_DDA_SUPPORTED) == AIP_DDA_SUPPORTED) Dbprintf("DDA supported"); + if ((AIP[0] & AIP_CARDHOLDER_VERIFICATION) == AIP_CARDHOLDER_VERIFICATION) Dbprintf("Cardholder verification is supported"); + if ((AIP[0] & AIP_TERMINAL_RISK) == AIP_TERMINAL_RISK) Dbprintf("Terminal risk management is to be performed"); + if ((AIP[0] & AIP_ISSUER_AUTH) == AIP_ISSUER_AUTH) Dbprintf("Issuer authentication is supported "); + if ((AIP[0] & AIP_CDA_SUPPORTED) == AIP_CDA_SUPPORTED) Dbprintf("CDA supported"); + if ((AIP[1] & AIP_CHIP_SUPPORTED) == AIP_CHIP_SUPPORTED) Dbprintf("Chip supported"); + if ((AIP[1] & AIP_MSR_SUPPORTED) == AIP_MSR_SUPPORTED) Dbprintf("MSR supported"); return 0; } @@ -1489,77 +1473,117 @@ int emv_decodeCVM(uint8_t* CVM, uint8_t CVMlen) amountX = bytes_to_num(CVM, 4); amountY = bytes_to_num(CVM+4, 4); counter +=8; - while(counter < CVMlen) + while (counter < CVMlen) { - if((CVM[counter] & 0x40) == 0x40){ - if((CVM[counter] & 0x3F)== 0x00){ - Dbprintf("Fail CVM processing"); - } - if((CVM[counter] & 0x3F) == 0x01){ - Dbprintf("Plaintext PIN verification performed by ICC"); - } - if((CVM[counter] & 0x3F) == 0x02){ - Dbprintf("Enciphered PIN verified online"); - } - if((CVM[counter] & 0x3F) == 0x03){ - Dbprintf("Plaintext PIN verification performed by ICC and signature (paper)"); - } - if((CVM[counter] & 0x3F) == 0x04){ - Dbprintf("Enciphered PIN verification performed by ICC"); - } - if((CVM[counter] & 0x3F) == 0x05){ - Dbprintf("Enciphered PIN verification performed by ICC and signature (paper)"); - } - if((CVM[counter] & 0x3F) == 0x30){ - Dbprintf("Signature (paper)"); - } - if((CVM[counter] & 0x3F) == 0x40){ - Dbprintf("No CVM required"); - } + if ((CVM[counter] & 0x40) == 0x40){ + if ((CVM[counter] & 0x3F)== 0x00){ Dbprintf("Fail CVM processing");} + if ((CVM[counter] & 0x3F) == 0x01){ Dbprintf("Plaintext PIN verification performed by ICC");} + if ((CVM[counter] & 0x3F) == 0x02){ Dbprintf("Enciphered PIN verified online");} + if ((CVM[counter] & 0x3F) == 0x03){ Dbprintf("Plaintext PIN verification performed by ICC and signature (paper)");} + if ((CVM[counter] & 0x3F) == 0x04){ Dbprintf("Enciphered PIN verification performed by ICC");} + if ((CVM[counter] & 0x3F) == 0x05){ Dbprintf("Enciphered PIN verification performed by ICC and signature (paper)");} + if ((CVM[counter] & 0x3F) == 0x30){ Dbprintf("Signature (paper)");} + // iceman, wrong masked used? changed from 0x3f -> 0x7f + if ((CVM[counter] & 0x7F) == 0x40){ Dbprintf("No CVM required");} counter +=2; - } - else{ + } else { Dbprintf("Fail cardholder verification if this CVM is unsuccessful"); counter +=2; } - if(CVM[counter+1] == 0x00){ - Dbprintf("Always");} - if(CVM[counter+1] == 0x01){ - Dbprintf("If unattended cash");} - if(CVM[counter+1] == 0x02){ - Dbprintf("If not unattended cash and not manual cash and not purchase with cashback");} - if(CVM[counter+1] == 0x03){ - Dbprintf("If terminal supports the CVM");} - if(CVM[counter+1] == 0x04){ - Dbprintf("If manual cash");} - if(CVM[counter+1] == 0x05){ - Dbprintf("If purchase with cashback");} - if(CVM[counter+1] == 0x06){ - Dbprintf("If transaction is in the application currency and is under %lu value", amountX);} - if(CVM[counter+1] == 0x07){ - Dbprintf("If transaction is in the application currency and is over %lu value", amountX);} - if(CVM[counter+1] == 0x08){ - Dbprintf("If transaction is in the application currency and is under %lu value", amountY);} - if(CVM[counter+1] == 0x09){ - Dbprintf("If transaction is in the application currency and is over %lu value", amountY);} + if (CVM[counter+1] == 0x00){ Dbprintf("Always");} + if (CVM[counter+1] == 0x01){ Dbprintf("If unattended cash");} + if (CVM[counter+1] == 0x02){ Dbprintf("If not unattended cash and not manual cash and not purchase with cashback");} + if (CVM[counter+1] == 0x03){ Dbprintf("If terminal supports the CVM");} + if (CVM[counter+1] == 0x04){ Dbprintf("If manual cash");} + if (CVM[counter+1] == 0x05){ Dbprintf("If purchase with cashback");} + if (CVM[counter+1] == 0x06){ Dbprintf("If transaction is in the application currency and is under %" PRIu32 " value", amountX);} + if (CVM[counter+1] == 0x07){ Dbprintf("If transaction is in the application currency and is over %" PRIu32 " value", amountX);} + if (CVM[counter+1] == 0x08){ Dbprintf("If transaction is in the application currency and is under %" PRIu32 " value", amountY);} + if (CVM[counter+1] == 0x09){ Dbprintf("If transaction is in the application currency and is over %" PRIu32 " value", amountY);} } return 0; } +//simulate a emvcard card +//input is a structure containing values to simulate +//clones an EMV card +void emvsnoop() { + //states + int cardSTATE = EMVEMUL_NOFIELD; + int vHf = 0; + int res; + uint16_t len = 0; + uint8_t* receivedCmd = BigBuf_malloc(MAX_MIFARE_FRAME_SIZE); + uint8_t par[MAX_MIFARE_PARITY_SIZE] = {0x00}; + uint8_t rATQA[] = {0x04,0x00}; + uint8_t rUIDBCC[] = {0x8F,0x2F,0x27,0xE1, 0x66}; + uint8_t rSAK[] = {0x28, 0xB4, 0xFC}; + + iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN); + bool finished = FALSE; + + while (!BUTTON_PRESS() && !finished){ + WDT_HIT(); + //find reader field + if(cardSTATE == EMVEMUL_NOFIELD){ + vHf = (33000 * AvgAdc(ADC_CHAN_HF)) >> 10; + if(vHf > EMV_MINFIELDV){ + cardSTATE_TO_IDLE(); + LED_A_ON(); + } + } + if(cardSTATE == EMVEMUL_NOFIELD) continue; + + //get data + + res = EmGetCmd(receivedCmd, &len, par); + if(res == 2) { //field is off + cardSTATE = EMVEMUL_NOFIELD; + LEDsoff(); + continue; + } + else if(res==1){ + break; // button press + } + + if(len==1 && ((receivedCmd[0] == 0x26 && cardSTATE != EMVEMUL_HALTED) || receivedCmd[0] == 0x52)){ + EmSendCmd(rATQA, sizeof(rATQA)); + cardSTATE = EMVEMUL_SELECT1; + continue; + } + switch(cardSTATE){ + case EMVEMUL_NOFIELD: + case EMVEMUL_HALTED: + case EMVEMUL_IDLE:{ + break; + } + case EMVEMUL_SELECT1:{ + //select all + if(len==2 && (receivedCmd[0] == 0x93 && receivedCmd[1] == 0x20)) { + EmSendCmd(rUIDBCC, sizeof(rUIDBCC)); + break; + } + if(len==2 && (receivedCmd[0] == 0x93 && receivedCmd[1] == 0x70 && memcmp(&receivedCmd[2], rUIDBCC, 4) == 0)) { + EmSendCmd(rSAK, sizeof(rSAK)); + break; + } + } + } + } + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + LEDsoff(); +} //ICEMAN: move to client //dump the current card to the console -void dumpCard(emvtags* currentcard){ +void dumpCard(emvcard* currentcard){ DUMP(currentcard->ATQA); Dbhexdump(sizeof(currentcard->ATQA), currentcard->ATQA, false); DUMP(currentcard->UID); Dbhexdump(currentcard->UID_len, currentcard->UID, false); - DUMP(currentcard->SAK1); - Dbhexdump(1, ¤tcard->SAK1, false); - DUMP(currentcard->SAK2); - Dbhexdump(1, ¤tcard->SAK2, false); + DUMP(currentcard->SAK); + Dbhexdump(1, ¤tcard->SAK, false); DUMP(currentcard->ATS); - Dbhexdump(currentcard->ATS_len, currentcard->ATS, false); - + Dbhexdump(currentcard->ATS_len, currentcard->ATS, false); DUMP(currentcard->tag_4F); Dbhexdump(currentcard->tag_4F_len, currentcard->tag_4F, false); DUMP(currentcard->tag_50); @@ -1578,9 +1602,9 @@ void dumpCard(emvtags* currentcard){ Dbhexdump(currentcard->tag_86_len, currentcard->tag_86, false); DUMP(currentcard->tag_87); Dbhexdump(1, currentcard->tag_87, false); -DUMP(currentcard->tag_88); + DUMP(currentcard->tag_88); Dbhexdump(1, currentcard->tag_88, false); -DUMP(currentcard->tag_8A); + DUMP(currentcard->tag_8A); Dbhexdump(2, currentcard->tag_8A, false); DUMP(currentcard->tag_8C); Dbhexdump(currentcard->tag_8C_len, currentcard->tag_8C, false);