]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/emv/cmdemv.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2017 Merlok
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
9 //-----------------------------------------------------------------------------
13 #include "test/cryptotest.h"
15 int UsageCmdHFEMVSelect(void) {
16 PrintAndLog("HELP : Executes select applet command:\n");
17 PrintAndLog("Usage: hf emv select [-s][-k][-a][-t] <HEX applet AID>\n");
18 PrintAndLog(" Options:");
19 PrintAndLog(" -s : select card");
20 PrintAndLog(" -k : keep field for next command");
21 PrintAndLog(" -a : show APDU reqests and responses\n");
22 PrintAndLog(" -t : TLV decode results\n");
23 PrintAndLog("Samples:");
24 PrintAndLog(" hf emv select -s a00000000101 -> select card, select applet");
25 PrintAndLog(" hf emv select -s -t a00000000101 -> select card, select applet, show result in TLV");
29 int CmdHFEMVSelect(const char *cmd
) {
30 uint8_t data
[APDU_AID_LEN
] = {0};
32 bool activateField
= false;
33 bool leaveSignalON
= false;
34 bool decodeTLV
= false;
36 if (strlen(cmd
) < 1) {
37 UsageCmdHFEMVSelect();
41 SetAPDULogging(false);
44 while(param_getchar(cmd
, cmdp
) != 0x00) {
45 char c
= param_getchar(cmd
, cmdp
);
46 if ((c
== '-') && (param_getlength(cmd
, cmdp
) == 2))
47 switch (param_getchar_indx(cmd
, 1, cmdp
)) {
50 UsageCmdHFEMVSelect();
69 PrintAndLog("Unknown parameter '%c'", param_getchar_indx(cmd
, 1, cmdp
));
73 if (isxdigit((unsigned char)c
)) {
74 switch(param_gethex_to_eol(cmd
, cmdp
, data
, sizeof(data
), &datalen
)) {
76 PrintAndLog("Invalid HEX value.");
79 PrintAndLog("AID too large.");
82 PrintAndLog("Hex must have even number of digits.");
86 // we get all the hex to end of line with spaces
95 uint8_t buf
[APDU_RES_LEN
] = {0};
98 int res
= EMVSelect(activateField
, leaveSignalON
, data
, datalen
, buf
, sizeof(buf
), &len
, &sw
, NULL
);
101 PrintAndLog("APDU response status: %04x - %s", sw
, GetAPDUCodeDescription(sw
>> 8, sw
& 0xff));
107 TLVPrintFromBuffer(buf
, len
);
112 int UsageCmdHFEMVSearch(void) {
113 PrintAndLog("HELP : Tries to select all applets from applet list:\n");
114 PrintAndLog("Usage: hf emv search [-s][-k][-a][-t]\n");
115 PrintAndLog(" Options:");
116 PrintAndLog(" -s : select card");
117 PrintAndLog(" -k : keep field for next command");
118 PrintAndLog(" -a : show APDU reqests and responses\n");
119 PrintAndLog(" -t : TLV decode results of selected applets\n");
120 PrintAndLog("Samples:");
121 PrintAndLog(" hf emv search -s -> select card and search");
122 PrintAndLog(" hf emv search -s -t -> select card, search and show result in TLV");
126 int CmdHFEMVSearch(const char *cmd
) {
128 bool activateField
= false;
129 bool leaveSignalON
= false;
130 bool decodeTLV
= false;
132 if (strlen(cmd
) < 1) {
133 UsageCmdHFEMVSearch();
137 SetAPDULogging(false);
140 while(param_getchar(cmd
, cmdp
) != 0x00) {
141 char c
= param_getchar(cmd
, cmdp
);
142 if ((c
== '-') && (param_getlength(cmd
, cmdp
) == 2))
143 switch (param_getchar_indx(cmd
, 1, cmdp
)) {
146 UsageCmdHFEMVSearch();
150 activateField
= true;
154 leaveSignalON
= true;
158 SetAPDULogging(true);
165 PrintAndLog("Unknown parameter '%c'", param_getchar_indx(cmd
, 1, cmdp
));
171 struct tlvdb
*t
= NULL
;
172 const char *al
= "Applets list";
173 t
= tlvdb_fixed(1, strlen(al
), (const unsigned char *)al
);
175 if (EMVSearch(activateField
, leaveSignalON
, decodeTLV
, t
)) {
180 PrintAndLog("Search completed.");
184 TLVPrintAIDlistFromSelectTLV(t
);
192 int UsageCmdHFEMVPPSE(void) {
193 PrintAndLog("HELP : Executes PSE/PPSE select command. It returns list of applet on the card:\n");
194 PrintAndLog("Usage: hf emv pse [-s][-k][-1][-2][-a][-t]\n");
195 PrintAndLog(" Options:");
196 PrintAndLog(" -s : select card");
197 PrintAndLog(" -k : keep field for next command");
198 PrintAndLog(" -1 : ppse (1PAY.SYS.DDF01)");
199 PrintAndLog(" -2 : pse (2PAY.SYS.DDF01)");
200 PrintAndLog(" -a : show APDU reqests and responses\n");
201 PrintAndLog(" -t : TLV decode results\n");
202 PrintAndLog("Samples:");
203 PrintAndLog(" hf emv pse -s -1 -> select, get pse");
204 PrintAndLog(" hf emv pse -s -k -2 -> select, get ppse, keep field");
205 PrintAndLog(" hf emv pse -s -t -2 -> select, get ppse, show result in TLV");
209 int CmdHFEMVPPSE(const char *cmd
) {
212 bool activateField
= false;
213 bool leaveSignalON
= false;
214 bool decodeTLV
= false;
216 if (strlen(cmd
) < 1) {
221 SetAPDULogging(false);
224 while(param_getchar(cmd
, cmdp
) != 0x00) {
225 char c
= param_getchar(cmd
, cmdp
);
226 if ((c
== '-') && (param_getlength(cmd
, cmdp
) == 2))
227 switch (param_getchar_indx(cmd
, 1, cmdp
)) {
234 activateField
= true;
238 leaveSignalON
= true;
242 SetAPDULogging(true);
255 PrintAndLog("Unknown parameter '%c'", param_getchar_indx(cmd
, 1, cmdp
));
262 uint8_t buf
[APDU_RES_LEN
] = {0};
265 int res
= EMVSelectPSE(activateField
, leaveSignalON
, PSENum
, buf
, sizeof(buf
), &len
, &sw
);
268 PrintAndLog("APDU response status: %04x - %s", sw
, GetAPDUCodeDescription(sw
>> 8, sw
& 0xff));
275 TLVPrintFromBuffer(buf
, len
);
280 int UsageCmdHFEMVExec(void) {
281 PrintAndLog("HELP : Executes EMV contactless transaction:\n");
282 PrintAndLog("Usage: hf emv exec [-s][-a][-t][-f][-v][-c][-x][-g]\n");
283 PrintAndLog(" Options:");
284 PrintAndLog(" -s : select card");
285 PrintAndLog(" -a : show APDU reqests and responses\n");
286 PrintAndLog(" -t : TLV decode results\n");
287 PrintAndLog(" -f : force search AID. Search AID instead of execute PPSE.\n");
288 PrintAndLog(" -v : transaction type - qVSDC or M/Chip.\n");
289 PrintAndLog(" -c : transaction type - qVSDC or M/Chip plus CDA (SDAD generation).\n");
290 PrintAndLog(" -x : transaction type - VSDC. For test only. Not a standart behavior.\n");
291 PrintAndLog(" -g : VISA. generate AC from GPO\n");
292 PrintAndLog("By default : transaction type - MSD.\n");
293 PrintAndLog("Samples:");
294 PrintAndLog(" hf emv exec -s -a -t -> execute MSD transaction");
295 PrintAndLog(" hf emv exec -s -a -t -c -> execute CDA transaction");
299 #define TLV_ADD(tag, value)( tlvdb_add(tlvRoot, tlvdb_fixed(tag, sizeof(value) - 1, (const unsigned char *)value)) )
300 #define dreturn(n) {free(pdol_data_tlv);tlvdb_free(tlvSelect);tlvdb_free(tlvRoot);DropField();return n;}
302 int CmdHFEMVExec(const char *cmd
) {
303 bool activateField
= false;
304 bool showAPDU
= false;
305 bool decodeTLV
= false;
306 bool forceSearch
= false;
307 enum TransactionType TrType
= TT_MSD
;
308 bool GenACGPO
= false;
310 uint8_t buf
[APDU_RES_LEN
] = {0};
313 uint8_t AID
[APDU_AID_LEN
] = {0};
315 uint8_t ODAiList
[4096];
316 size_t ODAiListLen
= 0;
320 struct tlvdb
*tlvSelect
= NULL
;
321 struct tlvdb
*tlvRoot
= NULL
;
322 struct tlv
*pdol_data_tlv
= NULL
;
324 if (strlen(cmd
) < 1) {
330 while(param_getchar(cmd
, cmdp
) != 0x00) {
331 char c
= param_getchar(cmd
, cmdp
);
332 if ((c
== '-') && (param_getlength(cmd
, cmdp
) == 2))
333 switch (param_getchar_indx(cmd
, 1, cmdp
)) {
340 activateField
= true;
360 TrType
= TT_QVSDCMCHIP
;
371 PrintAndLog("Unknown parameter '%c'", param_getchar_indx(cmd
, 1, cmdp
));
378 // init applets list tree
379 const char *al
= "Applets list";
380 tlvSelect
= tlvdb_fixed(1, strlen(al
), (const unsigned char *)al
);
382 // Application Selection
383 // https://www.openscdp.org/scripts/tutorial/emv/applicationselection.html
386 PrintAndLog("\n* PPSE.");
387 SetAPDULogging(showAPDU
);
388 res
= EMVSearchPSE(activateField
, true, decodeTLV
, tlvSelect
);
390 // check PPSE and select application id
392 TLVPrintAIDlistFromSelectTLV(tlvSelect
);
393 EMVSelectApplication(tlvSelect
, AID
, &AIDlen
);
399 PrintAndLog("\n* Search AID in list.");
400 SetAPDULogging(false);
401 if (EMVSearch(activateField
, true, decodeTLV
, tlvSelect
)) {
405 // check search and select application id
406 TLVPrintAIDlistFromSelectTLV(tlvSelect
);
407 EMVSelectApplication(tlvSelect
, AID
, &AIDlen
);
411 const char *alr
= "Root terminal TLV tree";
412 tlvRoot
= tlvdb_fixed(1, strlen(alr
), (const unsigned char *)alr
);
414 // check if we found EMV application on card
416 PrintAndLog("Can't select AID. EMV AID not found");
421 PrintAndLog("\n* Selecting AID:%s", sprint_hex_inrow(AID
, AIDlen
));
422 SetAPDULogging(showAPDU
);
423 res
= EMVSelect(false, true, AID
, AIDlen
, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
426 PrintAndLog("Can't select AID (%d). Exit...", res
);
431 TLVPrintFromBuffer(buf
, len
);
432 PrintAndLog("* Selected.");
434 PrintAndLog("\n* Init transaction parameters.");
436 //9F66:(Terminal Transaction Qualifiers (TTQ)) len:4
437 char *qVSDC
= "\x26\x00\x00\x00";
439 qVSDC
= "\x26\x80\x00\x00";
443 TLV_ADD(0x9F66, "\x86\x00\x00\x00"); // MSD
445 // not standard for contactless. just for test.
447 TLV_ADD(0x9F66, "\x46\x00\x00\x00"); // VSDC
450 TLV_ADD(0x9F66, qVSDC
); // qVSDC
453 TLV_ADD(0x9F66, qVSDC
); // qVSDC (VISA CDA not enabled)
456 TLV_ADD(0x9F66, "\x26\x00\x00\x00"); // qVSDC
460 //9F02:(Amount, authorized (Numeric)) len:6
461 TLV_ADD(0x9F02, "\x00\x00\x00\x00\x01\x00");
462 //9F1A:(Terminal Country Code) len:2
463 TLV_ADD(0x9F1A, "ru");
464 //5F2A:(Transaction Currency Code) len:2
465 // USD 840, EUR 978, RUR 810, RUB 643, RUR 810(old), UAH 980, AZN 031, n/a 999
466 TLV_ADD(0x5F2A, "\x09\x80");
467 //9A:(Transaction Date) len:3
468 TLV_ADD(0x9A, "\x00\x00\x00");
469 //9C:(Transaction Type) len:1 | 00 => Goods and service #01 => Cash
470 TLV_ADD(0x9C, "\x00");
471 // 9F37 Unpredictable Number len:4
472 TLV_ADD(0x9F37, "\x01\x02\x03\x04");
473 // 9F6A Unpredictable Number (MSD for UDOL) len:4
474 TLV_ADD(0x9F6A, "\x01\x02\x03\x04");
476 TLVPrintFromTLV(tlvRoot
); // TODO delete!!!
478 PrintAndLog("\n* Calc PDOL.");
479 pdol_data_tlv
= dol_process(tlvdb_get(tlvRoot
, 0x9f38, NULL
), tlvRoot
, 0x83);
481 PrintAndLog("ERROR: can't create PDOL TLV.");
485 size_t pdol_data_tlv_data_len
;
486 unsigned char *pdol_data_tlv_data
= tlv_encode(pdol_data_tlv
, &pdol_data_tlv_data_len
);
487 if (!pdol_data_tlv_data
) {
488 PrintAndLog("ERROR: can't create PDOL data.");
491 PrintAndLog("PDOL data[%d]: %s", pdol_data_tlv_data_len
, sprint_hex(pdol_data_tlv_data
, pdol_data_tlv_data_len
));
493 PrintAndLog("\n* GPO.");
494 res
= EMVGPO(true, pdol_data_tlv_data
, pdol_data_tlv_data_len
, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
496 free(pdol_data_tlv_data
);
497 //free(pdol_data_tlv); --- free on exit.
500 PrintAndLog("GPO error(%d): %4x. Exit...", res
, sw
);
504 // process response template format 1 [id:80 2b AIP + x4b AFL] and format 2 [id:77 TLV]
505 if (buf
[0] == 0x80) {
507 PrintAndLog("GPO response format1:");
508 TLVPrintFromBuffer(buf
, len
);
511 if (len
< 4 || (len
- 4) % 4) {
512 PrintAndLog("ERROR: GPO response format1 parsing error. length=%d", len
);
515 struct tlvdb
* f1AIP
= tlvdb_fixed(0x82, 2, buf
+ 2);
516 tlvdb_add(tlvRoot
, f1AIP
);
518 PrintAndLog("\n* * Decode response format 1 (0x80) AIP and AFL:");
519 TLVPrintFromTLV(f1AIP
);
523 struct tlvdb
* f1AFL
= tlvdb_fixed(0x94, len
- 4, buf
+ 2 + 2);
524 tlvdb_add(tlvRoot
, f1AFL
);
526 TLVPrintFromTLV(f1AFL
);
530 TLVPrintFromBuffer(buf
, len
);
533 // extract PAN from track2
535 const struct tlv
*track2
= tlvdb_get(tlvRoot
, 0x57, NULL
);
536 if (!tlvdb_get(tlvRoot
, 0x5a, NULL
) && track2
&& track2
->len
>= 8) {
537 struct tlvdb
*pan
= GetPANFromTrack2(track2
);
539 tlvdb_add(tlvRoot
, pan
);
541 const struct tlv
*pantlv
= tlvdb_get(tlvRoot
, 0x5a, NULL
);
542 PrintAndLog("\n* * Extracted PAN from track2: %s", sprint_hex(pantlv
->value
, pantlv
->len
));
544 PrintAndLog("\n* * WARNING: Can't extract PAN from track2.");
549 PrintAndLog("\n* Read records from AFL.");
550 const struct tlv
*AFL
= tlvdb_get(tlvRoot
, 0x94, NULL
);
551 if (!AFL
|| !AFL
->len
) {
552 PrintAndLog("WARNING: AFL not found.");
555 while(AFL
&& AFL
->len
) {
557 PrintAndLog("ERROR: Wrong AFL length: %d", AFL
->len
);
561 for (int i
= 0; i
< AFL
->len
/ 4; i
++) {
562 uint8_t SFI
= AFL
->value
[i
* 4 + 0] >> 3;
563 uint8_t SFIstart
= AFL
->value
[i
* 4 + 1];
564 uint8_t SFIend
= AFL
->value
[i
* 4 + 2];
565 uint8_t SFIoffline
= AFL
->value
[i
* 4 + 3];
567 PrintAndLog("* * SFI[%02x] start:%02x end:%02x offline:%02x", SFI
, SFIstart
, SFIend
, SFIoffline
);
568 if (SFI
== 0 || SFI
== 31 || SFIstart
== 0 || SFIstart
> SFIend
) {
569 PrintAndLog("SFI ERROR! Skipped...");
573 for(int n
= SFIstart
; n
<= SFIend
; n
++) {
574 PrintAndLog("* * * SFI[%02x] %d", SFI
, n
);
576 res
= EMVReadRecord(true, SFI
, n
, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
578 PrintAndLog("ERROR SFI[%02x]. APDU error %4x", SFI
, sw
);
583 TLVPrintFromBuffer(buf
, len
);
587 // Build Input list for Offline Data Authentication
588 // EMV 4.3 book3 10.3, page 96
591 const unsigned char *abuf
= buf
;
594 if (tlv_parse_tl(&abuf
, &elmlen
, &e
)) {
595 memcpy(&ODAiList
[ODAiListLen
], &buf
[len
- elmlen
], elmlen
);
596 ODAiListLen
+= elmlen
;
598 PrintAndLog("ERROR SFI[%02x]. Creating input list for Offline Data Authentication error.", SFI
);
601 memcpy(&ODAiList
[ODAiListLen
], buf
, len
);
611 // copy Input list for Offline Data Authentication
613 struct tlvdb
*oda
= tlvdb_fixed(0x21, ODAiListLen
, ODAiList
); // not a standard tag
614 tlvdb_add(tlvRoot
, oda
);
615 PrintAndLog("* Input list for Offline Data Authentication added to TLV. len=%d \n", ODAiListLen
);
619 const struct tlv
*AIPtlv
= tlvdb_get(tlvRoot
, 0x82, NULL
);
620 uint16_t AIP
= AIPtlv
->value
[0] + AIPtlv
->value
[1] * 0x100;
621 PrintAndLog("* * AIP=%04x", AIP
);
625 PrintAndLog("\n* SDA");
631 PrintAndLog("\n* DDA");
632 trDDA(decodeTLV
, tlvRoot
);
638 if (TrType
== TT_QVSDCMCHIP
|| TrType
== TT_CDA
){
639 // 9F26: Application Cryptogram
640 const struct tlv
*AC
= tlvdb_get(tlvRoot
, 0x9F26, NULL
);
642 PrintAndLog("\n--> qVSDC transaction.");
643 PrintAndLog("* AC path");
645 // 9F36: Application Transaction Counter (ATC)
646 const struct tlv
*ATC
= tlvdb_get(tlvRoot
, 0x9F36, NULL
);
649 // 9F10: Issuer Application Data - optional
650 const struct tlv
*IAD
= tlvdb_get(tlvRoot
, 0x9F10, NULL
);
653 PrintAndLog("ATC: %s", sprint_hex(ATC
->value
, ATC
->len
));
654 PrintAndLog("AC: %s", sprint_hex(AC
->value
, AC
->len
));
656 PrintAndLog("IAD: %s", sprint_hex(IAD
->value
, IAD
->len
));
658 if (IAD
->len
>= IAD
->value
[0] + 1) {
659 PrintAndLog("\tKey index: 0x%02x", IAD
->value
[1]);
660 PrintAndLog("\tCrypto ver: 0x%02x(%03d)", IAD
->value
[2], IAD
->value
[2]);
661 PrintAndLog("\tCVR:", sprint_hex(&IAD
->value
[3], IAD
->value
[0] - 2));
662 struct tlvdb
* cvr
= tlvdb_fixed(0x20, IAD
->value
[0] - 2, &IAD
->value
[3]);
663 TLVPrintFromTLVLev(cvr
, 1);
666 PrintAndLog("WARNING: IAD not found.");
670 PrintAndLog("ERROR AC: Application Transaction Counter (ATC) not found.");
676 if (GetCardPSVendor(AID
, AIDlen
) == CV_MASTERCARD
&& (TrType
== TT_QVSDCMCHIP
|| TrType
== TT_CDA
)){
677 const struct tlv
*CDOL1
= tlvdb_get(tlvRoot
, 0x8c, NULL
);
678 if (CDOL1
&& GetCardPSVendor(AID
, AIDlen
) == CV_MASTERCARD
) { // and m/chip transaction flag
679 PrintAndLog("\n--> Mastercard M/Chip transaction.");
681 PrintAndLog("* * Generate challenge");
682 res
= EMVGenerateChallenge(true, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
684 PrintAndLog("ERROR GetChallenge. APDU error %4x", sw
);
688 PrintAndLog("ERROR GetChallenge. Wrong challenge length %d", len
);
692 // ICC Dynamic Number
693 struct tlvdb
* ICCDynN
= tlvdb_fixed(0x9f4c, len
, buf
);
694 tlvdb_add(tlvRoot
, ICCDynN
);
696 PrintAndLog("\n* * ICC Dynamic Number:");
697 TLVPrintFromTLV(ICCDynN
);
700 PrintAndLog("* * Calc CDOL1");
701 struct tlv
*cdol_data_tlv
= dol_process(tlvdb_get(tlvRoot
, 0x8c, NULL
), tlvRoot
, 0x01); // 0x01 - dummy tag
703 PrintAndLog("ERROR: can't create CDOL1 TLV.");
706 PrintAndLog("CDOL1 data[%d]: %s", cdol_data_tlv
->len
, sprint_hex(cdol_data_tlv
->value
, cdol_data_tlv
->len
));
708 PrintAndLog("* * AC1");
709 // EMVAC_TC + EMVAC_CDAREQ --- to get SDAD
710 res
= EMVAC(true, (TrType
== TT_CDA
) ? EMVAC_TC
+ EMVAC_CDAREQ
: EMVAC_TC
, (uint8_t *)cdol_data_tlv
->value
, cdol_data_tlv
->len
, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
713 PrintAndLog("AC1 error(%d): %4x. Exit...", res
, sw
);
718 TLVPrintFromBuffer(buf
, len
);
721 PrintAndLog("\n* CDA:");
722 struct tlvdb
*ac_tlv
= tlvdb_parse_multi(buf
, len
);
723 res
= trCDA(tlvRoot
, ac_tlv
, pdol_data_tlv
, cdol_data_tlv
);
725 PrintAndLog("CDA error (%d)", res
);
730 PrintAndLog("\n* M/Chip transaction result:");
731 // 9F27: Cryptogram Information Data (CID)
732 const struct tlv
*CID
= tlvdb_get(tlvRoot
, 0x9F27, NULL
);
734 emv_tag_dump(CID
, stdout
, 0);
735 PrintAndLog("------------------------------");
737 switch(CID
->value
[0] & EMVAC_AC_MASK
){
739 PrintAndLog("Transaction DECLINED.");
742 PrintAndLog("Transaction approved OFFLINE.");
745 PrintAndLog("Transaction approved ONLINE.");
748 PrintAndLog("ERROR: CID transaction code error %2x", CID
->value
[0] & EMVAC_AC_MASK
);
752 PrintAndLog("ERROR: Wrong CID length %d", CID
->len
);
755 PrintAndLog("ERROR: CID(9F27) not found.");
762 if (AIP
& 0x8000 && TrType
== TT_MSD
) {
763 PrintAndLog("\n--> MSD transaction.");
765 PrintAndLog("* MSD dCVV path. Check dCVV");
767 const struct tlv
*track2
= tlvdb_get(tlvRoot
, 0x57, NULL
);
769 PrintAndLog("Track2: %s", sprint_hex(track2
->value
, track2
->len
));
771 struct tlvdb
*dCVV
= GetdCVVRawFromTrack2(track2
);
772 PrintAndLog("dCVV raw data:");
773 TLVPrintFromTLV(dCVV
);
775 if (GetCardPSVendor(AID
, AIDlen
) == CV_MASTERCARD
) {
776 PrintAndLog("\n* Mastercard calculate UDOL");
779 const struct tlv
*UDOL
= tlvdb_get(tlvRoot
, 0x9F69, NULL
);
780 // UDOL(9F69) default: 9F6A (Unpredictable number) 4 bytes
781 const struct tlv defUDOL
= {
784 .value
= (uint8_t *)"\x9f\x6a\x04",
787 PrintAndLog("Use default UDOL.");
789 struct tlv
*udol_data_tlv
= dol_process(UDOL
? UDOL
: &defUDOL
, tlvRoot
, 0x01); // 0x01 - dummy tag
791 PrintAndLog("ERROR: can't create UDOL TLV.");
795 PrintAndLog("UDOL data[%d]: %s", udol_data_tlv
->len
, sprint_hex(udol_data_tlv
->value
, udol_data_tlv
->len
));
797 PrintAndLog("\n* Mastercard compute cryptographic checksum(UDOL)");
799 res
= MSCComputeCryptoChecksum(true, (uint8_t *)udol_data_tlv
->value
, udol_data_tlv
->len
, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
801 PrintAndLog("ERROR Compute Crypto Checksum. APDU error %4x", sw
);
807 TLVPrintFromBuffer(buf
, len
);
814 PrintAndLog("ERROR MSD: Track2 data not found.");
823 tlvdb_free(tlvSelect
);
826 PrintAndLog("\n* Transaction completed.");
831 int CmdHFEMVTest(const char *cmd
) {
832 return ExecuteCryptoTests(true);
835 int CmdHelp(const char *Cmd
);
836 static command_t CommandTable
[] = {
837 {"help", CmdHelp
, 1, "This help"},
838 {"exec", CmdHFEMVExec
, 0, "Executes EMV contactless transaction."},
839 {"pse", CmdHFEMVPPSE
, 0, "Execute PPSE. It selects 2PAY.SYS.DDF01 or 1PAY.SYS.DDF01 directory."},
840 {"search", CmdHFEMVSearch
, 0, "Try to select all applets from applets list and print installed applets."},
841 {"select", CmdHFEMVSelect
, 0, "Select applet."},
842 {"test", CmdHFEMVTest
, 0, "Crypto logic test."},
843 {NULL
, NULL
, 0, NULL
}
846 int CmdHFEMV(const char *Cmd
) {
847 CmdsParse(CommandTable
, Cmd
);
851 int CmdHelp(const char *Cmd
) {
852 CmdsHelp(CommandTable
);