}
int CmdEMVSelect(const char *cmd) {
- uint8_t data[APDU_AID_LEN] = {0};
+ uint8_t data[APDU_DATA_LEN] = {0};
int datalen = 0;
CLIParserInit("emv select",
SetAPDULogging(APDULogging);
// exec
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVSelect(channel, activateField, leaveSignalON, data, datalen, buf, sizeof(buf), &len, &sw, NULL);
SetAPDULogging(APDULogging);
// exec
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVSelectPSE(channel, activateField, leaveSignalON, PSENum, buf, sizeof(buf), &len, &sw);
}
int CmdEMVGPO(const char *cmd) {
- uint8_t data[APDU_RES_LEN] = {0};
+ uint8_t data[APDU_RESPONSE_LEN] = {0};
int datalen = 0;
CLIParserInit("emv gpo",
PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));
// exec
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVGPO(channel, leaveSignalON, pdol_data_tlv_data, pdol_data_tlv_data_len, buf, sizeof(buf), &len, &sw, tlvRoot);
}
int CmdEMVReadRecord(const char *cmd) {
- uint8_t data[APDU_RES_LEN] = {0};
+ uint8_t data[APDU_RESPONSE_LEN] = {0};
int datalen = 0;
CLIParserInit("emv readrec",
SetAPDULogging(APDULogging);
// exec
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVReadRecord(channel, leaveSignalON, data[0], data[1], buf, sizeof(buf), &len, &sw, NULL);
}
int CmdEMVAC(const char *cmd) {
- uint8_t data[APDU_RES_LEN] = {0};
+ uint8_t data[APDU_RESPONSE_LEN] = {0};
int datalen = 0;
CLIParserInit("emv genac",
PrintAndLogEx(INFO, "CDOL data[%d]: %s", cdol_data_tlv->len, sprint_hex(cdol_data_tlv->value, cdol_data_tlv->len));
// exec
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVAC(channel, leaveSignalON, termDecision, (uint8_t *)cdol_data_tlv->value, cdol_data_tlv->len, buf, sizeof(buf), &len, &sw, tlvRoot);
SetAPDULogging(APDULogging);
// exec
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVGenerateChallenge(channel, leaveSignalON, buf, sizeof(buf), &len, &sw, NULL);
}
int CmdEMVInternalAuthenticate(const char *cmd) {
- uint8_t data[APDU_RES_LEN] = {0};
+ uint8_t data[APDU_RESPONSE_LEN] = {0};
int datalen = 0;
CLIParserInit("emv intauth",
PrintAndLogEx(INFO, "DDOL data[%d]: %s", ddol_data_tlv->len, sprint_hex(ddol_data_tlv->value, ddol_data_tlv->len));
// exec
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVInternalAuthenticate(channel, leaveSignalON, data, datalen, buf, sizeof(buf), &len, &sw, NULL);
}
int CmdEMVExec(const char *cmd) {
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
- uint8_t AID[APDU_AID_LEN] = {0};
+ uint8_t AID[APDU_DATA_LEN] = {0};
size_t AIDlen = 0;
uint8_t ODAiList[4096];
size_t ODAiListLen = 0;
channel = ECC_CONTACT;
#endif
uint8_t psenum = (channel == ECC_CONTACT) ? 1 : 2;
+ char *PSE_or_PPSE = psenum == 1 ? "PSE" : "PPSE";
+
CLIParserFree();
SetAPDULogging(showAPDU);
// Application Selection
// https://www.openscdp.org/scripts/tutorial/emv/applicationselection.html
if (!forceSearch) {
- // PPSE
- PrintAndLogEx(NORMAL, "\n* PPSE.");
+ // PPSE / PSE
+ PrintAndLogEx(NORMAL, "\n* %s.", PSE_or_PPSE);
SetAPDULogging(showAPDU);
res = EMVSearchPSE(channel, activateField, true, psenum, decodeTLV, tlvSelect);
- // check PPSE and select application id
+ // check PPSE / PSE and select application id
if (!res) {
TLVPrintAIDlistFromSelectTLV(tlvSelect);
EMVSelectApplication(tlvSelect, AID, &AIDlen);
}
}
- DropField();
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
// Destroy TLV's
free(pdol_data_tlv);
}
int CmdEMVScan(const char *cmd) {
- uint8_t AID[APDU_AID_LEN] = {0};
+ uint8_t AID[APDU_DATA_LEN] = {0};
size_t AIDlen = 0;
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res;
}
// drop field at start
- DropField();
-
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
+
// iso 14443 select
PrintAndLogEx(NORMAL, "--> GET UID, ATS.");
if (!AIDlen) {
PrintAndLogEx(INFO, "Can't select AID. EMV AID not found. Exit...");
- DropField();
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
return 4;
}
if (!pdol_data_tlv){
PrintAndLogEx(ERR, "Can't create PDOL TLV.");
tlvdb_free(tlvRoot);
- DropField();
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
return 6;
}
if (res) {
PrintAndLogEx(ERR, "GPO error(%d): %4x. Exit...", res, sw);
tlvdb_free(tlvRoot);
- DropField();
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
return 7;
}
ProcessGPOResponseFormat1(tlvRoot, buf, len, decodeTLV);
// free tlv object
tlvdb_free(tlvRoot);
- // DropField
- DropField();
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
res = json_dump_file(root, fname, JSON_INDENT(2));
if (res) {
}
int CmdEMVRoca(const char *cmd) {
- uint8_t AID[APDU_AID_LEN] = {0};
+ uint8_t AID[APDU_DATA_LEN] = {0};
size_t AIDlen = 0;
- uint8_t buf[APDU_RES_LEN] = {0};
+ uint8_t buf[APDU_RESPONSE_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res;
if (!AIDlen) {
PrintAndLogEx(INFO, "Can't select AID. EMV AID not found. Exit...");
- DropField();
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
return 4;
}
if (res) {
PrintAndLogEx(ERR, "Can't select AID (%d). Exit...", res);
tlvdb_free(tlvRoot);
- DropField();
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
return 5;
}
if (!pdol_data_tlv){
PrintAndLogEx(ERR, "Can't create PDOL TLV.");
tlvdb_free(tlvRoot);
- DropField();
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
return 6;
}
if (res) {
PrintAndLogEx(ERR, "GPO error(%d): %4x. Exit...", res, sw);
tlvdb_free(tlvRoot);
- DropField();
+ if (channel == ECC_CONTACTLESS) {
+ DropField();
+ }
return 7;
}
ProcessGPOResponseFormat1(tlvRoot, buf, len, false);
// free tlv object
tlvdb_free(tlvRoot);
- if ( channel == ECC_CONTACTLESS)
+ if (channel == ECC_CONTACTLESS) {
DropField();
-
+ }
return 0;
}
static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"},
- {"exec", CmdEMVExec, 0, "Executes EMV contactless transaction."},
- {"pse", CmdEMVPPSE, 0, "Execute PPSE. It selects 2PAY.SYS.DDF01 or 1PAY.SYS.DDF01 directory."},
- {"search", CmdEMVSearch, 0, "Try to select all applets from applets list and print installed applets."},
- {"select", CmdEMVSelect, 0, "Select applet."},
- {"gpo", CmdEMVGPO, 0, "Execute GetProcessingOptions."},
- {"readrec", CmdEMVReadRecord, 0, "Read files from card."},
- {"genac", CmdEMVAC, 0, "Generate ApplicationCryptogram."},
- {"challenge", CmdEMVGenerateChallenge, 0, "Generate challenge."},
- {"intauth", CmdEMVInternalAuthenticate, 0, "Internal authentication."},
- {"scan", CmdEMVScan, 0, "Scan EMV card and save it contents to json file for emulator."},
- {"test", CmdEMVTest, 0, "Crypto logic test."},
- {"roca", CmdEMVRoca, 0, "Extract public keys and run ROCA test"},
+ {"exec", CmdEMVExec, 1, "Executes EMV contactless transaction."},
+ {"pse", CmdEMVPPSE, 1, "Execute PPSE. It selects 2PAY.SYS.DDF01 or 1PAY.SYS.DDF01 directory."},
+ {"search", CmdEMVSearch, 1, "Try to select all applets from applets list and print installed applets."},
+ {"select", CmdEMVSelect, 1, "Select applet."},
+ {"gpo", CmdEMVGPO, 1, "Execute GetProcessingOptions."},
+ {"readrec", CmdEMVReadRecord, 1, "Read files from card."},
+ {"genac", CmdEMVAC, 1, "Generate ApplicationCryptogram."},
+ {"challenge", CmdEMVGenerateChallenge, 1, "Generate challenge."},
+ {"intauth", CmdEMVInternalAuthenticate, 1, "Internal authentication."},
+ {"scan", CmdEMVScan, 1, "Scan EMV card and save it contents to json file for emulator."},
+ {"test", CmdEMVTest, 1, "Crypto logic test."},
+ {"roca", CmdEMVRoca, 1, "Extract public keys and run ROCA test"},
{NULL, NULL, 0, NULL}
};