Skip to content

Commit

Permalink
Fix PDOL parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
wosk committed Feb 9, 2024
1 parent ec35662 commit d195de5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
14 changes: 1 addition & 13 deletions applications/main/nfc/helpers/protocol_support/emv/emv_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ void nfc_render_emv_uid(const uint8_t* uid, const uint8_t uid_len, FuriString* s
furi_string_cat_printf(str, "\n");
}

void nfc_render_emv_aid(const uint8_t* uid, const uint8_t uid_len, FuriString* str) {
if(uid_len == 0) return;

furi_string_cat_printf(str, "UID: ");

for(uint8_t i = 0; i < uid_len; i++) {
furi_string_cat_printf(str, "%02X ", uid[i]);
}

furi_string_cat_printf(str, "\n");
}

void nfc_render_emv_data(const EmvData* data, FuriString* str) {
nfc_render_emv_pan(data->emv_application.pan, data->emv_application.pan_len, str);
nfc_render_emv_name(data->emv_application.name, str);
Expand Down Expand Up @@ -83,7 +71,7 @@ void nfc_render_emv_application(const EmvApplication* apl, FuriString* str) {
return;
}

furi_string_cat_printf(str, " AID:");
furi_string_cat_printf(str, "AID: ");
for(uint8_t i = 0; i < len; i++) furi_string_cat_printf(str, "%02X", apl->aid[i]);
furi_string_cat_printf(str, "\n");
}
Expand Down
28 changes: 18 additions & 10 deletions lib/nfc/protocols/emv/emv_poller_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#define TAG "EMVPoller"

// "Terminal" parameters, which could be requested by card
const PDOLValue pdol_term_info = {0x9F59, {0xC8, 0x80, 0x00}}; // Terminal transaction information
const PDOLValue pdol_term_type = {0x9F5A, {0x00}}; // Terminal transaction type
const PDOLValue pdol_merchant_type = {0x9F58, {0x01}}; // Merchant type indicator
Expand Down Expand Up @@ -392,18 +393,25 @@ static void emv_prepare_pdol(APDU* dest, APDU* src) {
uint8_t tlen = 0;
uint8_t i = 0;
while(i < src->size) {
bool tag_found = emv_parse_tag(src->data, src->size, &tag, &tlen, &i);
if(tag_found) {
for(uint8_t j = 0; j < COUNT_OF(pdol_values); j++) {
if(tag == pdol_values[j]->tag) {
memcpy(dest->data + dest->size, pdol_values[j]->data, tlen);
dest->size += tlen;
break;
}
bool tag_found = false;
if(!emv_parse_tag(src->data, src->size, &tag, &tlen, &i)) {
FURI_LOG_T(TAG, "Parsing PDOL failed at 0x%x", i);
dest->size = 0;
return;
}

furi_check(dest->size + tlen < sizeof(dest->data));
for(uint8_t j = 0; j < COUNT_OF(pdol_values); j++) {
if(tag == pdol_values[j]->tag) {
memcpy(dest->data + dest->size, pdol_values[j]->data, tlen);
dest->size += tlen;
tag_found = true;
break;
}
} else {
}

if(!tag_found) {
// Unknown tag, fill zeros
furi_check(dest->size + tlen < sizeof(dest->data));
memset(dest->data + dest->size, 0, tlen);
dest->size += tlen;
}
Expand Down

0 comments on commit d195de5

Please sign in to comment.