PDOL parsing for GET PROCESSING OPTIONS command in transaction EMV

I am trying to create a properly formatted GET PROCESSING OPTIONS command to send to an EMV proximity card. This post was very helpful, but I just need to know a little more.

When analyzing PDOL, is it possible to assume that each tag has a length of 2 bytes, followed by the size of the data expected to wait?

For example, PDOL 9F66049F02069F37049F1A02 split into 9F66 04 , 9F02 06 , etc., each of which has 2 byte tags and 1 byte for the expected length of the data value.

Can we assume that there are 2 bytes when parsing each tag?

+5
source share
1 answer

No, you cannot expect that each tag consists of two bytes (although most tags). Tag-Length-Value (TLV) structures in EMV follow ASN.1 encoding rules (Basic Encoding Rules, BER). For more information, see the following documents:

The latter is a really good introduction that helped me get started.

The structure of a TLV (data object) consists of a tag value, a length value, and a data payload (value):

  + ----------- + ----------- + ----------- +
 |  Tag |  Length |  Value |
 |  (N Bytes) |  (M Bytes) |  (L bytes) |
 + ----------- + ----------- + ----------- +

PDOL (and any other list of data objects, DOL) contains a tag and part of the length of one or more such data objects. Similarly, PDOL-related data contains values โ€‹โ€‹of the DOs parts referenced by PDOL. Both tags and length can consist of one or more bytes.

For part of the tag, the rules are something like this (for more details, see the links above):

  • If the lower 5 bits of the first byte of the tag are unique ( tag[0] & 0x01F == 0x01F ), then the tag consists of at least two bytes.
  • If the upper bit of the next byte of the tag is one ( tag[i] & 0x080 == 0x080 ), then the tag consists of one more byte. This is repeated for each subsequent byte.

For part of the length, the rules are approximately as follows (for more details, see the links above):

  • If the upper bit of the first byte of length is zero ( length[0] & 0x080 == 0 ), the remaining seven bits encode the length value ( length[0] & 0x07F ).
  • If the top bit of the first byte of length is one ( length[0] & 0x080 == 0x080 ), the remaining seven bits encode the number of remaining bytes of length ( length[0] & 0x07F ). The remaining bytes represent the length value as an unsigned integer with the MSB.
+6
source

Source: https://habr.com/ru/post/1239451/


All Articles