解析PDOL以获取EMV事务中的GET PROCESSING OPTIONS命令 [英] Parsing PDOL for GET PROCESSING OPTIONS command in EMV transaction

查看:284
本文介绍了解析PDOL以获取EMV事务中的GET PROCESSING OPTIONS命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建正确格式的GET PROCESSING OPTIONS命令以发送到非接触式EMV卡。 这篇文章很有帮助,但我只想知道更多细节。



在解析PDOL时,可以安全地假设每个标签的长度为2个字节,然后是返回的预期数据大小吗?



例如,将PDOL 9F66049F02069F37049F1A02 分为
9F66 04 9F02 06 等,每个都有2个字节的标签和1个字节的数据值的预期长度。



可以安全地假定每个标签解析时长度为2个字节?

解决方案

不,您不能期望每个标签都包含两个字节(尽管大多数标签都可以)。 EMV中的标记长度值(TLV)结构遵循ASN.1编码规则(基本编码规则,BER)。有关更多信息,请参阅以下文档:







TLV结构(数据对象)由标签值,长度值和数据有效载荷组成(值):

 
+ ----------- + ---------- + ----------- +
|标签长度价值|
| (N字节)| (M字节)| (L个字节)|
+ ----------- + ----------- + ----------- +

PDOL(以及任何其他数据对象列表,DOL)包含一个或多个此类数据对象的标记和长度部分。同样,PDOL相关数据包含PDOL中引用的DO的值部分。标签和长度部分都可以包含一个或多个字节。



对于标签部分,规则是这样的(有关更多详细信息,请参见上述参考资料) ):




  • 如果第一个标记字节的低5位全为( tag [0]& 0x01F == 0x01F ),则标记至少由两个字节组成。

  • 如果下一个标记字节的高位为1( tag [i]& 0x080 == 0x080 ),则该标签又包含一个字节。对于随后的每个字节重复此操作。



对于长度部分,规则是这样的(有关更多详细信息,请参见上述参考资料) ):




  • 如果第一个长度字节的高位为零( length [0]& 0x080 = = 0 ),则剩余的7位对长度值进行编码( length [0]& 0x07F )。

  • 如果第一个长度字节的高位为1( length [0]& 0x080 == 0x080 ),则其余的7位将对长度部分的剩余字节( length [0]& 0x07F )。其余字节将长度值表示为无符号整数,其中MSB优先。


I am trying to build a correctly formatted GET PROCESSING OPTIONS command to be sent to a contactless EMV card. This post has been very helpful but I just need to know a little more detail.

When parsing the PDOL, is it safe to assume that each tag is 2 bytes in length, followed by the size of the data expected in return?

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

Is it safe to assume that each tag is 2 bytes in length when parsing?

解决方案

No, you can't expect that each tag consists of two bytes (though most tags do). Tag-Length-Value (TLV) structures in EMV follow ASN.1 encoding rules (basic encoding rules, BER). See the following documents for further information:

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

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

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

The PDOL (and any other data object list, DOL) contains the tag and the length part of one or more such data objects. Similarly, the PDOL related data contains the value parts of the DOs referenced in the PDOL. Both, the tag and the length part can consist of one or more bytes.

For the tag part, the rules are about like this (for more details see the above references):

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

For the length part, the rules are about like this (for more details see the above references):

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

这篇关于解析PDOL以获取EMV事务中的GET PROCESSING OPTIONS命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆