Merge branch 'master' into ext_apdu

This commit is contained in:
Oleg Moiseenko
2019-07-15 19:25:48 +03:00
committed by GitHub
116 changed files with 1000 additions and 1827 deletions

View File

@@ -287,8 +287,8 @@ static int CmdEMVGPO(const char *Cmd) {
PrintAndLogEx(ERR, "Can't create PDOL data.");
tlvdb_free(tmp_ext);
tlvdb_free(tlvRoot);
if (pdol_data_tlv != &data_tlv);
free(pdol_data_tlv);
if (pdol_data_tlv != &data_tlv)
free(pdol_data_tlv);
return PM3_ESOFT;
}
PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));
@@ -931,7 +931,7 @@ static int CmdEMVExec(const char *Cmd) {
while (AFL && AFL->len) {
if (AFL->len % 4) {
PrintAndLogEx(WARNING, "Error: Wrong AFL length: %d", AFL->len);
PrintAndLogEx(WARNING, "Warning: Wrong AFL length: %d", AFL->len);
break;
}
@@ -1001,7 +1001,7 @@ static int CmdEMVExec(const char *Cmd) {
AIP = AIPtlv->value[0] + AIPtlv->value[1] * 0x100;
PrintAndLogEx(NORMAL, "* * AIP=%04x", AIP);
} else {
PrintAndLogEx(ERR, "Can't found AIP.");
PrintAndLogEx(ERR, "Can't find AIP.");
}
// SDA
@@ -1047,11 +1047,11 @@ static int CmdEMVExec(const char *Cmd) {
TLVPrintFromTLVLev(cvr, 1);
}
} else {
PrintAndLogEx(NORMAL, "WARNING: IAD not found.");
PrintAndLogEx(WARNING, "WARNING: IAD not found.");
}
} else {
PrintAndLogEx(WARNING, "Error AC: Application Transaction Counter (ATC) not found.");
PrintAndLogEx(WARNING, "Warning AC: Application Transaction Counter (ATC) not found.");
}
}
}
@@ -1131,14 +1131,14 @@ static int CmdEMVExec(const char *Cmd) {
PrintAndLogEx(NORMAL, "Transaction approved ONLINE.");
break;
default:
PrintAndLogEx(WARNING, "Error: CID transaction code error %2x", CID->value[0] & EMVAC_AC_MASK);
PrintAndLogEx(WARNING, "Warning: CID transaction code error %2x", CID->value[0] & EMVAC_AC_MASK);
break;
}
} else {
PrintAndLogEx(WARNING, "Error: Wrong CID length %d", CID->len);
PrintAndLogEx(WARNING, "Warning: Wrong CID length %d", CID->len);
}
} else {
PrintAndLogEx(WARNING, "Error: CID(9F27) not found.");
PrintAndLogEx(WARNING, "Warning: CID(9F27) not found.");
}
}

View File

@@ -24,7 +24,7 @@
#include "emv_pk.h"
#include "crypto.h"
#include "proxmark3.h"
#include "util.h"
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
@@ -398,7 +398,7 @@ static struct emv_pk *emv_pk_get_ca_pk_from_file(const char *fname,
FILE *f = fopen(fname, "r");
if (!f) {
perror("fopen");
PrintAndLogEx(ERR, "Error: can't open file %s.", fname);
return NULL;
}

View File

@@ -511,7 +511,7 @@ int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO
PrintAndLogEx(WARNING, "%s ERROR: Can't get TLV from response.", PSE_or_PPSE);
}
} else {
PrintAndLogEx(WARNING, "%s ERROR: Can't select PPSE AID. Error: %d", PSE_or_PPSE, res);
PrintAndLogEx(ERR, "%s ERROR: Can't select PPSE AID. Error: %d", PSE_or_PPSE, res);
}
if (!LeaveFieldON)
@@ -654,14 +654,14 @@ int trSDA(struct tlvdb *tlv) {
struct emv_pk *pk = get_ca_pk(tlv);
if (!pk) {
PrintAndLogEx(WARNING, "Error: Key not found. Exit.");
PrintAndLogEx(ERR, "Error: Key not found. Exit.");
return 2;
}
struct emv_pk *issuer_pk = emv_pki_recover_issuer_cert(pk, tlv);
if (!issuer_pk) {
emv_pk_free(pk);
PrintAndLogEx(WARNING, "Error: Issuer certificate not found. Exit.");
PrintAndLogEx(ERR, "Error: Issuer certificate not found. Exit.");
return 2;
}
@@ -693,7 +693,7 @@ int trSDA(struct tlvdb *tlv) {
} else {
emv_pk_free(issuer_pk);
emv_pk_free(pk);
PrintAndLogEx(WARNING, "SSAD verify error");
PrintAndLogEx(ERR, "SSAD verify error");
return 4;
}
@@ -712,21 +712,21 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
struct emv_pk *pk = get_ca_pk(tlv);
if (!pk) {
PrintAndLogEx(WARNING, "Error: Key not found. Exit.");
PrintAndLogEx(ERR, "Error: Key not found. Exit.");
return 2;
}
const struct tlv *sda_tlv = tlvdb_get(tlv, 0x21, NULL);
/* if (!sda_tlv || sda_tlv->len < 1) { it may be 0!!!!
emv_pk_free(pk);
PrintAndLogEx(WARNING, "Error: Can't find input list for Offline Data Authentication. Exit.");
PrintAndLogEx(ERR, "Error: Can't find input list for Offline Data Authentication. Exit.");
return 3;
}
*/
struct emv_pk *issuer_pk = emv_pki_recover_issuer_cert(pk, tlv);
if (!issuer_pk) {
emv_pk_free(pk);
PrintAndLogEx(WARNING, "Error: Issuer certificate not found. Exit.");
PrintAndLogEx(ERR, "Error: Issuer certificate not found. Exit.");
return 2;
}
PrintAndLogEx(SUCCESS, "Issuer PK recovered. RID %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx CSN %02hhx:%02hhx:%02hhx\n",
@@ -745,7 +745,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
if (!icc_pk) {
emv_pk_free(pk);
emv_pk_free(issuer_pk);
PrintAndLogEx(WARNING, "Error: ICC certificate not found. Exit.");
PrintAndLogEx(ERR, "Error: ICC certificate not found. Exit.");
return 2;
}
PrintAndLogEx(SUCCESS, "ICC PK recovered. RID %02hhx:%02hhx:%02hhx:%02hhx:%02hhx IDX %02hhx CSN %02hhx:%02hhx:%02hhx\n",
@@ -790,7 +790,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
const struct tlvdb *atc_db = emv_pki_recover_atc_ex(icc_pk, tlv, true);
if (!atc_db) {
PrintAndLogEx(WARNING, "Error: Can't recover IDN (ICC Dynamic Number)");
PrintAndLogEx(ERR, "Error: Can't recover IDN (ICC Dynamic Number)");
emv_pk_free(pk);
emv_pk_free(issuer_pk);
emv_pk_free(icc_pk);
@@ -823,7 +823,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
PrintAndLogEx(NORMAL, "SDAD verified OK. (Data Authentication Code: %02hhx:%02hhx)\n", dac_tlv->value[0], dac_tlv->value[1]);
tlvdb_add(tlv, dac_db);
} else {
PrintAndLogEx(WARNING, "Error: SSAD verify error");
PrintAndLogEx(ERR, "Error: SSAD verify error");
emv_pk_free(pk);
emv_pk_free(issuer_pk);
emv_pk_free(icc_pk);
@@ -839,7 +839,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
struct tlv *ddol_data_tlv = dol_process(ddol_tlv, tlv, 0);
if (!ddol_data_tlv) {
PrintAndLogEx(WARNING, "Error: Can't create DDOL TLV");
PrintAndLogEx(ERR, "Error: Can't create DDOL TLV");
emv_pk_free(pk);
emv_pk_free(issuer_pk);
emv_pk_free(icc_pk);
@@ -851,7 +851,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
PrintAndLogEx(NORMAL, "\n* Internal Authenticate");
int res = EMVInternalAuthenticate(channel, true, (uint8_t *)ddol_data_tlv->value, ddol_data_tlv->len, buf, sizeof(buf), &len, &sw, NULL);
if (res) {
PrintAndLogEx(WARNING, "Internal Authenticate error(%d): %4x. Exit...", res, sw);
PrintAndLogEx(ERR, "Internal Authenticate error(%d): %4x. Exit...", res, sw);
free(ddol_data_tlv);
emv_pk_free(pk);
emv_pk_free(issuer_pk);
@@ -862,7 +862,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
struct tlvdb *dda_db = NULL;
if (buf[0] == 0x80) {
if (len < 3) {
PrintAndLogEx(WARNING, "Error: Internal Authenticate format1 parsing error. length=%d", len);
PrintAndLogEx(WARNING, "Warning: Internal Authenticate format1 parsing error. length=%d", len);
} else {
// parse response 0x80
struct tlvdb *t80 = tlvdb_parse_multi(buf, len);
@@ -882,7 +882,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
} else {
dda_db = tlvdb_parse_multi(buf, len);
if (!dda_db) {
PrintAndLogEx(WARNING, "Error: Can't parse Internal Authenticate result as TLV");
PrintAndLogEx(ERR, "Error: Can't parse Internal Authenticate result as TLV");
free(ddol_data_tlv);
emv_pk_free(pk);
emv_pk_free(issuer_pk);
@@ -898,7 +898,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
struct tlvdb *idn_db = emv_pki_recover_idn_ex(icc_pk, dda_db, ddol_data_tlv, true);
free(ddol_data_tlv);
if (!idn_db) {
PrintAndLogEx(WARNING, "Error: Can't recover IDN (ICC Dynamic Number)");
PrintAndLogEx(ERR, "Error: Can't recover IDN (ICC Dynamic Number)");
tlvdb_free(dda_db);
emv_pk_free(pk);
emv_pk_free(issuer_pk);
@@ -935,20 +935,20 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st
struct emv_pk *pk = get_ca_pk(tlv);
if (!pk) {
PrintAndLogEx(WARNING, "Error: Key not found. Exit.");
PrintAndLogEx(ERR, "Error: Key not found. Exit.");
return 2;
}
const struct tlv *sda_tlv = tlvdb_get(tlv, 0x21, NULL);
if (!sda_tlv || sda_tlv->len < 1) {
PrintAndLogEx(WARNING, "Error: Can't find input list for Offline Data Authentication. Exit.");
PrintAndLogEx(ERR, "Error: Can't find input list for Offline Data Authentication. Exit.");
emv_pk_free(pk);
return 3;
}
struct emv_pk *issuer_pk = emv_pki_recover_issuer_cert(pk, tlv);
if (!issuer_pk) {
PrintAndLogEx(WARNING, "Error: Issuer certificate not found. Exit.");
PrintAndLogEx(ERR, "Error: Issuer certificate not found. Exit.");
emv_pk_free(pk);
return 2;
}
@@ -966,7 +966,7 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st
struct emv_pk *icc_pk = emv_pki_recover_icc_cert(issuer_pk, tlv, sda_tlv);
if (!icc_pk) {
PrintAndLogEx(WARNING, "Error: ICC certificate not found. Exit.");
PrintAndLogEx(ERR, "Error: ICC certificate not found. Exit.");
emv_pk_free(pk);
emv_pk_free(issuer_pk);
return 2;
@@ -989,7 +989,7 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st
PrintAndLogEx(NORMAL, "SSAD verified OK. (%02hhx:%02hhx)", dac_tlv->value[0], dac_tlv->value[1]);
tlvdb_add(tlv, dac_db);
} else {
PrintAndLogEx(WARNING, "Error: SSAD verify error");
PrintAndLogEx(ERR, "Error: SSAD verify error");
emv_pk_free(pk);
emv_pk_free(issuer_pk);
emv_pk_free(icc_pk);