Search code examples
javaandroidpayment-processingemv

EMV transaction log result is not expected


I read transaction log to calculate floor limits in terminal risk management. I successfully read transaction log of EMV card with length is 10 lines, but why the EMV-tags of that result is not recognized when parsed it with TLV Parser?

EMV-tags: 4092 is not recognized by TLV Parser?

1.Log Format

REQ LOG_FORMAT: 80CA9F4F00

RES LOG_FORMAT: 9F4F289F27019F26088A029F02069F03069F1A0295055F2A029A039C019F370482029F36029F10209F6B30 9000

LogFormat is success

2.Log Entry

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

3.Transaction Log

REQ TRANS_LOG: 00B2015C00

RES TRANS_LOG: 4092AFED093EB371AC3030000030000000000000000000036080800480000360190519017B3B91CF7400000D01016100000000516D54FA000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 9000

//More transaction log in here

Transaction Log is success

Transaction Log code:

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;
}

Solution

  • Tag 0x9F4F Log Format define sequence of Tag + Length pairs. In other words the Value of Tag 0x9F4F contains TLs - the sequence of TL(1) + TL(2) + TL(3) + ... + TL(n).

    Transaction Log contain the sequence of Values for the correspondent Tags with mentioned lengths, i.e. Vs - the sequence of V(1) + V(2) + V(3) + ... + V(n).

    Log Format parsing

    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
    

    Transaction Log data parsing

    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"