mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
remove spurious spaces & tabs at end of lines
This commit is contained in:
parent
edc19f202a
commit
60f292b18e
249 changed files with 8481 additions and 8481 deletions
|
@ -270,10 +270,10 @@ int CodeCmp(const char *code1, const char *code2) {
|
|||
}
|
||||
if (cmp == 4)
|
||||
return 0;
|
||||
|
||||
|
||||
if (cmp + xsymb == 4)
|
||||
return xsymb;
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -282,17 +282,17 @@ const APDUCode* const GetAPDUCode(uint8_t sw1, uint8_t sw2) {
|
|||
int res;
|
||||
int mineq = APDUCodeTableLen;
|
||||
int mineqindx = 0;
|
||||
|
||||
|
||||
sprintf(buf, "%02X%02X", sw1, sw2);
|
||||
|
||||
|
||||
for (int i = 0; i < APDUCodeTableLen; i++) {
|
||||
res = CodeCmp(APDUCodeTable[i].ID, buf);
|
||||
|
||||
|
||||
// equal
|
||||
if (res == 0) {
|
||||
if (res == 0) {
|
||||
return &APDUCodeTable[i];
|
||||
}
|
||||
|
||||
|
||||
// with some 'X'
|
||||
if (res > 0 && mineq > res) {
|
||||
mineq = res;
|
||||
|
@ -304,7 +304,7 @@ const APDUCode* const GetAPDUCode(uint8_t sw1, uint8_t sw2) {
|
|||
if (mineqindx < APDUCodeTableLen) {
|
||||
return &APDUCodeTable[mineqindx];
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ typedef struct {
|
|||
const uint8_t Type;
|
||||
const char *Description;
|
||||
} APDUCode;
|
||||
|
||||
|
||||
extern const APDUCode* const GetAPDUCode(uint8_t sw1, uint8_t sw2);
|
||||
extern const char* GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -29,7 +29,7 @@ static bool crypto_init(void)
|
|||
if (crypto_backend)
|
||||
return true;
|
||||
|
||||
crypto_backend = crypto_polarssl_init();
|
||||
crypto_backend = crypto_polarssl_init();
|
||||
|
||||
if (!crypto_backend)
|
||||
return false;
|
||||
|
|
|
@ -98,11 +98,11 @@ static struct crypto_pk *crypto_pk_polarssl_open_rsa(va_list vl)
|
|||
int explen = va_arg(vl, size_t);
|
||||
|
||||
mbedtls_rsa_init(&cp->ctx, MBEDTLS_RSA_PKCS_V15, 0);
|
||||
|
||||
|
||||
cp->ctx.len = modlen; // size(N) in bytes
|
||||
mbedtls_mpi_read_binary(&cp->ctx.N, (const unsigned char *)mod, modlen);
|
||||
mbedtls_mpi_read_binary(&cp->ctx.E, (const unsigned char *)exp, explen);
|
||||
|
||||
|
||||
int res = mbedtls_rsa_check_pubkey(&cp->ctx);
|
||||
if(res != 0) {
|
||||
fprintf(stderr, "PolarSSL public key error res=%x exp=%d mod=%d.\n", res * -1, explen, modlen);
|
||||
|
@ -133,10 +133,10 @@ static struct crypto_pk *crypto_pk_polarssl_open_priv_rsa(va_list vl)
|
|||
int dqlen = va_arg(vl, size_t);
|
||||
// calc QP via Q and P
|
||||
// char *inv = va_arg(vl, char *);
|
||||
// int invlen = va_arg(vl, size_t);
|
||||
|
||||
// int invlen = va_arg(vl, size_t);
|
||||
|
||||
mbedtls_rsa_init(&cp->ctx, MBEDTLS_RSA_PKCS_V15, 0);
|
||||
|
||||
|
||||
cp->ctx.len = modlen; // size(N) in bytes
|
||||
mbedtls_mpi_read_binary(&cp->ctx.N, (const unsigned char *)mod, modlen);
|
||||
mbedtls_mpi_read_binary(&cp->ctx.E, (const unsigned char *)exp, explen);
|
||||
|
@ -147,7 +147,7 @@ static struct crypto_pk *crypto_pk_polarssl_open_priv_rsa(va_list vl)
|
|||
mbedtls_mpi_read_binary(&cp->ctx.DP, (const unsigned char *)dp, dplen);
|
||||
mbedtls_mpi_read_binary(&cp->ctx.DQ, (const unsigned char *)dq, dqlen);
|
||||
mbedtls_mpi_inv_mod(&cp->ctx.QP, &cp->ctx.Q, &cp->ctx.P);
|
||||
|
||||
|
||||
int res = mbedtls_rsa_check_privkey(&cp->ctx);
|
||||
if(res != 0) {
|
||||
fprintf(stderr, "PolarSSL private key error res=%x exp=%d mod=%d.\n", res * -1, explen, modlen);
|
||||
|
@ -166,7 +166,7 @@ static int myrand(void *rng_state, unsigned char *output, size_t len) {
|
|||
|
||||
for( i = 0; i < len; ++i )
|
||||
output[i] = rand();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -175,21 +175,21 @@ static struct crypto_pk *crypto_pk_polarssl_genkey_rsa(va_list vl)
|
|||
{
|
||||
struct crypto_pk_polarssl *cp = malloc(sizeof(*cp));
|
||||
memset(cp, 0x00, sizeof(*cp));
|
||||
|
||||
|
||||
int transient = va_arg(vl, int);
|
||||
unsigned int nbits = va_arg(vl, unsigned int);
|
||||
unsigned int exp = va_arg(vl, unsigned int);
|
||||
|
||||
if (transient) {
|
||||
}
|
||||
|
||||
|
||||
int res = mbedtls_rsa_gen_key(&cp->ctx, &myrand, NULL, nbits, exp);
|
||||
if (res) {
|
||||
fprintf(stderr, "PolarSSL private key generation error res=%x exp=%d nbits=%d.\n", res * -1, exp, nbits);
|
||||
free(cp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return &cp->cp;
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ static unsigned char *crypto_pk_polarssl_encrypt(const struct crypto_pk *_cp, co
|
|||
struct crypto_pk_polarssl *cp = (struct crypto_pk_polarssl *)_cp;
|
||||
int res;
|
||||
unsigned char *result;
|
||||
|
||||
|
||||
*clen = 0;
|
||||
size_t keylen = mbedtls_mpi_size(&cp->ctx.N);
|
||||
|
||||
|
@ -222,9 +222,9 @@ static unsigned char *crypto_pk_polarssl_encrypt(const struct crypto_pk *_cp, co
|
|||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
*clen = keylen;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ static unsigned char *crypto_pk_polarssl_decrypt(const struct crypto_pk *_cp, co
|
|||
struct crypto_pk_polarssl *cp = (struct crypto_pk_polarssl *)_cp;
|
||||
int res;
|
||||
unsigned char *result;
|
||||
|
||||
|
||||
*clen = 0;
|
||||
size_t keylen = mbedtls_mpi_size(&cp->ctx.N);
|
||||
|
||||
|
@ -249,9 +249,9 @@ static unsigned char *crypto_pk_polarssl_decrypt(const struct crypto_pk *_cp, co
|
|||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
*clen = keylen;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -286,7 +286,7 @@ static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_
|
|||
printf("Error get parameter. Param=%d", param);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -486,7 +486,7 @@ struct emv_pk *emv_pk_get_ca_pk(const unsigned char *rid, unsigned char idx)
|
|||
}
|
||||
*/
|
||||
if (!pk) {
|
||||
const char *relfname = "emv/capk.txt";
|
||||
const char *relfname = "emv/capk.txt";
|
||||
|
||||
char fname[strlen(get_my_executable_directory()) + strlen(relfname) + 1];
|
||||
strcpy(fname, get_my_executable_directory());
|
||||
|
|
|
@ -75,7 +75,7 @@ static unsigned char *emv_pki_decode_message(const struct emv_pk *enc_pk,
|
|||
printf("Recovered data:\n");
|
||||
dump_buffer(data, data_len, stdout, 0);
|
||||
}*/
|
||||
|
||||
|
||||
if (data[data_len-1] != 0xbc || data[0] != 0x6a || data[1] != msgtype) {
|
||||
printf("ERROR: Certificate format\n");
|
||||
free(data);
|
||||
|
@ -117,7 +117,7 @@ static unsigned char *emv_pki_decode_message(const struct emv_pk *enc_pk,
|
|||
printf("ERROR: Calculated wrong hash\n");
|
||||
printf("decoded: %s\n",sprint_hex(data + data_len - 1 - hash_len, hash_len));
|
||||
printf("calculated: %s\n",sprint_hex(hash, hash_len));
|
||||
|
||||
|
||||
if (strictExecution) {
|
||||
crypto_hash_close(ch);
|
||||
free(data);
|
||||
|
@ -206,7 +206,7 @@ static struct emv_pk *emv_pki_decode_key_ex(const struct emv_pk *enc_pk,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (showData){
|
||||
if (showData){
|
||||
printf("Recovered data:\n");
|
||||
dump_buffer(data, data_len, stdout, 0);
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ struct emv_pk *emv_pki_recover_icc_cert(const struct emv_pk *pk, struct tlvdb *d
|
|||
.len = sdatl_len,
|
||||
.value = sdatl
|
||||
};
|
||||
|
||||
|
||||
struct emv_pk *res = emv_pki_decode_key(pk, 4,
|
||||
tlvdb_get(db, 0x5a, NULL),
|
||||
tlvdb_get(db, 0x9f46, NULL),
|
||||
|
@ -316,7 +316,7 @@ struct emv_pk *emv_pki_recover_icc_cert(const struct emv_pk *pk, struct tlvdb *d
|
|||
tlvdb_get(db, 0x9f48, NULL),
|
||||
sda_tlv,
|
||||
&sda_tdata);
|
||||
|
||||
|
||||
free(sdatl); // malloc here: emv_pki_sdatl_fill
|
||||
return res;
|
||||
}
|
||||
|
@ -335,9 +335,9 @@ struct emv_pk *emv_pki_recover_icc_pe_cert(const struct emv_pk *pk, struct tlvdb
|
|||
unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len) {
|
||||
uint8_t buf[2048] = {0};
|
||||
size_t len = 0;
|
||||
|
||||
|
||||
*sdatl_len = 0;
|
||||
|
||||
|
||||
const struct tlv *sda_tl = tlvdb_get(db, 0x9f4a, NULL);
|
||||
if (!sda_tl || sda_tl->len <= 0)
|
||||
return NULL;
|
||||
|
@ -348,16 +348,16 @@ unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len) {
|
|||
if (elm) {
|
||||
memcpy(&buf[len], elm->value, elm->len);
|
||||
len += elm->len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (len) {
|
||||
*sdatl_len = len;
|
||||
unsigned char *value = malloc(len);
|
||||
memcpy(value, buf, len);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ unsigned char *emv_pki_sdatl_fill(const struct tlvdb *db, size_t *sdatl_len) {
|
|||
struct tlvdb *emv_pki_recover_dac_ex(const struct emv_pk *enc_pk, const struct tlvdb *db, const struct tlv *sda_tlv, bool showData)
|
||||
{
|
||||
size_t data_len;
|
||||
|
||||
|
||||
// Static Data Authentication Tag List
|
||||
size_t sdatl_len;
|
||||
unsigned char *sdatl = emv_pki_sdatl_fill(db, &sdatl_len);
|
||||
|
@ -383,7 +383,7 @@ struct tlvdb *emv_pki_recover_dac_ex(const struct emv_pk *enc_pk, const struct t
|
|||
NULL);
|
||||
|
||||
free(sdatl); // malloc here: emv_pki_sdatl_fill
|
||||
|
||||
|
||||
if (!data || data_len < 5)
|
||||
return NULL;
|
||||
|
||||
|
@ -436,7 +436,7 @@ struct tlvdb *emv_pki_recover_idn_ex(const struct emv_pk *enc_pk, const struct t
|
|||
|
||||
// 9f4c ICC Dynamic Number
|
||||
struct tlvdb *idn_db = tlvdb_fixed(0x9f4c, idn_len, data + 5);
|
||||
|
||||
|
||||
free(data);
|
||||
|
||||
return idn_db;
|
||||
|
@ -475,7 +475,7 @@ struct tlvdb *emv_pki_recover_atc_ex(const struct emv_pk *enc_pk, const struct t
|
|||
|
||||
// 9f36 Application Transaction Counter (ATC)
|
||||
struct tlvdb *atc_db = tlvdb_fixed(0x9f36, idn_len, data + 5);
|
||||
|
||||
|
||||
free(data);
|
||||
|
||||
return atc_db;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Copyright (C) 2017-2018 Sectigo Limited
|
||||
* modified 2018 iceman (dropped openssl bignum, now use mbedtls lib)
|
||||
* modified 2018 merlok
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
|
@ -30,10 +30,10 @@ static uint8_t g_primes[ROCA_PRINTS_LENGTH] = {
|
|||
mbedtls_mpi g_prints[ROCA_PRINTS_LENGTH];
|
||||
|
||||
void rocacheck_init(void) {
|
||||
|
||||
|
||||
for (int i = 0; i < ROCA_PRINTS_LENGTH; i++)
|
||||
mbedtls_mpi_init(&g_prints[i]);
|
||||
|
||||
|
||||
mbedtls_mpi_read_string(&g_prints[0], 10, "1026");
|
||||
mbedtls_mpi_read_string(&g_prints[1], 10, "5658");
|
||||
mbedtls_mpi_read_string(&g_prints[2], 10, "107286");
|
||||
|
@ -61,7 +61,7 @@ void rocacheck_cleanup(void) {
|
|||
int bitand_is_zero( mbedtls_mpi* a, mbedtls_mpi* b ) {
|
||||
|
||||
for (int i = 0; i < mbedtls_mpi_bitlen(a); i++) {
|
||||
|
||||
|
||||
if (mbedtls_mpi_get_bit(a, i) && mbedtls_mpi_get_bit(b, i))
|
||||
return 0;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ int bitand_is_zero( mbedtls_mpi* a, mbedtls_mpi* b ) {
|
|||
|
||||
|
||||
mbedtls_mpi_uint mpi_get_uint(const mbedtls_mpi *X) {
|
||||
|
||||
|
||||
if (X->n == 1 && X->s > 0) {
|
||||
return X->p[0];
|
||||
}
|
||||
|
@ -79,12 +79,12 @@ mbedtls_mpi_uint mpi_get_uint(const mbedtls_mpi *X) {
|
|||
}
|
||||
|
||||
void print_mpi(const char *msg, int radix, const mbedtls_mpi *X) {
|
||||
|
||||
|
||||
char Xchar[400] = {0};
|
||||
size_t len = 0;
|
||||
|
||||
mbedtls_mpi_write_string(X, radix, Xchar, sizeof(Xchar), &len);
|
||||
printf("%s[%d] %s\n", msg, len, Xchar);
|
||||
|
||||
mbedtls_mpi_write_string(X, radix, Xchar, sizeof(Xchar), &len);
|
||||
printf("%s[%d] %s\n", msg, len, Xchar);
|
||||
}
|
||||
|
||||
bool emv_rocacheck(const unsigned char *buf, size_t buflen, bool verbose) {
|
||||
|
@ -97,13 +97,13 @@ bool emv_rocacheck(const unsigned char *buf, size_t buflen, bool verbose) {
|
|||
rocacheck_init();
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary(&t_modulus, buf, buflen) );
|
||||
|
||||
|
||||
for (int i = 0; i < ROCA_PRINTS_LENGTH; i++) {
|
||||
|
||||
mbedtls_mpi t_temp;
|
||||
mbedtls_mpi t_prime;
|
||||
mbedtls_mpi g_one;
|
||||
|
||||
|
||||
mbedtls_mpi_init(&t_temp);
|
||||
mbedtls_mpi_init(&t_prime);
|
||||
mbedtls_mpi_init(&g_one);
|
||||
|
@ -111,18 +111,18 @@ bool emv_rocacheck(const unsigned char *buf, size_t buflen, bool verbose) {
|
|||
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string(&g_one, 10, "1") );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_add_int(&t_prime, &t_prime, g_primes[i]) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi(&t_temp, &t_modulus, &t_prime) );
|
||||
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi(&t_temp, &t_modulus, &t_prime) );
|
||||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l(&g_one, mpi_get_uint(&t_temp)) );
|
||||
|
||||
|
||||
if (bitand_is_zero(&g_one, &g_prints[i])) {
|
||||
if (verbose)
|
||||
PrintAndLogEx(FAILED, "No fingerprint found.\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
mbedtls_mpi_free(&g_one);
|
||||
|
||||
mbedtls_mpi_free(&g_one);
|
||||
mbedtls_mpi_free(&t_temp);
|
||||
mbedtls_mpi_free(&t_prime);
|
||||
}
|
||||
|
@ -149,9 +149,9 @@ int roca_self_test(void) {
|
|||
"\x27\x83\x30\xd3\xf4\x71\xa2\x53\x8f\xa6\x67\x80\x2e\xd2\xa3\xc4"\
|
||||
"\x4a\x8b\x7d\xea\x82\x6e\x88\x8d\x0a\xa3\x41\xfd\x66\x4f\x7f\xa7";
|
||||
|
||||
|
||||
|
||||
if (emv_rocacheck(keyp, 64, false)) {
|
||||
PrintAndLogEx(SUCCESS, "Weak modulus [ %s]", _GREEN_(PASS) );
|
||||
PrintAndLogEx(SUCCESS, "Weak modulus [ %s]", _GREEN_(PASS) );
|
||||
}
|
||||
else {
|
||||
ret++;
|
||||
|
@ -168,8 +168,8 @@ int roca_self_test(void) {
|
|||
ret++;
|
||||
PrintAndLogEx(FAILED, "Strong modulus [ %s]", _RED_(FAIL) );
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "Strong modulus [ %s]", _GREEN_(PASS) );
|
||||
PrintAndLogEx(SUCCESS, "Strong modulus [ %s]", _GREEN_(PASS) );
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Copyright (C) 2017-2018 Sectigo Limited
|
||||
* modified 2018 iceman (dropped openssl bignum, now use mbedtls lib)
|
||||
* modified 2018 merlok
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
|
|
|
@ -199,13 +199,13 @@ static const struct emv_tag emv_tags[] = {
|
|||
{ 0x5f2d, "Language Preference", EMV_TAG_STRING },
|
||||
{ 0x5f30, "Service Code", EMV_TAG_NUMERIC },
|
||||
{ 0x5f34, "Application Primary Account Number (PAN) Sequence Number", EMV_TAG_NUMERIC },
|
||||
{ 0x5f36, "Transaction Currency Exponent", EMV_TAG_NUMERIC },
|
||||
{ 0x5f36, "Transaction Currency Exponent", EMV_TAG_NUMERIC },
|
||||
{ 0x5f50, "Issuer URL", EMV_TAG_STRING },
|
||||
{ 0x5f53, "International Bank Account Number (IBAN)" },
|
||||
{ 0x5f54, "Bank Identifier Code (BIC)" },
|
||||
{ 0x5f55, "Issuer Country Code (alpha2 format)", EMV_TAG_STRING },
|
||||
{ 0x5f56, "Issuer Country Code (alpha3 format)", EMV_TAG_STRING },
|
||||
|
||||
|
||||
{ 0x61 , "Application Template" },
|
||||
{ 0x6f , "File Control Information (FCI) Template" },
|
||||
{ 0x70 , "READ RECORD Response Message Template" },
|
||||
|
@ -240,7 +240,7 @@ static const struct emv_tag emv_tags[] = {
|
|||
{ 0x9b , "Transaction Status Information" },
|
||||
{ 0x9c , "Transaction Type", EMV_TAG_NUMERIC },
|
||||
{ 0x9d , "Directory Definition File (DDF) Name" },
|
||||
|
||||
|
||||
{ 0x9f01, "Acquirer Identifier", EMV_TAG_NUMERIC },
|
||||
{ 0x9f02, "Amount, Authorised (Numeric)", EMV_TAG_NUMERIC },
|
||||
{ 0x9f03, "Amount, Other (Numeric)", EMV_TAG_NUMERIC },
|
||||
|
@ -268,10 +268,10 @@ static const struct emv_tag emv_tags[] = {
|
|||
{ 0x9f1b, "Terminal Floor Limit" },
|
||||
{ 0x9f1c, "Terminal Identification", EMV_TAG_STRING },
|
||||
{ 0x9f1d, "Terminal Risk Management Data" },
|
||||
{ 0x9f1e, "Interface Device (IFD) Serial Number", EMV_TAG_STRING },
|
||||
{ 0x9f1e, "Interface Device (IFD) Serial Number", EMV_TAG_STRING },
|
||||
{ 0x9f1f, "Track 1 Discretionary Data", EMV_TAG_STRING },
|
||||
{ 0x9f20, "Track 2 Discretionary Data", EMV_TAG_STRING },
|
||||
{ 0x9f21, "Transaction Time" },
|
||||
{ 0x9f21, "Transaction Time" },
|
||||
{ 0x9f22, "Certification Authority Public Key Index - Terminal" },
|
||||
{ 0x9f23, "Upper Consecutive Offline Limit" },
|
||||
{ 0x9f26, "Application Cryptogram" },
|
||||
|
@ -308,20 +308,20 @@ static const struct emv_tag emv_tags[] = {
|
|||
{ 0x9f4d, "Log Entry" },
|
||||
{ 0x9f4e, "Merchant Name and Location", EMV_TAG_STRING },
|
||||
{ 0x9f4f, "Log Format", EMV_TAG_DOL },
|
||||
|
||||
|
||||
{ 0x9f50, "Offline Accumulator Balance" },
|
||||
{ 0x9f51, "Application Currency Code" },
|
||||
{ 0x9f51, "DRDOL" },
|
||||
|
||||
{ 0x9f52, "Application Default Action (ADA)" },
|
||||
{ 0x9f52, "Terminal Compatibility Indicator" },
|
||||
|
||||
|
||||
{ 0x9f53, "Transaction Category Code" },
|
||||
{ 0x9f54, "DS ODS Card" },
|
||||
|
||||
{ 0x9f55, "Mobile Support Indicator" },
|
||||
|
||||
{ 0x9f55, "Mobile Support Indicator" },
|
||||
{ 0x9f55, "Issuer Authentication Flags" },
|
||||
|
||||
|
||||
{ 0x9f56, "Issuer Authentication Indicator" },
|
||||
{ 0x9f57, "Issuer Country Code" },
|
||||
{ 0x9f58, "Consecutive Transaction Counter Limit (CTCL)" },
|
||||
|
@ -332,7 +332,7 @@ static const struct emv_tag emv_tags[] = {
|
|||
{ 0x9f5d, "Application Capabilities Information" },
|
||||
{ 0x9f5e, "Data Storage Identifier" },
|
||||
{ 0x9f5f, "DS Slot Availability" },
|
||||
|
||||
|
||||
{ 0x9f60, "CVC3 (Track1)" },
|
||||
{ 0x9f61, "CVC3 (Track2)" },
|
||||
{ 0x9f62, "PCVC3 (Track1)" },
|
||||
|
@ -421,7 +421,7 @@ static const struct emv_tag emv_tags[] = {
|
|||
{ 0xff8103, "Tags To Write After Gen AC" },
|
||||
{ 0xff8104, "Data To Send" },
|
||||
{ 0xff8105, "Data Record" },
|
||||
{ 0xff8106, "Discretionary Data" },
|
||||
{ 0xff8106, "Discretionary Data" },
|
||||
};
|
||||
|
||||
static int emv_sort_tag(tlv_tag_t tag) {
|
||||
|
@ -554,13 +554,13 @@ static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, F
|
|||
fprintf(f, "\tINVALID!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (tlv->len != tlv->value[0] + 1) {
|
||||
PRINT_INDENT(level);
|
||||
fprintf(f, "\tINVALID length!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (tlv->len >= 2) {
|
||||
// AC1
|
||||
PRINT_INDENT(level);
|
||||
|
@ -587,7 +587,7 @@ static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, F
|
|||
PRINT_INDENT(level);
|
||||
fprintf(f, "\tSuccessfully processed issuer script commands: %x\n", tlv->value[4] >> 4);
|
||||
}
|
||||
|
||||
|
||||
// mask 0F 0F F0 0F
|
||||
uint8_t data[20] = {0};
|
||||
memcpy(data, &tlv->value[1], tlv->len - 1);
|
||||
|
@ -606,7 +606,7 @@ static void emv_tag_dump_cvr(const struct tlv *tlv, const struct emv_tag *tag, F
|
|||
.type = EMV_TAG_BITMASK,
|
||||
.data = EMV_CVR,
|
||||
};
|
||||
|
||||
|
||||
if (data[0] || data[1] || data[2] || data[3])
|
||||
emv_tag_dump_bitmask(&bit_tlv, &bit_tag, f, level);
|
||||
}
|
||||
|
@ -618,7 +618,7 @@ static void emv_tag_dump_cid(const struct tlv *tlv, const struct emv_tag *tag, F
|
|||
fprintf(f, "\tINVALID!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PRINT_INDENT(level);
|
||||
if ((tlv->value[0] & EMVAC_AC_MASK) == EMVAC_AAC) fprintf(f, "\tAC1: AAC (Transaction declined)\n");
|
||||
if ((tlv->value[0] & EMVAC_AC_MASK) == EMVAC_TC) fprintf(f, "\tAC1: TC (Transaction approved)\n");
|
||||
|
@ -757,7 +757,7 @@ static void emv_tag_dump_afl(const struct tlv *tlv, const struct emv_tag *tag, F
|
|||
fprintf(f, "\tINVALID!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < tlv->len / 4; i++) {
|
||||
PRINT_INDENT(level);
|
||||
fprintf(f, "SFI[%02x] start:%02x end:%02x offline:%02x\n", tlv->value[i * 4 + 0] >> 3, tlv->value[i * 4 + 1], tlv->value[i * 4 + 2], tlv->value[i * 4 + 3]);
|
||||
|
@ -819,13 +819,13 @@ bool emv_tag_dump(const struct tlv *tlv, FILE *f, int level) {
|
|||
|
||||
char *emv_get_tag_name(const struct tlv *tlv) {
|
||||
static char *defstr = "";
|
||||
|
||||
if (!tlv)
|
||||
|
||||
if (!tlv)
|
||||
return defstr;
|
||||
|
||||
const struct emv_tag *tag = emv_get_tag(tlv);
|
||||
if (tag)
|
||||
return tag->name;
|
||||
|
||||
|
||||
return defstr;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
// Got from here. Thanks)
|
||||
// https://eftlab.co.uk/index.php/site-map/knowledge-base/211-emv-aid-rid-pix
|
||||
static const char *PSElist [] = {
|
||||
static const char *PSElist [] = {
|
||||
"325041592E5359532E4444463031", // 2PAY.SYS.DDF01 - Visa Proximity Payment System Environment - PPSE
|
||||
"315041592E5359532E4444463031" // 1PAY.SYS.DDF01 - Visa Payment System Environment - PSE
|
||||
};
|
||||
|
@ -32,28 +32,28 @@ typedef struct {
|
|||
const char* aid;
|
||||
} TAIDList;
|
||||
|
||||
static const TAIDList AIDlist [] = {
|
||||
static const TAIDList AIDlist [] = {
|
||||
// Visa International
|
||||
{ CV_VISA, "A00000000305076010"}, // VISA ELO Credit
|
||||
{ CV_VISA, "A0000000031010" }, // VISA Debit/Credit (Classic)
|
||||
{ CV_VISA, "A000000003101001" }, // VISA Credit
|
||||
{ CV_VISA, "A000000003101002" }, // VISA Debit
|
||||
{ CV_VISA, "A00000000305076010"}, // VISA ELO Credit
|
||||
{ CV_VISA, "A0000000031010" }, // VISA Debit/Credit (Classic)
|
||||
{ CV_VISA, "A000000003101001" }, // VISA Credit
|
||||
{ CV_VISA, "A000000003101002" }, // VISA Debit
|
||||
{ CV_VISA, "A0000000032010" }, // VISA Electron
|
||||
{ CV_VISA, "A0000000032020" }, // VISA
|
||||
{ CV_VISA, "A0000000033010" }, // VISA Interlink
|
||||
{ CV_VISA, "A0000000034010" }, // VISA Specific
|
||||
{ CV_VISA, "A0000000035010" }, // VISA Specific
|
||||
{ CV_VISA, "A0000000036010" }, // Domestic Visa Cash Stored Value
|
||||
{ CV_VISA, "A0000000036020" }, // International Visa Cash Stored Value
|
||||
{ CV_VISA, "A0000000038002" }, // VISA Auth, VisaRemAuthen EMV-CAP (DPA)
|
||||
{ CV_VISA, "A0000000038010" }, // VISA Plus
|
||||
{ CV_VISA, "A0000000039010" }, // VISA Loyalty
|
||||
{ CV_VISA, "A000000003999910" }, // VISA Proprietary ATM
|
||||
{ CV_VISA, "A0000000032020" }, // VISA
|
||||
{ CV_VISA, "A0000000033010" }, // VISA Interlink
|
||||
{ CV_VISA, "A0000000034010" }, // VISA Specific
|
||||
{ CV_VISA, "A0000000035010" }, // VISA Specific
|
||||
{ CV_VISA, "A0000000036010" }, // Domestic Visa Cash Stored Value
|
||||
{ CV_VISA, "A0000000036020" }, // International Visa Cash Stored Value
|
||||
{ CV_VISA, "A0000000038002" }, // VISA Auth, VisaRemAuthen EMV-CAP (DPA)
|
||||
{ CV_VISA, "A0000000038010" }, // VISA Plus
|
||||
{ CV_VISA, "A0000000039010" }, // VISA Loyalty
|
||||
{ CV_VISA, "A000000003999910" }, // VISA Proprietary ATM
|
||||
// Visa USA
|
||||
{ CV_VISA, "A000000098" }, // Debit Card
|
||||
{ CV_VISA, "A0000000980848" }, // Debit Card
|
||||
// Mastercard International
|
||||
{ CV_MASTERCARD, "A00000000401" }, // MasterCard PayPass
|
||||
{ CV_MASTERCARD, "A00000000401" }, // MasterCard PayPass
|
||||
{ CV_MASTERCARD, "A0000000041010" }, // MasterCard Credit
|
||||
{ CV_MASTERCARD, "A00000000410101213" }, // MasterCard Credit
|
||||
{ CV_MASTERCARD, "A00000000410101215" }, // MasterCard Credit
|
||||
|
@ -65,7 +65,7 @@ static const TAIDList AIDlist [] = {
|
|||
{ CV_MASTERCARD, "A0000000045010" }, // MasterCard Specific
|
||||
{ CV_MASTERCARD, "A0000000046000" }, // Cirrus
|
||||
{ CV_MASTERCARD, "A0000000048002" }, // SecureCode Auth EMV-CAP
|
||||
{ CV_MASTERCARD, "A0000000049999" }, // MasterCard PayPass
|
||||
{ CV_MASTERCARD, "A0000000049999" }, // MasterCard PayPass
|
||||
// American Express
|
||||
{ CV_AMERICANEXPRESS, "A000000025" },
|
||||
{ CV_AMERICANEXPRESS, "A0000000250000" },
|
||||
|
@ -74,14 +74,14 @@ static const TAIDList AIDlist [] = {
|
|||
{ CV_AMERICANEXPRESS, "A000000025010701" },
|
||||
{ CV_AMERICANEXPRESS, "A000000025010801" },
|
||||
// Groupement des Cartes Bancaires "CB"
|
||||
{ CV_CB, "A0000000421010" }, // Cartes Bancaire EMV Card
|
||||
{ CV_CB, "A0000000422010" },
|
||||
{ CV_CB, "A0000000423010" },
|
||||
{ CV_CB, "A0000000424010" },
|
||||
{ CV_CB, "A0000000425010" },
|
||||
{ CV_CB, "A0000000421010" }, // Cartes Bancaire EMV Card
|
||||
{ CV_CB, "A0000000422010" },
|
||||
{ CV_CB, "A0000000423010" },
|
||||
{ CV_CB, "A0000000424010" },
|
||||
{ CV_CB, "A0000000425010" },
|
||||
// JCB CO., LTD.
|
||||
{ CV_JCB, "A00000006510" }, // JCB
|
||||
{ CV_JCB, "A0000000651010" }, // JCB J Smart Credit
|
||||
{ CV_JCB, "A00000006510" }, // JCB
|
||||
{ CV_JCB, "A0000000651010" }, // JCB J Smart Credit
|
||||
// Other
|
||||
{ CV_OTHER, "A0000001544442" }, // Banricompras Debito - Banrisul - Banco do Estado do Rio Grande do SUL - S.A.
|
||||
{ CV_OTHER, "F0000000030001" }, // BRADESCO
|
||||
|
@ -106,8 +106,8 @@ enum CardPSVendor GetCardPSVendor(uint8_t * AID, size_t AIDlen) {
|
|||
if (strncmp(AIDlist[i].aid, buf, strlen(AIDlist[i].aid)) == 0){
|
||||
return AIDlist[i].vendor;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return CV_NA;
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ bool TLVPrintFromBuffer(uint8_t *data, int datalen) {
|
|||
t = tlvdb_parse_multi(data, datalen);
|
||||
if (t) {
|
||||
PrintAndLogEx(NORMAL, "-------------------- TLV decoded --------------------");
|
||||
|
||||
|
||||
tlvdb_visit(t, print_cb, NULL, 0);
|
||||
tlvdb_free(t);
|
||||
return true;
|
||||
|
@ -136,9 +136,9 @@ bool TLVPrintFromBuffer(uint8_t *data, int datalen) {
|
|||
}
|
||||
|
||||
void TLVPrintFromTLVLev(struct tlvdb *tlv, int level) {
|
||||
if (!tlv)
|
||||
if (!tlv)
|
||||
return;
|
||||
|
||||
|
||||
tlvdb_visit(tlv, print_cb, NULL, level);
|
||||
}
|
||||
|
||||
|
@ -154,18 +154,18 @@ void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv) {
|
|||
struct tlvdb *ttmp = tlvdb_find(tlv, 0x6f);
|
||||
if (!ttmp)
|
||||
PrintAndLogEx(NORMAL, "| none |");
|
||||
|
||||
|
||||
while (ttmp) {
|
||||
const struct tlv *tgAID = tlvdb_get_inchild(ttmp, 0x84, NULL);
|
||||
const struct tlv *tgName = tlvdb_get_inchild(ttmp, 0x50, NULL);
|
||||
const struct tlv *tgPrio = tlvdb_get_inchild(ttmp, 0x87, NULL);
|
||||
if (!tgAID)
|
||||
break;
|
||||
PrintAndLogEx(NORMAL, "|%s| %s |%s|",
|
||||
sprint_hex_inrow_ex(tgAID->value, tgAID->len, 18),
|
||||
(tgPrio) ? sprint_hex(tgPrio->value, 1) : " ",
|
||||
PrintAndLogEx(NORMAL, "|%s| %s |%s|",
|
||||
sprint_hex_inrow_ex(tgAID->value, tgAID->len, 18),
|
||||
(tgPrio) ? sprint_hex(tgPrio->value, 1) : " ",
|
||||
(tgName) ? sprint_ascii_ex(tgName->value, tgName->len, 25) : " ");
|
||||
|
||||
|
||||
ttmp = tlvdb_find_next(ttmp, 0x6f);
|
||||
}
|
||||
|
||||
|
@ -183,19 +183,19 @@ struct tlvdb *GetPANFromTrack2(const struct tlv *track2) {
|
|||
|
||||
for (int i = 0; i < track2->len; ++i, tmp += 2)
|
||||
sprintf(tmp, "%02x", (unsigned int)track2->value[i]);
|
||||
|
||||
|
||||
int posD = strchr(track2Hex, 'd') - track2Hex;
|
||||
if (posD < 1)
|
||||
return NULL;
|
||||
|
||||
|
||||
track2Hex[posD] = 0;
|
||||
if (strlen(track2Hex) % 2) {
|
||||
track2Hex[posD] = 'F';
|
||||
track2Hex[posD + 1] = '\0';
|
||||
}
|
||||
|
||||
|
||||
param_gethex_to_eol(track2Hex, 0, PAN, sizeof(PAN), &PANlen);
|
||||
|
||||
|
||||
return tlvdb_fixed(0x5a, PANlen, PAN);
|
||||
}
|
||||
|
||||
|
@ -206,13 +206,13 @@ struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2) {
|
|||
int dCVVlen = 0;
|
||||
const int PINlen = 5; // must calculated from 9F67 MSD Offset but i have not seen this tag)
|
||||
char *tmp = track2Hex;
|
||||
|
||||
|
||||
if (!track2)
|
||||
return NULL;
|
||||
|
||||
|
||||
for (int i = 0; i < track2->len; ++i, tmp += 2)
|
||||
sprintf(tmp, "%02x", (unsigned int)track2->value[i]);
|
||||
|
||||
|
||||
int posD = strchr(track2Hex, 'd') - track2Hex;
|
||||
if (posD < 1)
|
||||
return NULL;
|
||||
|
@ -226,9 +226,9 @@ struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2) {
|
|||
memcpy(dCVVHex + 9, track2Hex + posD + 1, 4);
|
||||
// service code
|
||||
memcpy(dCVVHex + 13, track2Hex + posD + 5, 3);
|
||||
|
||||
|
||||
param_gethex_to_eol(dCVVHex, 0, dCVV, sizeof(dCVV), &dCVVlen);
|
||||
|
||||
|
||||
return tlvdb_fixed(0x02, dCVVlen, dCVV);
|
||||
}
|
||||
|
||||
|
@ -239,17 +239,17 @@ int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool LeaveField
|
|||
if (sw) *sw = 0;
|
||||
uint16_t isw = 0;
|
||||
int res = 0;
|
||||
|
||||
|
||||
if (ActivateField) {
|
||||
DropFieldEx( channel );
|
||||
msleep(50);
|
||||
}
|
||||
|
||||
|
||||
// COMPUTE APDU
|
||||
memcpy(data, &apdu, 5);
|
||||
if (apdu.data)
|
||||
memcpy(&data[5], apdu.data, apdu.Lc);
|
||||
|
||||
|
||||
if (APDULogging)
|
||||
PrintAndLogEx(SUCCESS, ">>>> %s", sprint_hex(data, (IncludeLe?6:5) + apdu.Lc));
|
||||
|
||||
|
@ -262,24 +262,24 @@ int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool LeaveField
|
|||
}
|
||||
break;
|
||||
case ECC_CONTACT:
|
||||
#ifdef WITH_SMARTCARD
|
||||
#ifdef WITH_SMARTCARD
|
||||
res = ExchangeAPDUSC(data, (IncludeLe?6:5) + apdu.Lc, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen);
|
||||
#else
|
||||
res = 1;
|
||||
#endif
|
||||
#endif
|
||||
if (res) {
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (APDULogging)
|
||||
PrintAndLogEx(SUCCESS, "<<<< %s", sprint_hex(Result, *ResultLen));
|
||||
|
||||
if (*ResultLen < 2) {
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
||||
*ResultLen -= 2;
|
||||
isw = Result[*ResultLen] * 0x0100 + Result[*ResultLen + 1];
|
||||
if (sw)
|
||||
|
@ -301,7 +301,7 @@ int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool LeaveField
|
|||
struct tlvdb *t = tlvdb_parse_multi(Result, *ResultLen);
|
||||
tlvdb_add(tlv, t);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -328,7 +328,7 @@ int EMVSelectPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO
|
|||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// select
|
||||
res = EMVSelect(channel, ActivateField, LeaveFieldON, buf, len, Result, MaxResultLen, ResultLen, sw, NULL);
|
||||
|
||||
|
@ -351,11 +351,11 @@ int EMVSelectWithRetry(EMVCommandChannel channel, bool ActivateField, bool Leave
|
|||
PrintAndLogEx(WARNING, "Exit...");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
retrycnt = 0;
|
||||
PrintAndLogEx(NORMAL, "Retry failed [%s]. Skiped...", sprint_hex_inrow(AID, AIDLen));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (res && res != 5);
|
||||
|
||||
|
@ -379,7 +379,7 @@ int EMVCheckAID(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlvdbel
|
|||
tlvdbelm = tlvdb_find_next(tlvdbelm, 0x61);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (res)
|
||||
break;
|
||||
|
||||
|
@ -411,7 +411,7 @@ int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO
|
|||
PrintAndLogEx(FAILED, "Select PSE error. APDU error: %04x.", sw);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
struct tlvdb *t = NULL;
|
||||
t = tlvdb_parse_multi(data, datalen);
|
||||
if (t) {
|
||||
|
@ -421,18 +421,18 @@ int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO
|
|||
uint8_t sfin = 0;
|
||||
tlv_get_uint8(tlvdb_get_tlv(tsfi), &sfin);
|
||||
PrintAndLogEx(INFO, "* PPSE get SFI: 0x%02x.", sfin);
|
||||
|
||||
|
||||
for (uint8_t ui = 0x01; ui <= 0x10; ui++) {
|
||||
PrintAndLogEx(INFO, "* * Get SFI: 0x%02x. num: 0x%02x", sfin, ui);
|
||||
res = EMVReadRecord(channel, true, sfin, ui, sfidata[ui], APDU_RES_LEN, &sfidatalen[ui], &sw, NULL);
|
||||
|
||||
|
||||
// end of records
|
||||
if (sw == 0x6a83) {
|
||||
sfidatalen[ui] = 0;
|
||||
PrintAndLogEx(INFO, "* * PPSE get SFI. End of records.");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// error catch!
|
||||
if (sw != 0x9000) {
|
||||
sfidatalen[ui] = 0;
|
||||
|
@ -455,7 +455,7 @@ int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO
|
|||
PrintAndLogEx(FAILED, "SFI 0x%02d don't have records.", sfidatalen[ui]);
|
||||
continue;
|
||||
}
|
||||
res = EMVCheckAID(channel, decodeTLV, tsfitmp, tlv);
|
||||
res = EMVCheckAID(channel, decodeTLV, tsfitmp, tlv);
|
||||
fileFound = true;
|
||||
}
|
||||
tlvdb_free(tsfi);
|
||||
|
@ -470,21 +470,21 @@ int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldO
|
|||
res = EMVCheckAID(channel, decodeTLV, ttmp, tlv);
|
||||
fileFound = true;
|
||||
}
|
||||
|
||||
|
||||
if (!fileFound)
|
||||
PrintAndLogEx(FAILED, "PPSE don't have records.");
|
||||
|
||||
tlvdb_free(t);
|
||||
} else {
|
||||
PrintAndLogEx(WARNING, "PPSE ERROR: Can't get TLV from response.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PrintAndLogEx(WARNING, "PPSE ERROR: Can't select PPSE AID. Error: %d", res);
|
||||
}
|
||||
|
||||
|
||||
if(!LeaveFieldON)
|
||||
DropFieldEx( channel );
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,7 @@ int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON,
|
|||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
size_t datalen = 0;
|
||||
uint16_t sw = 0;
|
||||
|
||||
|
||||
int res = 0;
|
||||
int retrycnt = 0;
|
||||
for(int i = 0; i < AIDlistLen; i ++) {
|
||||
|
@ -510,20 +510,20 @@ int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON,
|
|||
PrintAndLogEx(WARNING, "Exit...");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
retrycnt = 0;
|
||||
PrintAndLogEx(FAILED, "Retry failed [%s]. Skipped...", AIDlist[i].aid);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
retrycnt = 0;
|
||||
|
||||
|
||||
if (res)
|
||||
continue;
|
||||
|
||||
|
||||
if (!datalen)
|
||||
continue;
|
||||
|
||||
|
||||
if (decodeTLV) {
|
||||
PrintAndLogEx(SUCCESS, "%s", AIDlist[i].aid);
|
||||
TLVPrintFromBuffer(data, datalen);
|
||||
|
@ -536,25 +536,25 @@ int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON,
|
|||
int EMVSelectApplication(struct tlvdb *tlv, uint8_t *AID, size_t *AIDlen) {
|
||||
// check priority. 0x00 - highest
|
||||
int prio = 0xffff;
|
||||
|
||||
|
||||
*AIDlen = 0;
|
||||
|
||||
struct tlvdb *ttmp = tlvdb_find(tlv, 0x6f);
|
||||
if (!ttmp)
|
||||
return 1;
|
||||
|
||||
|
||||
while (ttmp) {
|
||||
const struct tlv *tgAID = tlvdb_get_inchild(ttmp, 0x84, NULL);
|
||||
const struct tlv *tgPrio = tlvdb_get_inchild(ttmp, 0x87, NULL);
|
||||
|
||||
|
||||
if (!tgAID)
|
||||
break;
|
||||
|
||||
if (tgPrio) {
|
||||
int pt = bytes_to_num((uint8_t*)tgPrio->value, (tgPrio->len < 2) ? tgPrio->len : 2);
|
||||
int pt = bytes_to_num((uint8_t*)tgPrio->value, (tgPrio->len < 2) ? tgPrio->len : 2);
|
||||
if (pt < prio) {
|
||||
prio = pt;
|
||||
|
||||
|
||||
memcpy(AID, tgAID->value, tgAID->len);
|
||||
*AIDlen = tgAID->len;
|
||||
}
|
||||
|
@ -562,13 +562,13 @@ int EMVSelectApplication(struct tlvdb *tlv, uint8_t *AID, size_t *AIDlen) {
|
|||
// takes the first application from list wo priority
|
||||
if (!*AIDlen) {
|
||||
memcpy(AID, tgAID->value, tgAID->len);
|
||||
*AIDlen = tgAID->len;
|
||||
*AIDlen = tgAID->len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ttmp = tlvdb_find_next(ttmp, 0x6f);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -606,7 +606,7 @@ int MSCComputeCryptoChecksum(EMVCommandChannel channel, bool LeaveFieldON, uint8
|
|||
return EMVExchange(channel, LeaveFieldON, (sAPDU){0x80, 0x2a, 0x8e, 0x80, UDOLlen, UDOL}, Result, MaxResultLen, ResultLen, sw, tlv);
|
||||
}
|
||||
|
||||
// Authentication
|
||||
// Authentication
|
||||
struct emv_pk *get_ca_pk(struct tlvdb *db) {
|
||||
const struct tlv *df_tlv = tlvdb_get(db, 0x84, NULL);
|
||||
const struct tlv *caidx_tlv = tlvdb_get(db, 0x8f, NULL);
|
||||
|
@ -625,7 +625,7 @@ int trSDA(struct tlvdb *tlv) {
|
|||
PrintAndLogEx(WARNING, "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);
|
||||
|
@ -652,7 +652,7 @@ int trSDA(struct tlvdb *tlv) {
|
|||
PrintAndLogEx(WARNING, "Can't find input list for Offline Data Authentication. Exit.");
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
||||
struct tlvdb *dac_db = emv_pki_recover_dac(issuer_pk, tlv, sda_tlv);
|
||||
if (dac_db) {
|
||||
const struct tlv *dac_tlv = tlvdb_get(dac_db, 0x9f45, NULL);
|
||||
|
@ -664,7 +664,7 @@ int trSDA(struct tlvdb *tlv) {
|
|||
PrintAndLogEx(WARNING, "SSAD verify error");
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
emv_pk_free(issuer_pk);
|
||||
emv_pk_free(pk);
|
||||
return 0;
|
||||
|
@ -708,7 +708,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
|
|||
issuer_pk->serial[1],
|
||||
issuer_pk->serial[2]
|
||||
);
|
||||
|
||||
|
||||
struct emv_pk *icc_pk = emv_pki_recover_icc_cert(issuer_pk, tlv, sda_tlv);
|
||||
if (!icc_pk) {
|
||||
emv_pk_free(pk);
|
||||
|
@ -769,7 +769,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
|
|||
const struct tlv *atc_tlv = tlvdb_get(atc_db, 0x9f36, NULL);
|
||||
if(atc_tlv) {
|
||||
PrintAndLogEx(NORMAL, "\nATC (Application Transaction Counter) [%zu] %s", atc_tlv->len, sprint_hex_inrow(atc_tlv->value, atc_tlv->len));
|
||||
|
||||
|
||||
const struct tlv *core_atc_tlv = tlvdb_get(tlv, 0x9f36, NULL);
|
||||
if(tlv_equal(core_atc_tlv, atc_tlv)) {
|
||||
PrintAndLogEx(SUCCESS, "ATC check OK.");
|
||||
|
@ -797,7 +797,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
|
|||
emv_pk_free(icc_pk);
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "\n* * Calc DDOL");
|
||||
const struct tlv *ddol_tlv = tlvdb_get(tlv, 0x9f49, NULL);
|
||||
if (!ddol_tlv) {
|
||||
|
@ -818,7 +818,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) {
|
||||
if (res) {
|
||||
PrintAndLogEx(WARNING, "Internal Authenticate error(%d): %4x. Exit...", res, sw);
|
||||
free(ddol_data_tlv);
|
||||
emv_pk_free(pk);
|
||||
|
@ -835,13 +835,13 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
|
|||
// parse response 0x80
|
||||
struct tlvdb *t80 = tlvdb_parse_multi(buf, len);
|
||||
const struct tlv * t80tlv = tlvdb_get_tlv(t80);
|
||||
|
||||
|
||||
// 9f4b Signed Dynamic Application Data
|
||||
dda_db = tlvdb_fixed(0x9f4b, t80tlv->len, t80tlv->value);
|
||||
tlvdb_add(tlv, dda_db);
|
||||
|
||||
|
||||
tlvdb_free(t80);
|
||||
|
||||
|
||||
if (decodeTLV){
|
||||
PrintAndLogEx(NORMAL, "* * * Decode response format 1:");
|
||||
TLVPrintFromTLV(dda_db);
|
||||
|
@ -858,7 +858,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
|
|||
return 7;
|
||||
}
|
||||
tlvdb_add(tlv, dda_db);
|
||||
|
||||
|
||||
if (decodeTLV)
|
||||
TLVPrintFromTLV(dda_db);
|
||||
}
|
||||
|
@ -892,7 +892,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
|
|||
return 9;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
emv_pk_free(pk);
|
||||
emv_pk_free(issuer_pk);
|
||||
emv_pk_free(icc_pk);
|
||||
|
@ -931,7 +931,7 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st
|
|||
issuer_pk->serial[1],
|
||||
issuer_pk->serial[2]
|
||||
);
|
||||
|
||||
|
||||
struct emv_pk *icc_pk = emv_pki_recover_icc_cert(issuer_pk, tlv, sda_tlv);
|
||||
if (!icc_pk) {
|
||||
PrintAndLogEx(WARNING, "Error: ICC setrificate not found. Exit.");
|
||||
|
@ -963,12 +963,12 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st
|
|||
emv_pk_free(icc_pk);
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "\n* * Check Signed Dynamic Application Data (SDAD)");
|
||||
struct tlvdb *idn_db = emv_pki_perform_cda_ex(icc_pk, tlv, ac_tlv,
|
||||
pdol_data_tlv, // pdol
|
||||
ac_data_tlv, // cdol1
|
||||
NULL, // cdol2
|
||||
NULL, // cdol2
|
||||
true);
|
||||
if (idn_db) {
|
||||
const struct tlv *idn_tlv = tlvdb_get(idn_db, 0x9f4c, NULL);
|
||||
|
@ -986,7 +986,7 @@ int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, st
|
|||
}
|
||||
|
||||
int RecoveryCertificates(struct tlvdb *tlvRoot, json_t *root) {
|
||||
|
||||
|
||||
struct emv_pk *pk = get_ca_pk(tlvRoot);
|
||||
if (!pk) {
|
||||
PrintAndLog("ERROR: Key not found. Exit.");
|
||||
|
@ -1036,11 +1036,11 @@ int RecoveryCertificates(struct tlvdb *tlvRoot, json_t *root) {
|
|||
icc_pk->serial[1],
|
||||
icc_pk->serial[2]
|
||||
);
|
||||
|
||||
|
||||
char *icc_pk_c = emv_pk_dump_pk(icc_pk);
|
||||
JsonSaveStr(root, "$.ApplicationData.ICCPublicKeyDec", icc_pk_c);
|
||||
JsonSaveBufAsHex(root, "$.ApplicationData.ICCPublicKeyModulus", icc_pk->modulus, icc_pk->mlen);
|
||||
free(issuer_pk_c);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ char* GetApplicationDataName(tlv_tag_t tag) {
|
|||
for (int i = 0; i < ApplicationDataLen; i++)
|
||||
if (ApplicationData[i].Tag == tag)
|
||||
return ApplicationData[i].Name;
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ int JsonSaveJsonObject(json_t *root, char *path, json_t *value) {
|
|||
|
||||
if (strlen(path) < 1)
|
||||
return 1;
|
||||
|
||||
|
||||
if (path[0] == '$') {
|
||||
if (json_path_set(root, path, value, 0, &error)) {
|
||||
PrintAndLog("ERROR: can't set json path: ", error.text);
|
||||
|
@ -124,9 +124,9 @@ int JsonSaveHex(json_t *elm, char *path, uint64_t data, int datalen) {
|
|||
len = 1;
|
||||
} else {
|
||||
len = datalen;
|
||||
}
|
||||
}
|
||||
num_to_bytes(data, len, bdata);
|
||||
|
||||
|
||||
return JsonSaveBufAsHex(elm, path, bdata, len);
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ int JsonSaveTLVValue(json_t *root, char *path, struct tlvdb *tlvdbelm) {
|
|||
if (tlvelm)
|
||||
return JsonSaveBufAsHex(root, path, (uint8_t *)tlvelm->value, tlvelm->len);
|
||||
else
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, bool saveValue, bool saveAppDataLink) {
|
||||
|
@ -143,13 +143,13 @@ int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, b
|
|||
|
||||
if (strlen(path) < 1 || !tlvelm)
|
||||
return 1;
|
||||
|
||||
|
||||
if (path[0] == '$') {
|
||||
|
||||
json_t *obj = json_path_get(elm, path);
|
||||
if (!obj) {
|
||||
obj = json_object();
|
||||
|
||||
|
||||
if (json_is_array(elm)) {
|
||||
if (json_array_append_new(elm, obj)) {
|
||||
PrintAndLog("ERROR: can't append array: %s", path);
|
||||
|
@ -162,12 +162,12 @@ int JsonSaveTLVElm(json_t *elm, char *path, struct tlv *tlvelm, bool saveName, b
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (saveAppDataLink) {
|
||||
char * AppDataName = GetApplicationDataName(tlvelm->tag);
|
||||
if (AppDataName)
|
||||
JsonSaveStr(obj, "appdata", AppDataName);
|
||||
} else {
|
||||
} else {
|
||||
char * name = emv_get_tag_name(tlvelm);
|
||||
if (saveName && name && strlen(name) > 0 && strncmp(name, "Unknown", 7))
|
||||
JsonSaveStr(obj, "name", emv_get_tag_name(tlvelm));
|
||||
|
@ -193,13 +193,13 @@ int JsonSaveTLVTree(json_t *root, json_t *elm, char *path, struct tlvdb *tlvdbel
|
|||
char * AppDataName = NULL;
|
||||
if (tlvpelm)
|
||||
AppDataName = GetApplicationDataName(tlvpelm->tag);
|
||||
|
||||
|
||||
if (AppDataName) {
|
||||
char appdatalink[200] = {0};
|
||||
sprintf(appdatalink, "$.ApplicationData.%s", AppDataName);
|
||||
JsonSaveBufAsHex(root, appdatalink, (uint8_t *)tlvpelm->value, tlvpelm->len);
|
||||
}
|
||||
|
||||
|
||||
json_t *pelm = json_path_get(elm, path);
|
||||
if (pelm && json_is_array(pelm)) {
|
||||
json_t *appendelm = json_object();
|
||||
|
@ -210,20 +210,20 @@ int JsonSaveTLVTree(json_t *root, json_t *elm, char *path, struct tlvdb *tlvdbel
|
|||
JsonSaveTLVTreeElm(elm, path, tlvp, !AppDataName, !tlvdb_elm_get_children(tlvp), AppDataName);
|
||||
pelm = json_path_get(elm, path);
|
||||
}
|
||||
|
||||
|
||||
if (tlvdb_elm_get_children(tlvp)) {
|
||||
// get path element
|
||||
if(!pelm)
|
||||
return 1;
|
||||
|
||||
|
||||
// check childs element and add it if not found
|
||||
json_t *chjson = json_path_get(pelm, "$.Childs");
|
||||
if (!chjson) {
|
||||
json_object_set_new(pelm, "Childs", json_array());
|
||||
|
||||
|
||||
chjson = json_path_get(pelm, "$.Childs");
|
||||
}
|
||||
|
||||
|
||||
// check
|
||||
if (!json_is_array(chjson)) {
|
||||
PrintAndLog("E->Internal logic error. `$.Childs` is not an array.");
|
||||
|
@ -240,8 +240,8 @@ int JsonSaveTLVTree(json_t *root, json_t *elm, char *path, struct tlvdb *tlvdbel
|
|||
}
|
||||
|
||||
bool HexToBuffer(const char *errormsg, const char *hexvalue, uint8_t * buffer, size_t maxbufferlen, size_t *bufferlen) {
|
||||
int buflen = 0;
|
||||
|
||||
int buflen = 0;
|
||||
|
||||
switch (param_gethex_to_eol(hexvalue, 0, buffer, maxbufferlen, &buflen)) {
|
||||
case 1:
|
||||
PrintAndLog("%s Invalid HEX value.", errormsg);
|
||||
|
@ -253,15 +253,15 @@ bool HexToBuffer(const char *errormsg, const char *hexvalue, uint8_t * buffer, s
|
|||
PrintAndLog("%s Hex value must have even number of digits.", errormsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (buflen > maxbufferlen) {
|
||||
PrintAndLog("%s HEX length (%d) more than %d", errormsg, (bufferlen) ? *bufferlen : -1, maxbufferlen);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ( bufferlen )
|
||||
*bufferlen = buflen;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -272,27 +272,27 @@ int JsonLoadStr(json_t *root, char *path, char *value) {
|
|||
json_t *jelm = json_path_get((const json_t *)root, path);
|
||||
if (!jelm || !json_is_string(jelm))
|
||||
return 2;
|
||||
|
||||
|
||||
const char * strval = json_string_value(jelm);
|
||||
if (!strval)
|
||||
return 1;
|
||||
|
||||
|
||||
memcpy(value, strval, strlen(strval));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JsonLoadBufAsHex(json_t *elm, char *path, uint8_t *data, size_t maxbufferlen, size_t *datalen) {
|
||||
if (datalen)
|
||||
*datalen = 0;
|
||||
|
||||
|
||||
json_t *jelm = json_path_get((const json_t *)elm, path);
|
||||
if (!jelm || !json_is_string(jelm))
|
||||
return 1;
|
||||
|
||||
|
||||
if (!HexToBuffer("ERROR load", json_string_value(jelm), data, maxbufferlen, datalen))
|
||||
return 2;
|
||||
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
@ -302,11 +302,11 @@ bool ParamLoadFromJson(struct tlvdb *tlv) {
|
|||
|
||||
if (!tlv) {
|
||||
PrintAndLog("ERROR load params: tlv tree is NULL.");
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// current path + file name
|
||||
const char *relfname = "emv/defparams.json";
|
||||
const char *relfname = "emv/defparams.json";
|
||||
char fname[strlen(get_my_executable_directory()) + strlen(relfname) + 1];
|
||||
strcpy(fname, get_my_executable_directory());
|
||||
strcat(fname, relfname);
|
||||
|
@ -314,16 +314,16 @@ bool ParamLoadFromJson(struct tlvdb *tlv) {
|
|||
root = json_load_file(fname, 0, &error);
|
||||
if (!root) {
|
||||
PrintAndLog("Load params: json error on line %d: %s", error.line, error.text);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!json_is_array(root)) {
|
||||
PrintAndLog("Load params: Invalid json format. root must be array.");
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
PrintAndLog("Load params: json(%d) OK", json_array_size(root));
|
||||
|
||||
|
||||
for(int i = 0; i < json_array_size(root); i++) {
|
||||
json_t *data, *jtag, *jlength, *jvalue;
|
||||
|
||||
|
@ -334,7 +334,7 @@ bool ParamLoadFromJson(struct tlvdb *tlv) {
|
|||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
jtag = json_object_get(data, "tag");
|
||||
if(!json_is_string(jtag))
|
||||
{
|
||||
|
@ -360,39 +360,39 @@ bool ParamLoadFromJson(struct tlvdb *tlv) {
|
|||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int tlvLength = json_integer_value(jlength);
|
||||
if (tlvLength > 250) {
|
||||
PrintAndLog("Load params: data [%d] length more than 250", i + 1);
|
||||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
PrintAndLog("TLV param: %s[%d]=%s", tlvTag, tlvLength, tlvValue);
|
||||
uint8_t buf[251] = {0};
|
||||
size_t buflen = 0;
|
||||
|
||||
if (!HexToBuffer("TLV Error type:", tlvTag, buf, 4, &buflen)) {
|
||||
|
||||
if (!HexToBuffer("TLV Error type:", tlvTag, buf, 4, &buflen)) {
|
||||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
tlv_tag_t tag = 0;
|
||||
for (int i = 0; i < buflen; i++) {
|
||||
tag = (tag << 8) | buf[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!HexToBuffer("TLV Error value:", tlvValue, buf, sizeof(buf) - 1, &buflen)) {
|
||||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (buflen != tlvLength) {
|
||||
PrintAndLog("Load params: data [%d] length of HEX must(%d) be identical to length in TLV param(%d)", i + 1, buflen, tlvLength);
|
||||
json_decref(root);
|
||||
return false;
|
||||
}
|
||||
|
||||
tlvdb_change_or_add_node(tlv, tag, tlvLength, (const unsigned char *)buf);
|
||||
|
||||
tlvdb_change_or_add_node(tlv, tag, tlvLength, (const unsigned char *)buf);
|
||||
}
|
||||
|
||||
json_decref(root);
|
||||
|
|
|
@ -423,7 +423,7 @@ int exec_cda_test(bool verbose)
|
|||
{
|
||||
int ret;
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
|
||||
ret = cda_test_raw(verbose);
|
||||
if (ret) {
|
||||
fprintf(stderr, "CDA raw test: failed\n");
|
||||
|
|
|
@ -13,6 +13,6 @@
|
|||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
extern int exec_cda_test(bool verbose);
|
||||
|
|
|
@ -36,25 +36,25 @@
|
|||
int ExecuteCryptoTests(bool verbose) {
|
||||
int res;
|
||||
bool TestFail = false;
|
||||
|
||||
|
||||
res = mbedtls_mpi_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
||||
res = mbedtls_aes_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
res = mbedtls_des_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
||||
res = mbedtls_sha1_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
res = mbedtls_md5_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
||||
res = mbedtls_rsa_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
||||
res = mbedtls_entropy_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
@ -63,7 +63,7 @@ int ExecuteCryptoTests(bool verbose) {
|
|||
|
||||
res = mbedtls_ctr_drbg_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
||||
res = mbedtls_base64_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
@ -78,13 +78,13 @@ int ExecuteCryptoTests(bool verbose) {
|
|||
|
||||
res = mbedtls_x509_self_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
||||
res = exec_sda_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
res = exec_dda_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
||||
res = exec_cda_test(verbose);
|
||||
if (res) TestFail = true;
|
||||
|
||||
|
@ -95,12 +95,12 @@ int ExecuteCryptoTests(bool verbose) {
|
|||
if (res) TestFail = true;
|
||||
|
||||
PrintAndLog("\n--------------------------");
|
||||
|
||||
|
||||
if (TestFail)
|
||||
PrintAndLogEx(FAILED, "\tTest(s) [ %s ]", _RED_(FAIL) );
|
||||
else
|
||||
PrintAndLogEx(SUCCESS, "\tTest(s) [ %s ]", _GREEN_(OK) );
|
||||
|
||||
|
||||
return TestFail;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,6 @@
|
|||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
extern int exec_dda_test(bool verbose);
|
||||
|
|
|
@ -12,5 +12,5 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
extern int exec_sda_test(bool verbose);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* https://github.com/lumag/emv-tools/blob/master/lib/tlv.c
|
||||
*/
|
||||
|
||||
|
@ -37,8 +37,8 @@
|
|||
#define TLV_LEN_INVALID (~0)
|
||||
|
||||
// http://radek.io/2012/11/10/magical-container_of-macro/
|
||||
//#define container_of(ptr, type, member) ({
|
||||
// const typeof( ((type *)0)->member ) *__mptr = (ptr);
|
||||
//#define container_of(ptr, type, member) ({
|
||||
// const typeof( ((type *)0)->member ) *__mptr = (ptr);
|
||||
// (type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
|
||||
struct tlvdb {
|
||||
|
@ -301,14 +301,14 @@ void tlvdb_free(struct tlvdb *tlvdb)
|
|||
struct tlvdb *tlvdb_find_next(struct tlvdb *tlvdb, tlv_tag_t tag) {
|
||||
if (!tlvdb)
|
||||
return NULL;
|
||||
|
||||
|
||||
return tlvdb_find(tlvdb->next, tag);
|
||||
}
|
||||
|
||||
struct tlvdb *tlvdb_find(struct tlvdb *tlvdb, tlv_tag_t tag) {
|
||||
if (!tlvdb)
|
||||
return NULL;
|
||||
|
||||
|
||||
for (; tlvdb; tlvdb = tlvdb->next) {
|
||||
if (tlvdb->tag.tag == tag)
|
||||
return tlvdb;
|
||||
|
@ -320,16 +320,16 @@ struct tlvdb *tlvdb_find(struct tlvdb *tlvdb, tlv_tag_t tag) {
|
|||
struct tlvdb *tlvdb_find_full(struct tlvdb *tlvdb, tlv_tag_t tag) {
|
||||
if (!tlvdb)
|
||||
return NULL;
|
||||
|
||||
|
||||
for (; tlvdb; tlvdb = tlvdb->next) {
|
||||
if (tlvdb->tag.tag == tag)
|
||||
return tlvdb;
|
||||
|
||||
|
||||
if (tlvdb->children) {
|
||||
struct tlvdb * ch = tlvdb_find_full(tlvdb->children, tag);
|
||||
if (ch)
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -338,7 +338,7 @@ struct tlvdb *tlvdb_find_full(struct tlvdb *tlvdb, tlv_tag_t tag) {
|
|||
struct tlvdb *tlvdb_find_path(struct tlvdb *tlvdb, tlv_tag_t tag[]) {
|
||||
int i = 0;
|
||||
struct tlvdb *tnext = tlvdb;
|
||||
|
||||
|
||||
while (tnext && tag[i]) {
|
||||
tnext = tlvdb_find(tnext, tag[i]);
|
||||
i++;
|
||||
|
@ -346,7 +346,7 @@ struct tlvdb *tlvdb_find_path(struct tlvdb *tlvdb, tlv_tag_t tag[]) {
|
|||
tnext = tnext->children;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return tnext;
|
||||
}
|
||||
|
||||
|
@ -354,11 +354,11 @@ void tlvdb_add(struct tlvdb *tlvdb, struct tlvdb *other)
|
|||
{
|
||||
if (tlvdb == other)
|
||||
return;
|
||||
|
||||
|
||||
while (tlvdb->next) {
|
||||
if (tlvdb->next == other)
|
||||
return;
|
||||
|
||||
|
||||
tlvdb = tlvdb->next;
|
||||
}
|
||||
|
||||
|
@ -383,20 +383,20 @@ void tlvdb_change_or_add_node_ex(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len,
|
|||
struct tlvdb *tnewelm = tlvdb_fixed(tag, len, value);
|
||||
tnewelm->next = telm->next;
|
||||
tnewelm->parent = telm->parent;
|
||||
|
||||
|
||||
// if telm stayed first in children chain
|
||||
if (telm->parent && telm->parent->children == telm) {
|
||||
telm->parent->children = tnewelm;
|
||||
}
|
||||
|
||||
|
||||
// if telm have previous element
|
||||
if (telm != tlvdb) {
|
||||
// elm in root
|
||||
struct tlvdb *celm = tlvdb;
|
||||
// elm in child list of node
|
||||
if (telm->parent && telm->parent->children)
|
||||
celm = telm->parent->children;
|
||||
|
||||
celm = telm->parent->children;
|
||||
|
||||
// find previous element
|
||||
for (; celm; celm = celm->next) {
|
||||
if (celm->next == telm) {
|
||||
|
@ -405,15 +405,15 @@ void tlvdb_change_or_add_node_ex(struct tlvdb *tlvdb, tlv_tag_t tag, size_t len,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// free old element with childrens
|
||||
telm->next = NULL;
|
||||
tlvdb_free(telm);
|
||||
|
||||
|
||||
if (tlvdb_elm)
|
||||
*tlvdb_elm = tnewelm;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -557,18 +557,18 @@ struct tlvdb *tlvdb_elm_get_parent(struct tlvdb *tlvdb)
|
|||
|
||||
bool tlvdb_get_uint8(struct tlvdb *tlvRoot, tlv_tag_t tag, uint8_t *value)
|
||||
{
|
||||
const struct tlv *tlvelm = tlvdb_get(tlvRoot, tag, NULL);
|
||||
const struct tlv *tlvelm = tlvdb_get(tlvRoot, tag, NULL);
|
||||
return tlv_get_uint8(tlvelm, value);
|
||||
}
|
||||
|
||||
bool tlv_get_uint8(const struct tlv *etlv, uint8_t *value)
|
||||
bool tlv_get_uint8(const struct tlv *etlv, uint8_t *value)
|
||||
{
|
||||
*value = 0;
|
||||
if (etlv)
|
||||
{
|
||||
if (etlv->len == 0)
|
||||
return true;
|
||||
|
||||
|
||||
if (etlv->len == 1)
|
||||
{
|
||||
*value = etlv->value[0];
|
||||
|
@ -585,7 +585,7 @@ bool tlv_get_int(const struct tlv *etlv, int *value)
|
|||
{
|
||||
if (etlv->len == 0)
|
||||
return true;
|
||||
|
||||
|
||||
if (etlv->len <= 4)
|
||||
{
|
||||
for (int i = 0; i < etlv->len; i++)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* https://github.com/lumag/emv-tools/blob/master/lib/include/openemv/tlv.h
|
||||
*/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue