Fix PDOL parsing

This commit is contained in:
Nikita Vostokov 2024-02-08 23:30:38 +00:00
parent ec356626fa
commit d195de502e
2 changed files with 19 additions and 23 deletions

View File

@ -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);
@ -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");
}

View File

@ -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
@ -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;
}