]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/emv/cmdemv.c
42c8524aaaa897e80df91033e6b3dda6811060d0
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 //-----------------------------------------------------------------------------
12 #include "test/cryptotest.h"
14 int UsageCmdHFEMVSelect(void) {
15 PrintAndLog("HELP : Executes select applet command:\n");
16 PrintAndLog("Usage: hf emv select [-s][-k][-a][-t] <HEX applet AID>\n");
17 PrintAndLog(" Options:");
18 PrintAndLog(" -s : select card");
19 PrintAndLog(" -k : keep field for next command");
20 PrintAndLog(" -a : show APDU reqests and responses\n");
21 PrintAndLog(" -t : TLV decode results\n");
22 PrintAndLog("Samples:");
23 PrintAndLog(" hf emv select -s a00000000101 -> select card, select applet");
24 PrintAndLog(" hf emv select -s -t a00000000101 -> select card, select applet, show result in TLV");
28 int CmdHFEMVSelect(const char *cmd
) {
29 uint8_t data
[APDU_AID_LEN
] = {0};
31 bool activateField
= false;
32 bool leaveSignalON
= false;
33 bool decodeTLV
= false;
35 if (strlen(cmd
) < 1) {
36 UsageCmdHFEMVSelect();
40 SetAPDULogging(false);
43 while(param_getchar(cmd
, cmdp
) != 0x00) {
44 char c
= param_getchar(cmd
, cmdp
);
45 if ((c
== '-') && (param_getlength(cmd
, cmdp
) == 2))
46 switch (param_getchar_indx(cmd
, 1, cmdp
)) {
49 UsageCmdHFEMVSelect();
68 PrintAndLog("Unknown parameter '%c'", param_getchar_indx(cmd
, 1, cmdp
));
73 switch(param_gethex_to_eol(cmd
, cmdp
, data
, sizeof(data
), &datalen
)) {
75 PrintAndLog("Invalid HEX value.");
78 PrintAndLog("AID too large.");
81 PrintAndLog("Hex must have even number of digits.");
85 // we get all the hex to end of line with spaces
94 uint8_t buf
[APDU_RES_LEN
] = {0};
97 int res
= EMVSelect(activateField
, leaveSignalON
, data
, datalen
, buf
, sizeof(buf
), &len
, &sw
, NULL
);
100 PrintAndLog("APDU response status: %04x - %s", sw
, GetAPDUCodeDescription(sw
>> 8, sw
& 0xff));
106 TLVPrintFromBuffer(buf
, len
);
111 int UsageCmdHFEMVSearch(void) {
112 PrintAndLog("HELP : Tries to select all applets from applet list:\n");
113 PrintAndLog("Usage: hf emv search [-s][-k][-a][-t]\n");
114 PrintAndLog(" Options:");
115 PrintAndLog(" -s : select card");
116 PrintAndLog(" -k : keep field for next command");
117 PrintAndLog(" -a : show APDU reqests and responses\n");
118 PrintAndLog(" -t : TLV decode results of selected applets\n");
119 PrintAndLog("Samples:");
120 PrintAndLog(" hf emv search -s -> select card and search");
121 PrintAndLog(" hf emv search -s -t -> select card, search and show result in TLV");
125 int CmdHFEMVSearch(const char *cmd
) {
127 bool activateField
= false;
128 bool leaveSignalON
= false;
129 bool decodeTLV
= false;
131 if (strlen(cmd
) < 1) {
132 UsageCmdHFEMVSearch();
136 SetAPDULogging(false);
139 while(param_getchar(cmd
, cmdp
) != 0x00) {
140 char c
= param_getchar(cmd
, cmdp
);
141 if ((c
== '-') && (param_getlength(cmd
, cmdp
) == 2))
142 switch (param_getchar_indx(cmd
, 1, cmdp
)) {
145 UsageCmdHFEMVSearch();
149 activateField
= true;
153 leaveSignalON
= true;
157 SetAPDULogging(true);
164 PrintAndLog("Unknown parameter '%c'", param_getchar_indx(cmd
, 1, cmdp
));
170 struct tlvdb
*t
= NULL
;
171 const char *al
= "Applets list";
172 t
= tlvdb_fixed(1, strlen(al
), (const unsigned char *)al
);
174 if (EMVSearch(activateField
, leaveSignalON
, decodeTLV
, t
)) {
179 PrintAndLog("Search completed.");
183 TLVPrintAIDlistFromSelectTLV(t
);
191 int UsageCmdHFEMVPPSE(void) {
192 PrintAndLog("HELP : Executes PSE/PPSE select command. It returns list of applet on the card:\n");
193 PrintAndLog("Usage: hf emv pse [-s][-k][-1][-2][-a][-t]\n");
194 PrintAndLog(" Options:");
195 PrintAndLog(" -s : select card");
196 PrintAndLog(" -k : keep field for next command");
197 PrintAndLog(" -1 : ppse (1PAY.SYS.DDF01)");
198 PrintAndLog(" -2 : pse (2PAY.SYS.DDF01)");
199 PrintAndLog(" -a : show APDU reqests and responses\n");
200 PrintAndLog(" -t : TLV decode results\n");
201 PrintAndLog("Samples:");
202 PrintAndLog(" hf emv pse -s -1 -> select, get pse");
203 PrintAndLog(" hf emv pse -s -k -2 -> select, get ppse, keep field");
204 PrintAndLog(" hf emv pse -s -t -2 -> select, get ppse, show result in TLV");
208 int CmdHFEMVPPSE(const char *cmd
) {
211 bool activateField
= false;
212 bool leaveSignalON
= false;
213 bool decodeTLV
= false;
215 if (strlen(cmd
) < 1) {
220 SetAPDULogging(false);
223 while(param_getchar(cmd
, cmdp
) != 0x00) {
224 char c
= param_getchar(cmd
, cmdp
);
225 if ((c
== '-') && (param_getlength(cmd
, cmdp
) == 2))
226 switch (param_getchar_indx(cmd
, 1, cmdp
)) {
233 activateField
= true;
237 leaveSignalON
= true;
241 SetAPDULogging(true);
254 PrintAndLog("Unknown parameter '%c'", param_getchar_indx(cmd
, 1, cmdp
));
261 uint8_t buf
[APDU_RES_LEN
] = {0};
264 int res
= EMVSelectPSE(activateField
, leaveSignalON
, PSENum
, buf
, sizeof(buf
), &len
, &sw
);
267 PrintAndLog("APDU response status: %04x - %s", sw
, GetAPDUCodeDescription(sw
>> 8, sw
& 0xff));
274 TLVPrintFromBuffer(buf
, len
);
279 int UsageCmdHFEMVExec(void) {
280 PrintAndLog("HELP : Executes EMV contactless transaction:\n");
281 PrintAndLog("Usage: hf emv exec [-s][-a][-t][-f][-v][-c][-x][-g]\n");
282 PrintAndLog(" Options:");
283 PrintAndLog(" -s : select card");
284 PrintAndLog(" -a : show APDU reqests and responses\n");
285 PrintAndLog(" -t : TLV decode results\n");
286 PrintAndLog(" -f : force search AID. Search AID instead of execute PPSE.\n");
287 PrintAndLog(" -v : transaction type - qVSDC or M/Chip.\n");
288 PrintAndLog(" -c : transaction type - qVSDC or M/Chip plus CDA (SDAD generation).\n");
289 PrintAndLog(" -x : transaction type - VSDC. For test only. Not a standart behavior.\n");
290 PrintAndLog(" -g : VISA. generate AC from GPO\n");
291 PrintAndLog("By default : transaction type - MSD.\n");
292 PrintAndLog("Samples:");
293 PrintAndLog(" hf emv exec -s -a -t -> execute MSD transaction");
294 PrintAndLog(" hf emv exec -s -a -t -c -> execute CDA transaction");
298 #define TLV_ADD(tag, value)( tlvdb_add(tlvRoot, tlvdb_fixed(tag, sizeof(value) - 1, (const unsigned char *)value)) )
299 #define dreturn(n) {free(pdol_data_tlv);tlvdb_free(tlvSelect);tlvdb_free(tlvRoot);DropField();return n;}
301 int CmdHFEMVExec(const char *cmd
) {
302 bool activateField
= false;
303 bool showAPDU
= false;
304 bool decodeTLV
= false;
305 bool forceSearch
= false;
306 enum TransactionType TrType
= TT_MSD
;
307 bool GenACGPO
= false;
309 uint8_t buf
[APDU_RES_LEN
] = {0};
312 uint8_t AID
[APDU_AID_LEN
] = {0};
314 uint8_t ODAiList
[4096];
315 size_t ODAiListLen
= 0;
319 struct tlvdb
*tlvSelect
= NULL
;
320 struct tlvdb
*tlvRoot
= NULL
;
321 struct tlv
*pdol_data_tlv
= NULL
;
323 if (strlen(cmd
) < 1) {
329 while(param_getchar(cmd
, cmdp
) != 0x00) {
330 char c
= param_getchar(cmd
, cmdp
);
331 if ((c
== '-') && (param_getlength(cmd
, cmdp
) == 2))
332 switch (param_getchar_indx(cmd
, 1, cmdp
)) {
339 activateField
= true;
359 TrType
= TT_QVSDCMCHIP
;
370 PrintAndLog("Unknown parameter '%c'", param_getchar_indx(cmd
, 1, cmdp
));
377 // init applets list tree
378 const char *al
= "Applets list";
379 tlvSelect
= tlvdb_fixed(1, strlen(al
), (const unsigned char *)al
);
381 // Application Selection
382 // https://www.openscdp.org/scripts/tutorial/emv/applicationselection.html
385 PrintAndLog("\n* PPSE.");
386 SetAPDULogging(showAPDU
);
387 res
= EMVSearchPSE(activateField
, true, decodeTLV
, tlvSelect
);
389 // check PPSE and select application id
391 TLVPrintAIDlistFromSelectTLV(tlvSelect
);
392 EMVSelectApplication(tlvSelect
, AID
, &AIDlen
);
398 PrintAndLog("\n* Search AID in list.");
399 SetAPDULogging(false);
400 if (EMVSearch(activateField
, true, decodeTLV
, tlvSelect
)) {
404 // check search and select application id
405 TLVPrintAIDlistFromSelectTLV(tlvSelect
);
406 EMVSelectApplication(tlvSelect
, AID
, &AIDlen
);
410 const char *alr
= "Root terminal TLV tree";
411 tlvRoot
= tlvdb_fixed(1, strlen(alr
), (const unsigned char *)alr
);
413 // check if we found EMV application on card
415 PrintAndLog("Can't select AID. EMV AID not found");
420 PrintAndLog("\n* Selecting AID:%s", sprint_hex_inrow(AID
, AIDlen
));
421 SetAPDULogging(showAPDU
);
422 res
= EMVSelect(false, true, AID
, AIDlen
, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
425 PrintAndLog("Can't select AID (%d). Exit...", res
);
430 TLVPrintFromBuffer(buf
, len
);
431 PrintAndLog("* Selected.");
433 PrintAndLog("\n* Init transaction parameters.");
435 //9F66:(Terminal Transaction Qualifiers (TTQ)) len:4
436 char *qVSDC
= "\x26\x00\x00\x00";
438 qVSDC
= "\x26\x80\x00\x00";
442 TLV_ADD(0x9F66, "\x86\x00\x00\x00"); // MSD
444 // not standard for contactless. just for test.
446 TLV_ADD(0x9F66, "\x46\x00\x00\x00"); // VSDC
449 TLV_ADD(0x9F66, qVSDC
); // qVSDC
452 TLV_ADD(0x9F66, qVSDC
); // qVSDC (VISA CDA not enabled)
455 TLV_ADD(0x9F66, "\x26\x00\x00\x00"); // qVSDC
459 //9F02:(Amount, authorized (Numeric)) len:6
460 TLV_ADD(0x9F02, "\x00\x00\x00\x00\x01\x00");
461 //9F1A:(Terminal Country Code) len:2
462 TLV_ADD(0x9F1A, "ru");
463 //5F2A:(Transaction Currency Code) len:2
464 // USD 840, EUR 978, RUR 810, RUB 643, RUR 810(old), UAH 980, AZN 031, n/a 999
465 TLV_ADD(0x5F2A, "\x09\x80");
466 //9A:(Transaction Date) len:3
467 TLV_ADD(0x9A, "\x00\x00\x00");
468 //9C:(Transaction Type) len:1 | 00 => Goods and service #01 => Cash
469 TLV_ADD(0x9C, "\x00");
470 // 9F37 Unpredictable Number len:4
471 TLV_ADD(0x9F37, "\x01\x02\x03\x04");
472 // 9F6A Unpredictable Number (MSD for UDOL) len:4
473 TLV_ADD(0x9F6A, "\x01\x02\x03\x04");
475 TLVPrintFromTLV(tlvRoot
); // TODO delete!!!
477 PrintAndLog("\n* Calc PDOL.");
478 pdol_data_tlv
= dol_process(tlvdb_get(tlvRoot
, 0x9f38, NULL
), tlvRoot
, 0x83);
480 PrintAndLog("ERROR: can't create PDOL TLV.");
484 size_t pdol_data_tlv_data_len
;
485 unsigned char *pdol_data_tlv_data
= tlv_encode(pdol_data_tlv
, &pdol_data_tlv_data_len
);
486 if (!pdol_data_tlv_data
) {
487 PrintAndLog("ERROR: can't create PDOL data.");
490 PrintAndLog("PDOL data[%d]: %s", pdol_data_tlv_data_len
, sprint_hex(pdol_data_tlv_data
, pdol_data_tlv_data_len
));
492 PrintAndLog("\n* GPO.");
493 res
= EMVGPO(true, pdol_data_tlv_data
, pdol_data_tlv_data_len
, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
495 free(pdol_data_tlv_data
);
496 //free(pdol_data_tlv); --- free on exit.
499 PrintAndLog("GPO error(%d): %4x. Exit...", res
, sw
);
503 // process response template format 1 [id:80 2b AIP + x4b AFL] and format 2 [id:77 TLV]
504 if (buf
[0] == 0x80) {
506 PrintAndLog("GPO response format1:");
507 TLVPrintFromBuffer(buf
, len
);
510 if (len
< 4 || (len
- 4) % 4) {
511 PrintAndLog("ERROR: GPO response format1 parsing error. length=%d", len
);
514 struct tlvdb
* f1AIP
= tlvdb_fixed(0x82, 2, buf
+ 2);
515 tlvdb_add(tlvRoot
, f1AIP
);
517 PrintAndLog("\n* * Decode response format 1 (0x80) AIP and AFL:");
518 TLVPrintFromTLV(f1AIP
);
522 struct tlvdb
* f1AFL
= tlvdb_fixed(0x94, len
- 4, buf
+ 2 + 2);
523 tlvdb_add(tlvRoot
, f1AFL
);
525 TLVPrintFromTLV(f1AFL
);
529 TLVPrintFromBuffer(buf
, len
);
532 // extract PAN from track2
534 const struct tlv
*track2
= tlvdb_get(tlvRoot
, 0x57, NULL
);
535 if (!tlvdb_get(tlvRoot
, 0x5a, NULL
) && track2
&& track2
->len
>= 8) {
536 struct tlvdb
*pan
= GetPANFromTrack2(track2
);
538 tlvdb_add(tlvRoot
, pan
);
540 const struct tlv
*pantlv
= tlvdb_get(tlvRoot
, 0x5a, NULL
);
541 PrintAndLog("\n* * Extracted PAN from track2: %s", sprint_hex(pantlv
->value
, pantlv
->len
));
543 PrintAndLog("\n* * WARNING: Can't extract PAN from track2.");
548 PrintAndLog("\n* Read records from AFL.");
549 const struct tlv
*AFL
= tlvdb_get(tlvRoot
, 0x94, NULL
);
550 if (!AFL
|| !AFL
->len
) {
551 PrintAndLog("WARNING: AFL not found.");
554 while(AFL
&& AFL
->len
) {
556 PrintAndLog("ERROR: Wrong AFL length: %d", AFL
->len
);
560 for (int i
= 0; i
< AFL
->len
/ 4; i
++) {
561 uint8_t SFI
= AFL
->value
[i
* 4 + 0] >> 3;
562 uint8_t SFIstart
= AFL
->value
[i
* 4 + 1];
563 uint8_t SFIend
= AFL
->value
[i
* 4 + 2];
564 uint8_t SFIoffline
= AFL
->value
[i
* 4 + 3];
566 PrintAndLog("* * SFI[%02x] start:%02x end:%02x offline:%02x", SFI
, SFIstart
, SFIend
, SFIoffline
);
567 if (SFI
== 0 || SFI
== 31 || SFIstart
== 0 || SFIstart
> SFIend
) {
568 PrintAndLog("SFI ERROR! Skipped...");
572 for(int n
= SFIstart
; n
<= SFIend
; n
++) {
573 PrintAndLog("* * * SFI[%02x] %d", SFI
, n
);
575 res
= EMVReadRecord(true, SFI
, n
, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
577 PrintAndLog("ERROR SFI[%02x]. APDU error %4x", SFI
, sw
);
582 TLVPrintFromBuffer(buf
, len
);
586 // Build Input list for Offline Data Authentication
587 // EMV 4.3 book3 10.3, page 96
590 const unsigned char *abuf
= buf
;
593 if (tlv_parse_tl(&abuf
, &elmlen
, &e
)) {
594 memcpy(&ODAiList
[ODAiListLen
], &buf
[len
- elmlen
], elmlen
);
595 ODAiListLen
+= elmlen
;
597 PrintAndLog("ERROR SFI[%02x]. Creating input list for Offline Data Authentication error.", SFI
);
600 memcpy(&ODAiList
[ODAiListLen
], buf
, len
);
610 // copy Input list for Offline Data Authentication
612 struct tlvdb
*oda
= tlvdb_fixed(0x21, ODAiListLen
, ODAiList
); // not a standard tag
613 tlvdb_add(tlvRoot
, oda
);
614 PrintAndLog("* Input list for Offline Data Authentication added to TLV. len=%d \n", ODAiListLen
);
618 const struct tlv
*AIPtlv
= tlvdb_get(tlvRoot
, 0x82, NULL
);
619 uint16_t AIP
= AIPtlv
->value
[0] + AIPtlv
->value
[1] * 0x100;
620 PrintAndLog("* * AIP=%04x", AIP
);
624 PrintAndLog("\n* SDA");
630 PrintAndLog("\n* DDA");
631 trDDA(decodeTLV
, tlvRoot
);
637 if (TrType
== TT_QVSDCMCHIP
|| TrType
== TT_CDA
){
638 // 9F26: Application Cryptogram
639 const struct tlv
*AC
= tlvdb_get(tlvRoot
, 0x9F26, NULL
);
641 PrintAndLog("\n--> qVSDC transaction.");
642 PrintAndLog("* AC path");
644 // 9F36: Application Transaction Counter (ATC)
645 const struct tlv
*ATC
= tlvdb_get(tlvRoot
, 0x9F36, NULL
);
648 // 9F10: Issuer Application Data - optional
649 const struct tlv
*IAD
= tlvdb_get(tlvRoot
, 0x9F10, NULL
);
652 PrintAndLog("ATC: %s", sprint_hex(ATC
->value
, ATC
->len
));
653 PrintAndLog("AC: %s", sprint_hex(AC
->value
, AC
->len
));
655 PrintAndLog("IAD: %s", sprint_hex(IAD
->value
, IAD
->len
));
657 if (IAD
->len
>= IAD
->value
[0] + 1) {
658 PrintAndLog("\tKey index: 0x%02x", IAD
->value
[1]);
659 PrintAndLog("\tCrypto ver: 0x%02x(%03d)", IAD
->value
[2], IAD
->value
[2]);
660 PrintAndLog("\tCVR:", sprint_hex(&IAD
->value
[3], IAD
->value
[0] - 2));
661 struct tlvdb
* cvr
= tlvdb_fixed(0x20, IAD
->value
[0] - 2, &IAD
->value
[3]);
662 TLVPrintFromTLVLev(cvr
, 1);
665 PrintAndLog("WARNING: IAD not found.");
669 PrintAndLog("ERROR AC: Application Transaction Counter (ATC) not found.");
675 if (GetCardPSVendor(AID
, AIDlen
) == CV_MASTERCARD
&& (TrType
== TT_QVSDCMCHIP
|| TrType
== TT_CDA
)){
676 const struct tlv
*CDOL1
= tlvdb_get(tlvRoot
, 0x8c, NULL
);
677 if (CDOL1
&& GetCardPSVendor(AID
, AIDlen
) == CV_MASTERCARD
) { // and m/chip transaction flag
678 PrintAndLog("\n--> Mastercard M/Chip transaction.");
680 PrintAndLog("* * Generate challenge");
681 res
= EMVGenerateChallenge(true, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
683 PrintAndLog("ERROR GetChallenge. APDU error %4x", sw
);
687 PrintAndLog("ERROR GetChallenge. Wrong challenge length %d", len
);
691 // ICC Dynamic Number
692 struct tlvdb
* ICCDynN
= tlvdb_fixed(0x9f4c, len
, buf
);
693 tlvdb_add(tlvRoot
, ICCDynN
);
695 PrintAndLog("\n* * ICC Dynamic Number:");
696 TLVPrintFromTLV(ICCDynN
);
699 PrintAndLog("* * Calc CDOL1");
700 struct tlv
*cdol_data_tlv
= dol_process(tlvdb_get(tlvRoot
, 0x8c, NULL
), tlvRoot
, 0x01); // 0x01 - dummy tag
702 PrintAndLog("ERROR: can't create CDOL1 TLV.");
705 PrintAndLog("CDOL1 data[%d]: %s", cdol_data_tlv
->len
, sprint_hex(cdol_data_tlv
->value
, cdol_data_tlv
->len
));
707 PrintAndLog("* * AC1");
708 // EMVAC_TC + EMVAC_CDAREQ --- to get SDAD
709 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
);
712 PrintAndLog("AC1 error(%d): %4x. Exit...", res
, sw
);
717 TLVPrintFromBuffer(buf
, len
);
720 PrintAndLog("\n* CDA:");
721 struct tlvdb
*ac_tlv
= tlvdb_parse_multi(buf
, len
);
722 res
= trCDA(tlvRoot
, ac_tlv
, pdol_data_tlv
, cdol_data_tlv
);
724 PrintAndLog("CDA error (%d)", res
);
729 PrintAndLog("\n* M/Chip transaction result:");
730 // 9F27: Cryptogram Information Data (CID)
731 const struct tlv
*CID
= tlvdb_get(tlvRoot
, 0x9F27, NULL
);
733 emv_tag_dump(CID
, stdout
, 0);
734 PrintAndLog("------------------------------");
736 switch(CID
->value
[0] & EMVAC_AC_MASK
){
738 PrintAndLog("Transaction DECLINED.");
741 PrintAndLog("Transaction approved OFFLINE.");
744 PrintAndLog("Transaction approved ONLINE.");
747 PrintAndLog("ERROR: CID transaction code error %2x", CID
->value
[0] & EMVAC_AC_MASK
);
751 PrintAndLog("ERROR: Wrong CID length %d", CID
->len
);
754 PrintAndLog("ERROR: CID(9F27) not found.");
761 if (AIP
& 0x8000 && TrType
== TT_MSD
) {
762 PrintAndLog("\n--> MSD transaction.");
764 PrintAndLog("* MSD dCVV path. Check dCVV");
766 const struct tlv
*track2
= tlvdb_get(tlvRoot
, 0x57, NULL
);
768 PrintAndLog("Track2: %s", sprint_hex(track2
->value
, track2
->len
));
770 struct tlvdb
*dCVV
= GetdCVVRawFromTrack2(track2
);
771 PrintAndLog("dCVV raw data:");
772 TLVPrintFromTLV(dCVV
);
774 if (GetCardPSVendor(AID
, AIDlen
) == CV_MASTERCARD
) {
775 PrintAndLog("\n* Mastercard calculate UDOL");
778 const struct tlv
*UDOL
= tlvdb_get(tlvRoot
, 0x9F69, NULL
);
779 // UDOL(9F69) default: 9F6A (Unpredictable number) 4 bytes
780 const struct tlv defUDOL
= {
783 .value
= (uint8_t *)"\x9f\x6a\x04",
786 PrintAndLog("Use default UDOL.");
788 struct tlv
*udol_data_tlv
= dol_process(UDOL
? UDOL
: &defUDOL
, tlvRoot
, 0x01); // 0x01 - dummy tag
790 PrintAndLog("ERROR: can't create UDOL TLV.");
794 PrintAndLog("UDOL data[%d]: %s", udol_data_tlv
->len
, sprint_hex(udol_data_tlv
->value
, udol_data_tlv
->len
));
796 PrintAndLog("\n* Mastercard compute cryptographic checksum(UDOL)");
798 res
= MSCComputeCryptoChecksum(true, (uint8_t *)udol_data_tlv
->value
, udol_data_tlv
->len
, buf
, sizeof(buf
), &len
, &sw
, tlvRoot
);
800 PrintAndLog("ERROR Compute Crypto Checksum. APDU error %4x", sw
);
806 TLVPrintFromBuffer(buf
, len
);
813 PrintAndLog("ERROR MSD: Track2 data not found.");
822 tlvdb_free(tlvSelect
);
825 PrintAndLog("\n* Transaction completed.");
830 int CmdHFEMVTest(const char *cmd
) {
831 return ExecuteCryptoTests(true);
834 int CmdHelp(const char *Cmd
);
835 static command_t CommandTable
[] = {
836 {"help", CmdHelp
, 1, "This help"},
837 {"exec", CmdHFEMVExec
, 0, "Executes EMV contactless transaction."},
838 {"pse", CmdHFEMVPPSE
, 0, "Execute PPSE. It selects 2PAY.SYS.DDF01 or 1PAY.SYS.DDF01 directory."},
839 {"search", CmdHFEMVSearch
, 0, "Try to select all applets from applets list and print installed applets."},
840 {"select", CmdHFEMVSelect
, 0, "Select applet."},
841 {"test", CmdHFEMVTest
, 0, "Crypto logic test."},
842 {NULL
, NULL
, 0, NULL
}
845 int CmdHFEMV(const char *Cmd
) {
846 CmdsParse(CommandTable
, Cmd
);
850 int CmdHelp(const char *Cmd
) {
851 CmdsHelp(CommandTable
);