#include "cmdemv.h"
#include <ctype.h>
+#include <string.h>
#include "proxmark3.h"
#include "cmdparser.h"
+#include "ui.h"
+#include "util.h"
#include "mifare.h"
#include "emvjson.h"
#include "emv_pki.h"
#include "cliparser/cliparser.h"
#include "jansson.h"
#include "emv_roca.h"
-
+#include "pcsc.h"
+#include "apduinfo.h"
+#include "dol.h"
+#include "emv_tags.h"
+#include "cmdhf14a.h"
#define TLV_ADD(tag, value)( tlvdb_change_or_add_node(tlvRoot, tag, sizeof(value) - 1, (const unsigned char *)value) )
void ParamLoadDefaults(struct tlvdb *tlvRoot) {
PrintAndLogEx(INFO, "Channel: CONTACTLESS");
break;
case ECC_CONTACT:
- PrintAndLogEx(INFO, "Channel: CONTACT");
+ PrintAndLogEx(INFO, "Channel: CONTACT, using %s", getAlternativeSmartcardReader());
break;
}
}
return 0;
}
-#define dreturn(n) {free(pdol_data_tlv);tlvdb_free(tlvSelect);tlvdb_free(tlvRoot);DropField();return n;}
+#define dreturn(n) {free(pdol_data_tlv); tlvdb_free(tlvSelect); tlvdb_free(tlvRoot); DropFieldEx( channel ); return n;}
void InitTransactionParameters(struct tlvdb *tlvRoot, bool paramLoadJSON, enum TransactionType TrType, bool GenACGPO) {
PrintAndLogEx(NORMAL, "* * Host Response: `%s`", HostResponse);
tlvdb_change_or_add_node(tlvRoot, 0x8a, sizeof(HostResponse) - 1, (const unsigned char *)HostResponse);
- }
- if (channel == ECC_CONTACTLESS) {
- DropField();
}
+ DropFieldEx( channel );
+
// Destroy TLV's
free(pdol_data_tlv);
tlvdb_free(tlvSelect);
}
// drop field at start
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
+ DropFieldEx( channel );
// iso 14443 select
PrintAndLogEx(NORMAL, "--> GET UID, ATS.");
if (EMVSearch(channel, false, true, decodeTLV, tlvSelect)) {
PrintAndLogEx(ERR, "Can't found any of EMV AID. Exit...");
tlvdb_free(tlvSelect);
- DropField();
+ DropFieldEx( channel );
return 3;
}
if (!AIDlen) {
PrintAndLogEx(INFO, "Can't select AID. EMV AID not found. Exit...");
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
+ DropFieldEx( channel );
return 4;
}
if (res) {
PrintAndLogEx(ERR, "Can't select AID (%d). Exit...", res);
tlvdb_free(tlvRoot);
- DropField();
+ DropFieldEx( channel );
return 5;
}
if (!pdol_data_tlv){
PrintAndLogEx(ERR, "Can't create PDOL TLV.");
tlvdb_free(tlvRoot);
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
+ DropFieldEx( channel );
return 6;
}
if (!pdol_data_tlv_data) {
PrintAndLogEx(ERR, "Can't create PDOL data.");
tlvdb_free(tlvRoot);
- DropField();
+ DropFieldEx( channel );
return 6;
}
PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));
if (res) {
PrintAndLogEx(ERR, "GPO error(%d): %4x. Exit...", res, sw);
tlvdb_free(tlvRoot);
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
+ DropFieldEx( channel );
return 7;
}
ProcessGPOResponseFormat1(tlvRoot, buf, len, decodeTLV);
// free tlv object
tlvdb_free(tlvRoot);
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
+ DropFieldEx( channel );
res = json_dump_file(root, fname, JSON_INDENT(2));
if (res) {
if (EMVSearch(channel, false, true, false, tlvSelect)) {
PrintAndLogEx(ERR, "Couldn't find any known EMV AID. Exit...");
tlvdb_free(tlvSelect);
- DropField();
+ DropFieldEx( channel );
return 3;
}
}
// EMV SELECT application
- SetAPDULogging(true);
+ SetAPDULogging(false);
EMVSelectApplication(tlvSelect, AID, &AIDlen);
tlvdb_free(tlvSelect);
if (!AIDlen) {
PrintAndLogEx(INFO, "Can't select AID. EMV AID not found. Exit...");
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
+ DropFieldEx( channel );
return 4;
}
if (res) {
PrintAndLogEx(ERR, "Can't select AID (%d). Exit...", res);
tlvdb_free(tlvRoot);
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
+ DropFieldEx( channel );
return 5;
}
if (!pdol_data_tlv){
PrintAndLogEx(ERR, "Can't create PDOL TLV.");
tlvdb_free(tlvRoot);
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
+ DropFieldEx( channel );
return 6;
}
if (!pdol_data_tlv_data) {
PrintAndLogEx(ERR, "Can't create PDOL data.");
tlvdb_free(tlvRoot);
- DropField();
+ DropFieldEx( channel );
return 6;
}
PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));
if (res) {
PrintAndLogEx(ERR, "GPO error(%d): %4x. Exit...", res, sw);
tlvdb_free(tlvRoot);
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
+ DropFieldEx( channel );
return 7;
}
ProcessGPOResponseFormat1(tlvRoot, buf, len, false);
struct emv_pk *pk = get_ca_pk(tlvRoot);
if (!pk) {
- PrintAndLogEx(ERR, "ERROR: Key not found. Exit.");
+ PrintAndLogEx(ERR, "CA Public Key not found. Exit.");
goto out;
}
goto out;
}
+ char RID[15] = {0};
+ memcpy(RID, sprint_hex(issuer_pk->rid, 5), 14);
PrintAndLogEx(SUCCESS, "Issuer PK recovered. RID %s IDX %02hhx CSN %s",
- sprint_hex(issuer_pk->rid, 5),
+ RID,
issuer_pk->index,
sprint_hex(issuer_pk->serial, 3)
);
PrintAndLogEx(WARNING, "WARNING: ICC certificate not found. Exit.");
goto out;
}
+
+ memcpy(RID, sprint_hex(icc_pk->rid, 5), 14);
PrintAndLogEx(SUCCESS, "ICC PK recovered. RID %s IDX %02hhx CSN %s\n",
- sprint_hex(icc_pk->rid, 5),
+ RID,
icc_pk->index,
sprint_hex(icc_pk->serial, 3)
);
// free tlv object
tlvdb_free(tlvRoot);
- if (channel == ECC_CONTACTLESS) {
- DropField();
- }
-
+ DropFieldEx( channel );
return 0;
}