EMV Smart Card TLV Format Error?

2.3k views Asked by At

I am developing a smartcard reader for reading EMV cards. I am working on a Mastercard card, and I was trying to read a specific record. The result showed the reading was fine, but when I parse the results, they do not seem to follow the TLV standard, where results come in a Tag/Template-Length-Value format. A sample of the results returned is:

70 - Read Record Response Tag
81 - Should indicate length
e0 - Should be a tag/template...?
8f -Should indicate length of prev. tag...?
01 05 9f 32 ... 90 00

My problem is the first few bytes. The first byte indicates its a READ RECORD template, but the second byte should indicate the length, and the third should be the value, which is the beginning of the next tag. But there is no EMV tag labelled E0, so am I translating the results wrongly or is there something am missing. I have read a previous record using the same command and the results came out just fine:
70 - Tag
27
61 - Another Tag/Template indicator e.t.c.
25 4f 07 ... 90 00
What could I be doing wrong? Or how are these results to be translated?

2

There are 2 answers

0
guidot On BEST ANSWER

The length here is coded in BER format. This means 81 indicates there is one length byte following (only lengths upto 7F can be coded directly in one byte), so E0 is the length and 8F is the tag. For more details cf. ISO 7816-4 (in the 2005 version it is chapter 5.2.2.2 BER-TLV length fields). The final 90 00 is the SW1/SW2 indicates that the read succeeded of course.

0
aussie1984 On

Like guidot says the length component in a TLV isn't always a single byte. Same goes for the tag. You could try pasting your response into http://tvr-decoder.appspot.com/. Select TLV data in the first drop down.

EMV Book 3 has a section devoted to BER-TLV.