This commit is contained in:
iceman1001 2017-12-05 21:07:03 +01:00
commit 5f87b24493
2 changed files with 83 additions and 66 deletions

View file

@ -1,6 +1,6 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2017 Merlok // Copyright (C) 2017 Merlok
// // modified 2017 iceman
// This code is licensed to you under the terms of the GNU GPL, version 2 or, // This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of // at your option, any later version. See the LICENSE.txt file for the text of
// the license. // the license.
@ -12,8 +12,8 @@
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
int UsageCmdHFEMVSelect(void) { int usage_emv_select(void) {
PrintAndLog("HELP : Executes select applet command:\n"); PrintAndLog("Executes select applet command:\n");
PrintAndLog("Usage: hf emv select [-s][-k][-a][-t] <HEX applet AID>\n"); PrintAndLog("Usage: hf emv select [-s][-k][-a][-t] <HEX applet AID>\n");
PrintAndLog(" Options:"); PrintAndLog(" Options:");
PrintAndLog(" -s : select card"); PrintAndLog(" -s : select card");
@ -33,10 +33,8 @@ int CmdHFEMVSelect(const char *cmd) {
bool leaveSignalON = false; bool leaveSignalON = false;
bool decodeTLV = false; bool decodeTLV = false;
if (strlen(cmd) < 1) { if (strlen(cmd) < 1)
UsageCmdHFEMVSelect(); return usage_emv_select();
return 0;
}
SetAPDULogging(false); SetAPDULogging(false);
@ -47,8 +45,7 @@ int CmdHFEMVSelect(const char *cmd) {
switch (param_getchar_indx(cmd, 1, cmdp)) { switch (param_getchar_indx(cmd, 1, cmdp)) {
case 'h': case 'h':
case 'H': case 'H':
UsageCmdHFEMVSelect(); return usage_emv_select();
return 0;
case 's': case 's':
case 'S': case 'S':
activateField = true; activateField = true;
@ -86,8 +83,6 @@ int CmdHFEMVSelect(const char *cmd) {
// we get all the hex to end of line with spaces // we get all the hex to end of line with spaces
break; break;
} }
cmdp++; cmdp++;
} }
@ -109,8 +104,8 @@ int CmdHFEMVSelect(const char *cmd) {
return 0; return 0;
} }
int UsageCmdHFEMVSearch(void) { int usage_emv_search(void) {
PrintAndLog("HELP : Tries to select all applets from applet list:\n"); PrintAndLog("Tries to select all applets from applet list:\n");
PrintAndLog("Usage: hf emv search [-s][-k][-a][-t]\n"); PrintAndLog("Usage: hf emv search [-s][-k][-a][-t]\n");
PrintAndLog(" Options:"); PrintAndLog(" Options:");
PrintAndLog(" -s : select card"); PrintAndLog(" -s : select card");
@ -129,10 +124,8 @@ int CmdHFEMVSearch(const char *cmd) {
bool leaveSignalON = false; bool leaveSignalON = false;
bool decodeTLV = false; bool decodeTLV = false;
if (strlen(cmd) < 1) { if (strlen(cmd) < 1)
UsageCmdHFEMVSearch(); return usage_emv_search();
return 0;
}
SetAPDULogging(false); SetAPDULogging(false);
@ -143,8 +136,7 @@ int CmdHFEMVSearch(const char *cmd) {
switch (param_getchar_indx(cmd, 1, cmdp)) { switch (param_getchar_indx(cmd, 1, cmdp)) {
case 'h': case 'h':
case 'H': case 'H':
UsageCmdHFEMVSearch(); return usage_emv_search();
return 0;
case 's': case 's':
case 'S': case 'S':
activateField = true; activateField = true;
@ -189,8 +181,8 @@ int CmdHFEMVSearch(const char *cmd) {
return 0; return 0;
} }
int UsageCmdHFEMVPPSE(void) { int usage_emv_ppse(void) {
PrintAndLog("HELP : Executes PSE/PPSE select command. It returns list of applet on the card:\n"); PrintAndLog("Executes PSE/PPSE select command. It returns list of applet on the card:\n");
PrintAndLog("Usage: hf emv pse [-s][-k][-1][-2][-a][-t]\n"); PrintAndLog("Usage: hf emv pse [-s][-k][-1][-2][-a][-t]\n");
PrintAndLog(" Options:"); PrintAndLog(" Options:");
PrintAndLog(" -s : select card"); PrintAndLog(" -s : select card");
@ -213,10 +205,8 @@ int CmdHFEMVPPSE(const char *cmd) {
bool leaveSignalON = false; bool leaveSignalON = false;
bool decodeTLV = false; bool decodeTLV = false;
if (strlen(cmd) < 1) { if (strlen(cmd) < 1)
UsageCmdHFEMVPPSE(); return usage_emv_ppse();
return 0;
}
SetAPDULogging(false); SetAPDULogging(false);
@ -227,8 +217,7 @@ int CmdHFEMVPPSE(const char *cmd) {
switch (param_getchar_indx(cmd, 1, cmdp)) { switch (param_getchar_indx(cmd, 1, cmdp)) {
case 'h': case 'h':
case 'H': case 'H':
UsageCmdHFEMVPPSE(); return usage_emv_ppse();
return 0;
case 's': case 's':
case 'S': case 'S':
activateField = true; activateField = true;
@ -270,15 +259,14 @@ int CmdHFEMVPPSE(const char *cmd) {
if (res) if (res)
return res; return res;
if (decodeTLV) if (decodeTLV)
TLVPrintFromBuffer(buf, len); TLVPrintFromBuffer(buf, len);
return 0; return 0;
} }
int UsageCmdHFEMVExec(void) { int usage_emv_exec(void) {
PrintAndLog("HELP : Executes EMV contactless transaction:\n"); PrintAndLog("Executes EMV contactless transaction:\n");
PrintAndLog("Usage: hf emv exec [-s][-a][-t]\n"); PrintAndLog("Usage: hf emv exec [-s][-a][-t]\n");
PrintAndLog(" Options:"); PrintAndLog(" Options:");
PrintAndLog(" -s : select card"); PrintAndLog(" -s : select card");
@ -310,10 +298,8 @@ int CmdHFEMVExec(const char *cmd) {
int res; int res;
if (strlen(cmd) < 1) { if (strlen(cmd) < 1)
UsageCmdHFEMVExec(); return usage_emv_exec();
return 0;
}
int cmdp = 0; int cmdp = 0;
while(param_getchar(cmd, cmdp) != 0x00) { while(param_getchar(cmd, cmdp) != 0x00) {
@ -322,8 +308,7 @@ int CmdHFEMVExec(const char *cmd) {
switch (param_getchar_indx(cmd, 1, cmdp)) { switch (param_getchar_indx(cmd, 1, cmdp)) {
case 'h': case 'h':
case 'H': case 'H':
UsageCmdHFEMVExec(); return usage_emv_exec();
return 0;
case 's': case 's':
case 'S': case 'S':
activateField = true; activateField = true;
@ -359,7 +344,6 @@ int CmdHFEMVExec(const char *cmd) {
cmdp++; cmdp++;
} }
// init applets list tree // init applets list tree
struct tlvdb *tlvSelect = NULL; struct tlvdb *tlvSelect = NULL;
const char *al = "Applets list"; const char *al = "Applets list";
@ -417,8 +401,8 @@ int CmdHFEMVExec(const char *cmd) {
if (decodeTLV) if (decodeTLV)
TLVPrintFromBuffer(buf, len); TLVPrintFromBuffer(buf, len);
PrintAndLog("* Selected.");
PrintAndLog("* Selected.");
PrintAndLog("\n* Init transaction parameters."); PrintAndLog("\n* Init transaction parameters.");
//9F66:(Terminal Transaction Qualifiers (TTQ)) len:4 //9F66:(Terminal Transaction Qualifiers (TTQ)) len:4
@ -531,9 +515,9 @@ int CmdHFEMVExec(const char *cmd) {
PrintAndLog("\n* Read records from AFL."); PrintAndLog("\n* Read records from AFL.");
const struct tlv *AFL = tlvdb_get(tlvRoot, 0x94, NULL); const struct tlv *AFL = tlvdb_get(tlvRoot, 0x94, NULL);
if (!AFL || !AFL->len) {
if (!AFL || !AFL->len)
PrintAndLog("WARNING: AFL not found."); PrintAndLog("WARNING: AFL not found.");
}
while (AFL && AFL->len) { while (AFL && AFL->len) {
if (AFL->len % 4) { if (AFL->len % 4) {
@ -573,7 +557,6 @@ int CmdHFEMVExec(const char *cmd) {
} }
} }
} }
break; break;
} }
@ -591,9 +574,7 @@ int CmdHFEMVExec(const char *cmd) {
// DDA // DDA
if (AIP & 0x0020) { if (AIP & 0x0020) {
PrintAndLog("\n* DDA"); PrintAndLog("\n* DDA");
} }
// transaction check // transaction check
// qVSDC // qVSDC
@ -760,14 +741,12 @@ int CmdHFEMVExec(const char *cmd) {
TLVPrintFromBuffer(buf, len); TLVPrintFromBuffer(buf, len);
PrintAndLog(""); PrintAndLog("");
} }
} }
} else { } else {
PrintAndLog("ERROR MSD: Track2 data not found."); PrintAndLog("ERROR MSD: Track2 data not found.");
} }
} }
// DropField
DropField(); DropField();
// Destroy TLV's // Destroy TLV's
@ -775,16 +754,47 @@ int CmdHFEMVExec(const char *cmd) {
tlvdb_free(tlvRoot); tlvdb_free(tlvRoot);
PrintAndLog("\n* Transaction completed."); PrintAndLog("\n* Transaction completed.");
return 0;
}
int usage_emv_getrnd(void){
PrintAndLog("retrieve the UN number from a terminal");
PrintAndLog("Usage: hf emv getrnd [h]");
PrintAndLog("Options:");
PrintAndLog(" h : this help");
PrintAndLog("");
PrintAndLog("Samples:");
PrintAndLog(" hf emv getrnd");
return 0;
}
//retrieve the UN number from a terminal
int CmdHfEMVGetrng(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if ( cmdp == 'h' || cmdp == 'H') return usage_emv_getrnd();
return 0; return 0;
} }
int CmdHfEMVList(const char *Cmd) {
return CmdHFList("7816");
}
static command_t CommandTable[] = { static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"}, {"help", CmdHelp, 1, "This help"},
{"exec", CmdHFEMVExec, 0, "Executes EMV contactless transaction."}, {"exec", CmdHFEMVExec, 0, "Executes EMV contactless transaction."},
{"pse", CmdHFEMVPPSE, 0, "Execute PPSE. It selects 2PAY.SYS.DDF01 or 1PAY.SYS.DDF01 directory."}, {"pse", CmdHFEMVPPSE, 0, "Execute PPSE. It selects 2PAY.SYS.DDF01 or 1PAY.SYS.DDF01 directory."},
{"search", CmdHFEMVSearch, 0, "Try to select all applets from applets list and print installed applets."}, {"search", CmdHFEMVSearch, 0, "Try to select all applets from applets list and print installed applets."},
{"select", CmdHFEMVSelect, 0, "Select applet."}, {"select", CmdHFEMVSelect, 0, "Select applet."},
/*
{"getrng", CmdHfEMVGetrng, 0, "get random number from terminal"},
{"eload", CmdHfEmvELoad, 0, "load EMV tag into device"},
{"dump", CmdHfEmvDump, 0, "dump EMV tag values"},
{"sim", CmdHfEmvSim, 0, "simulate EMV tag"},
{"clone", CmdHfEmvClone, 0, "clone an EMV tag"},
*/
{"list", CmdHfEMVList, 0, "[Deprecated] List ISO7816 history"},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };

View file

@ -1,6 +1,6 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2017 Merlok // Copyright (C) 2017 Merlok
// // modified 2017 iceman
// This code is licensed to you under the terms of the GNU GPL, version 2 or, // This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of // at your option, any later version. See the LICENSE.txt file for the text of
// the license. // the license.
@ -26,8 +26,15 @@
#include "emvcore.h" #include "emvcore.h"
#include "apduinfo.h" #include "apduinfo.h"
int CmdHFEMV(const char *Cmd);
#define TLV_ADD(tag, value)( tlvdb_add(tlvRoot, tlvdb_fixed(tag, sizeof(value) - 1, (const unsigned char *)value)) ) #define TLV_ADD(tag, value)( tlvdb_add(tlvRoot, tlvdb_fixed(tag, sizeof(value) - 1, (const unsigned char *)value)) )
int CmdHFEMV(const char *Cmd);
extern int CmdHFEMVSelect(const char *cmd);
extern int CmdHFEMVSearch(const char *cmd);
extern int CmdHFEMVPPSE(const char *cmd);
extern int CmdHFEMVExec(const char *cmd);
extern int CmdHfEMVGetrng(const char *Cmd);
extern int CmdHfEMVList(const char *Cmd);
#endif #endif