阅读BERTLV时,你什么时候停止?

时间:2017-01-25 19:10:48

标签: asn.1 tlv ber

我有以下BERTLV: 61394F0BA00000030800001001234579074F05A000012345500E49442D4F6E65205049562042494F5F50107777772E6F626572746875722E636F6D7F66080202800002028000

我试图以递归的方式解析它,所以我将第一部分视为TLV。

代码:0x61,Len:0x39,价值:4F0BA00000030800001001234579074F05A000012345500E49442D4F6E65205049562042494F5F50107777772E6F626572746875722E636F6D

然后我进一步分解,然后

标记:0x4F,Len:0x0B,值: A000000308000010012345

现在,我该怎么办?此时,我知道此值是此TLV的最后一段,并不是另一个嵌套的TLV。

2 个答案:

答案 0 :(得分:3)

好好经过多次挖掘,我发现简单的TAG实际上不仅仅是一个数字,TAG本身实际上编码了那里的信息早午餐。我想知道TLV是否包含嵌套TLV以便我的代码知道何时继续处理以及何时停止,我必须解码TAG

因此TAG包含8位,并且每一位都有特殊含义:

TLV TAG and their bits meaning

我需要的位是B5,以确定当前TLV是否为Constructed ...何时Constructed表示当前TLV 1}}由多个TLV组成,因此对于我的代码,我使用此信息以递归方式挖掘嵌套的TLV

TLV Constructed时,这是我要停止冒泡的情况。

这是我的递归函数输出,通过解析数据并检查B5中的位TAG

11:20:38.428 Parsing: 61394F0BA00000030800001000010079074F05A000000308500E49442D4F6E65205049562042494F5F50107777772E6F626572746875722E636F6D7F66080202800002028000
11:20:38.436 Constructed Data Object
11:20:38.437 Parsing: 4F0BA00000030800001000010079074F05A000000308500E49442D4F6E65205049562042494F5F50107777772E6F626572746875722E636F6D
11:20:38.437 Primitive Data Object
11:20:38.437 tag: 79, len: 11, value: A000000308000010000100
11:20:38.437 Constructed Data Object
11:20:38.437 Parsing: 4F05A000000308
11:20:38.437 Primitive Data Object
11:20:38.437 tag: 79, len: 5, value: A000000308
11:20:38.437 Primitive Data Object
11:20:38.437 tag: 80, len: 14, value: 49442D4F6E65205049562042494F
11:20:38.437 MultiByte tag
11:20:38.437 Primitive Data Object
11:20:38.437 tag: 24400, len: 16, value: 7777772E6F626572746875722E636F6D
11:20:38.438 MultiByte tag
11:20:38.438 Constructed Data Object
11:20:38.438 Parsing: 0202800002028000
11:20:38.438 Primitive Data Object
11:20:38.438 tag: 2, len: 2, value: 8000
11:20:38.438 Primitive Data Object
11:20:38.438 tag: 2, len: 2, value: 8000

答案 1 :(得分:1)

问:现在,我该怎么办?

A:标签长度(0x0B)以十六进制表示,并显示值中的字节数。每个字节在您的示例中表示为2(两)个十六进制字符。因此,十进制11的0x0B表示要使用的值为11 * 2 = 22个字符。

这是解析由https://iso8583.info/lib/EMV/TLVs工具解析的BER-TLV缓冲区的示例:

---
# Cheef's parser.
# Copyright (C) 2008-2017 Alexander Shevelev. https://iso8583.info/
# lib   : "/lib/EMV/" - Integrated Circuit Card Specifications for Payment Systems
# tool  : "TLVs"
# stat  : 40 nodes, 4 lookup tables, 25.00% passed (1/4)

TLVs:#"61394F0BA00000030800001001234579074F05A000012345500E49442D4F..8000" # EMV, Tag + Length + Value (TLV) series
- x61:#"61394F0BA00000030800001001234579074F05A000012345500E49442D4F..6F6D" # ISO 7816, Template, Application
  - tag: "61"
  - len: "39" #  // 57
  - val:#"4F0BA00000030800001001234579074F05A000012345500E49442D4F6E65..6F6D" # Template, Application.
    - x4F:#"4F0BA000000308000010012345" # ISO 7816, Application Identifier (AID), Card
      - tag: "4F"
      - len: "0B" #  // 11
      - val:#"A000000308000010012345" # AID, Card.
        - RID: "A000000308" # Registered Application Provider Identifier (RID) // National Institute of Standards and Technology
        - PIX: "000010012345" # Proprietary Application Identifier Extension (PIX)
    - x79:#"79074F05A000012345" # ISO 7816, Coexistent Tag Allocation Authority
      - tag: "79"
      - len: "07" #  // 7
      - val:#"4F05A000012345"
        - x4F:#"4F05A000012345" # ISO 7816, Application Identifier (AID), Card
          - tag: "4F"
          - len: "05" #  // 5
          - val:#"A000012345" # AID, Card.
            - RID: "A000012345" # Registered Application Provider Identifier (RID)
    - x50:#"500E49442D4F6E65205049562042494F" # ISO 7816, Application Label
      - tag: "50"
      - len: "0E" #  // 14
      - val: "49442D4F6E65205049562042494F" # Application Label. // ID-One PIV BIO
    - x5F50:#"5F50107777772E6F626572746875722E636F6D" # ISO 7816, Uniform resource locator (URL)
      - tag: "5F50"
      - len: "10" #  // 16
      - val: "7777772E6F626572746875722E636F6D" # URL. // www.oberthur.com
- x7F66:#"7F66080202800002028000"
  - tag: "7F66"
  - len: "08" #  // 8
  - val:#"0202800002028000"
    - x02:#"02028000"
      - tag: "02"
      - len: "02" #  // 2
      - val: "8000"
    - x02:#"02028000"
      - tag: "02"
      - len: "02" #  // 2
      - val: "8000"