EMV 事务日志结果不是预期的

EMV transaction log result is not expected

我阅读了交易日志以计算终端风险管理中的下限。我成功读取了EMV卡交易日志,长度为10行,但为什么EMV-tags使用 TLV Parser?

解析时无法识别该结果的一部分

EMV 标签:TLV 解析器无法识别 4092?

1.Log格式

REQ LOG_FORMAT: 80CA9F4F00

RES LOG_FORMAT: 9F4F289F27019F26088A029F02069F03069F1A0295055F2A029A039C019F370482029F36029F10209F6B30 9000

LogFormat is success

2.Log条目

After select AID, I get log entry as follows 0B 0A

3.Transaction日志

REQ TRANS_LOG: 00B2015C00

RES TRANS_LOG: 4092AFED093EB371AC3030000030000000000000000000036080800480000360190519017B3B91CF7400000D01016100000000516D54FA000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 9000

//More transaction log in here

Transaction Log is success

事务日志代码:

private List<IApdu.IApduResp> readTransactionLog(byte[] logEntry) {
    try {
        if (logEntry.length != 2) {
            return null;
        }
        List<IApdu.IApduResp> apduRespList = new ArrayList<>();
        int sfi = logEntry[0] & 0xFF;  // 11
        int rows = logEntry[1] & 0xFF; // 10 rows
        int successCount = 0;
        for (int row = 1; row <= rows; row++) {
            IApdu.IApduReq req = APDU.createReq((byte) 0x00, (byte) 0xB2, (byte) row, (byte) ((sfi << 3) | 0x04));
            if (req == null) {
                break;
            }
            Log.i(TAG, "REQ TRANS_LOG: " + row + " " + sfi + " : " + bcdToStr(req.pack()));
            byte[] cmd = isoCommand(req.pack());
            if (cmd == null) {
                return null;
            }
            IApdu.IApduResp unpack = APDU.unpack(cmd);
            if (unpack == null) {
                return null;
            }
            Log.i(TAG, "RES TRANS_LOG: " + bcdToStr(unpack.getData()) + " " + unpack.getStatusString());
            if (unpack.getStatusString().equals("9000")) {
                ++successCount;
                apduRespList.add(unpack);
            } else if (unpack.getStatusString().equals("6A83")) {
                break;
            }
        }
        if (successCount > 0) {
            transLogResponse.setApduResponse(apduRespList);
            return apduRespList;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

RES TRANS_LOG 不是 TLV 编码。它仅包含值字段。您必须根据您在具有标记和长度的日志格式的早期响应中收到的日志格式进行解析,并根据此格式解析日志数据。 解析后如下:

9F27 01 40 9F26 08 92AFED093EB371AC 8A 02 3030 9F02 06 000030000000 9F03 06 000000000000 9F1A 02 0360 95 05 8080048000 5F2A 02 0360 9A 03 190519 9C 01 01 9F37 04 7B3B91CF 82 02 7400 9F36 02 000D 9F10 20 01016100000000516D54FA000000000000000000000000000000000000000000 9F6B 30 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

标签 0x9F4F 日志格式 定义标签 + 长度对的顺序。换句话说,标签 0x9F4F 的值包含 TLs - TL(1) + TL(2) + TL(3) + ... + TL(n ).

事务日志 包含具有上述长度的相应标签的值序列,即 Vs - V(1) 的序列+ V(2) + V(3) + ... + V(n).

日志格式解析

TLV:#"9F4F289F27019F26088A029F02069F03069F1A0295055F2A029A039C019F..6B30" # EMV, Tag + Length + Value (TLV) series
- x9F4F:#"9F4F289F27019F26088A029F02069F03069F1A0295055F2A029A039C019F..6B30" # EMV, Log Format
  - tag: "9F4F"
  - len: "28" #  // 40
  - val:#"9F27019F26088A029F02069F03069F1A0295055F2A029A039C019F370482..6B30" # Log Format.
    - x9F27:#"9F2701" # EMV, Cryptogram Information Data (CID)
      - tag: "9F27"
      - len: "01" #  // 1
    - x9F26:#"9F2608" # EMV, Cryptogram, Application
      - tag: "9F26"
      - len: "08" #  // 8
    - x8A:#"8A02" # EMV, Authorization Response Code (ARC)
      - tag: "8A"
      - len: "02" #  // 2
    - x9F02:#"9F0206" # EMV, Authorised Amount (Numeric)
      - tag: "9F02"
      - len: "06" #  // 6
    - x9F03:#"9F0306" # EMV, Amount, Other (Numeric)
      - tag: "9F03"
      - len: "06" #  // 6
    - x9F1A:#"9F1A02" # EMV, Country Code, Terminal
      - tag: "9F1A"
      - len: "02" #  // 2
    - x95:#"9505" # EMV, Terminal Verification Results (TVR)
      - tag: "95"
      - len: "05" #  // 5
    - x5F2A:#"5F2A02" # ISO 7816, Currency Code, Transaction
      - tag: "5F2A"
      - len: "02" #  // 2
    - x9A:#"9A03" # EMV, Date, Transaction
      - tag: "9A"
      - len: "03" #  // 3
    - x9C:#"9C01" # EMV, Transaction Type
      - tag: "9C"
      - len: "01" #  // 1
    - x9F37:#"9F3704" # EMV, Unpredictable Number
      - tag: "9F37"
      - len: "04" #  // 4
    - x82:#"8202" # EMV, Application Interchange Profile (AIP)
      - tag: "82"
      - len: "02" #  // 2
    - x9F36:#"9F3602" # EMV, Application Transaction Counter (ATC)
      - tag: "9F36"
      - len: "02" #  // 2
    - x9F10:#"9F1020" # EMV, Issuer Application Data (IAD)
      - tag: "9F10"
      - len: "20" #  // 32
    - x9F6B:#"9F6B30"
      - tag: "9F6B"
      - len: "30" #  // 48

事务日志数据解析

data:#"4092AFED093EB371AC3030000030000...0000"
- x9F27:
  - val: "40" # Cryptogram Information Data (CID).
    # 01______ - bits 8-7, TC
    # _____000 - bits 3-1, (Reason/Advice/Referral Code), No information given
- x9F26:
  - val: "92AFED093EB371AC" # Cryptogram, Application.
- x8A:
  - val: "3030" # Authorization Response Code (ARC). // 00 - Approved
- x9F02:
  - val: "000030000000" # Amount, Authorised (Numeric). // 30000000
- x9F03:
  - val: "000000000000" # Amount, Other (Numeric).
- x9F1A:
  - val: "0360" # Country Code, Terminal. // 360 - Indonesia
- x95:
  - val:#"8080048000" # Terminal Verification Results (TVR).
    - B01: "80"
      # 1_______ - bit 8, Offline data authentication was not performed
    - B02: "80"
      # 1_______ - bit 8, ICC and terminal have different application versions
    - B03: "04"
      # _____1__ - bit 3, Online PIN entered
    - B04: "80"
      # 1_______ - bit 8, Transaction exceeds floor limit
    - B05: "00"
- x5F2A:
  - val: "0360" # Currency Code, Transaction. // 360 - Rupiah
- x9A:
  - val: "190519" # Date, Transaction. // 2019.05.19
- x9C:
  - val: "01" # Transaction Type. // cash
- x9F37:
  - val: "7B3B91CF" # Unpredictable Number (UN), Terminal.
- x82:
  - val:#"7400" # Application Interchange Profile (AIP).
    - B01: "74"
      # _1______ - bit 7, SDA supported
      # __1_____ - bit 6, DDA supported
      # ___1____ - bit 5, Cardholder verification is supported
      # _____1__ - bit 3, Issuer Authentication is supported
    - B02: "00" # RFU
- x9F36:
  - val: "000D" # Application Transaction Counter (ATC). // 13
- x9F10:
  - val: "01016100000000516D54FA000000000000000000000000000000000000000000" # Issuer Application Data (IAD).
- x9F6B:
  - val: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"