PDOL为EMV卡(APDU)生成“GET PROCESSING OPTIONS”(GPO)

Posted

技术标签:

【中文标题】PDOL为EMV卡(APDU)生成“GET PROCESSING OPTIONS”(GPO)【英文标题】:Generate "GET PROCESSING OPTIONS" (GPO) for EMV card (APDU) by PDOL 【发布时间】:2019-03-25 12:21:58 【问题描述】:

GPO 命令被这样定义为 APDU 命令:

CLA INS P1 P2 Lc Data Le
80  A8  00 00 Lc Data 00

所以缺少的部分是 LcData 我们必须从 PDOL 计算(如果给定的话)。如果没有给出,我们可以使用:

80 A8 00 00 02 8300 00

这适用于万事达卡,但对于 VISA,我得到了一个 PDOL 并试图构建缺少的 APDU 部分(Lc 和数据)。

第 1 步 - 我从我的 EMV 卡中获得此 PDOL:

9F66049F02069F03069F1A0295055F2A029A039C019F3704

第 2 步 - 按命令拆分:

9F6604 9F0206 9F0306 9F1A02 9505 5F2A02 9A03 9C01 9F3704

第 3 步 - 按字节长度再次拆分:

9F66 04 | 9F02 06 | 9F03 06 | 9F1A 02 | 95 05 | 5F2A 02 | 9A 03 | 9C 01 | 9F37 04

第 4 步 - 给出以下命令(删除长度):

描述“要插入的内容”

9F66 | 9F02 | 9F03 | 9F1A | 95 | 5F2A | 9A | 9C | 9F37

第 5 步 - 以及以下命令长度(删除命令):

描述“每个命令的长度”

04 | 06 | 06 | 02 | 05 | 02 | 03 | 01 | 04

第 6 步 - 假设长度为 2 位,这将使我们加倍:

8 | 12 | 12 | 4 | 10 | 4 | 6 | 2 | 8

第 7 步 - 预期输出现在应如下所示:

aaaaaaaa bbbbbbbbbbbb cccccccccccc dddd eeeeeeeeee ffff gggggg hh iiiiiiii

第 8 步 - 查找命令以查找值:

9F66 | 9F02 | 9F03 | 9F1A | 95 | 5F2A | 9A | 9C | 9F37

https://www.emvlab.org/emvtags/show/t9F66/ = 未知(我用 Google 搜索发现它是:'Terminal Transaction Qualifiers' = TTQ)

https://www.emvlab.org/emvtags/show/t9F02/ = 授权金额

https://www.emvlab.org/emvtags/show/t9F03/ = 次要/返现金额

https://www.emvlab.org/emvtags/show/t9F1A/ = ISO 3166 终端国家代码 (TCC)

https://www.emvlab.org/emvtags/show/t95/ = 终端验证结果(TVR)

https://www.emvlab.org/emvtags/show/t5F2A/ = ISO 4217 货币代码 (CC)

https://www.emvlab.org/emvtags/show/t9A/ = 交易日期 YYMMDD

https://www.emvlab.org/emvtags/show/t9C/ = ISO 8583:1987 前 2 位数字(交易类型 - TT)

https://www.emvlab.org/emvtags/show/t9F37/ = 不可预测数(密码的随机数 - UN)

第 9 步 - 插入 obvios 数据:

9F66 aaaaaaaa     TTQ      
9F02 bbbbbbbbbbbb Amount   000000001000
9F03 cccccccccccc Cashback 000000000000
9F1A dddd         TCC
95   eeeeeeeeee   TVR
5F2A ffff         CC
9A   gggggg       YYMMDD   190325
9C   hh           TT
9F37 iiiiiiii     UN       12121212

第 10 步 - 终端交易限定符 (TTQ):

(支持的终端功能设置)

9F66 a1 a2 a3 a4   

A. a1 - Hex to binary -> 00000000
B. a2 - Hex to binary -> 00000000
C. a3 - Hex to binary -> 00000000
D. a4 - Hex to binary -> 00000000 - RFU (Reserved Future Use)

每个零都可以打开或关闭。

A. a1 (hex to binary gives 8 numbers)

  8. 0 - Contactless MSD          - Example: 0 - false
  7. 0 - Contactless VSDC         - Example: 1 - true
  6. 0 - Contactless qVSDC        - Example: 0 - false
  5. 0 - EMV contact chip         - Example: 1 - true
  4. 0 - Offline-only reader      - Example: 0 - false
  3. 0 - Online PIN               - Example: 0 - false
  2. 0 - Signature                - Example: 0 - false
  1. 0 - Offline data auth (ODA)  - Example: 1 - true

示例给出:01010001。二进制转十六进制 -> 51

B. a2 (hex to binary gives 8 numbers)

  8. 0 - Require Online Crypt     - Example: 0 - false
  7. 0 - CVM required .           - Example: 0 - false
  6. 0 - Offline PIN support      - Example: 0 - false
  5. 0 - RFU(Reserved Future Use) - Example: 0 - false
  4. 0 - RFU(Reserved Future Use) - Example: 0 - false
  3. 0 - RFU(Reserved Future Use) - Example: 0 - false
  2. 0 - RFU(Reserved Future Use) - Example: 0 - false
  1. 0 - RFU(Reserved Future Use) - Example: 0 - false

示例给出:00000000。二进制转十六进制 -> 00

C. a3 (hex to binary gives 8 numbers)

  8. 0 - Issuer update process    - Example: 0 - false
  7. 0 - Mobile functionality     - Example: 1 - true
  6. 0 - RFU(Reserved Future Use) - Example: 0 - false
  5. 0 - RFU(Reserved Future Use) - Example: 0 - false
  4. 0 - RFU(Reserved Future Use) - Example: 0 - false
  3. 0 - RFU(Reserved Future Use) - Example: 0 - false
  2. 0 - RFU(Reserved Future Use) - Example: 0 - false
  1. 0 - RFU(Reserved Future Use) - Example: 0 - false

示例给出:01000000。二进制转十六进制 -> 40

D. a4 = RFU(Reserved Future Use) = 00000000 = 00

给出:00000000。二进制到十六进制 -> 00

将 HEX 值放在一起返回:TTQ = 51004000

第 11 步 - 更新 ISO 值(谷歌搜索)并插入 TTQ:

参考:https://en.wikipedia.org/wiki/ISO_8583

TT
Authorization:   00
Balance inquiry: 31
Sale:            00
Cash:            01
Void:            02
Mobile topup:    57

9F66 aaaaaaaa     TTQ      51004000     TTQ
9F02 bbbbbbbbbbbb Amount   000000001000
9F03 cccccccccccc Cashback 000000000000
9F1A dddd         TCC      0578         ISO 3166 Norway (not same as phone)
95   eeeeeeeeee   TVR
5F2A ffff         CC       0978         ISO 4217 Euro
9A   gggggg       YYMMDD   190325
9C   hh           TT       00           ISO 8583:1987 first 2 digits
9F37 iiiiiiii     UN       12121212

第 12 步 - 终端验证结果 (TVR):

https://en.wikipedia.org/wiki/Terminal_verification_results

9F66 e1 e2 e3 e4 e5 

A. e1 - Hex to binary -> 00000000
B. e2 - Hex to binary -> 00000000
C. e3 - Hex to binary -> 00000000
D. e4 - Hex to binary -> 00000000
E. e5 - Hex to binary -> 00000000

每个零都可以打开或关闭。

A. e1 (hex to binary gives 8 numbers)

  8. 0 - Offline process not performed - Example: 0 - false
  7. 0 - SDA failed                    - Example: 0 - false
  6. 0 - ICC data missing              - Example: 0 - false
  5. 0 - Card number on hotlist        - Example: 0 - false
  4. 0 - DDA failed                    - Example: 0 - false
  3. 0 - CDA failed                    - Example: 0 - false
  2. 0 - RFU (SDA was selected)        - Example: 0 - false
  1. 0 - RFU                           - Example: 0 - false

示例给出:00000000。二进制转十六进制 -> 00

B. e2 (hex to binary gives 8 numbers)

  8. 0 - Card/terminal version differ. - Example: 0 - false
  7. 0 - Expired app                   - Example: 0 - false
  6. 0 - App not yet effective         - Example: 0 - false
  5. 0 - Service not allowed for card  - Example: 0 - false
  4. 0 - New card                      - Example: 0 - false
  3. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  2. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  1. 0 - RFU(Reserved Future Use)      - Example: 0 - false

示例给出:00000000。二进制转十六进制 -> 00

C. e3 (hex to binary gives 8 numbers)

  8. 0 - Cardholder verification fail  - Example: 0 - false
  7. 0 - Unrecognised CVM              - Example: 0 - false
  6. 0 - PIN try limit exceeded        - Example: 0 - false
  5. 0 - PIN required, but no pinpad   - Example: 0 - false
  4. 0 - PIN req. & present & missing  - Example: 0 - false
  3. 0 - On-line PIN entered           - Example: 0 - false
  2. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  1. 0 - RFU(Reserved Future Use)      - Example: 0 - false

示例给出:00000000。二进制转十六进制 -> 00

D. e4 (hex to binary gives 8 numbers)

  8. 0 - Transact. exceeds floor limit - Example: 0 - false
  7. 0 - Lower offline limit exceeded  - Example: 0 - false
  6. 0 - Upper offline limit exceeded  - Example: 0 - false
  5. 0 - Transa. randomly sele. online - Example: 0 - false
  4. 0 - Merch. forced online transac. - Example: 0 - false
  3. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  2. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  1. 0 - RFU(Reserved Future Use)      - Example: 0 - false

示例给出:00000000。二进制转十六进制 -> 00

E. e5 (hex to binary gives 8 numbers)

  8. 0 - Default TDOL Used             - Example: 0 - false
  7. 0 - Issuer authentication failed  - Example: 0 - false
  6. 0 - Script fail before final GAC  - Example: 0 - false
  5. 0 - Script fail after final GAC   - Example: 0 - false
  4. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  3. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  2. 0 - RFU(Reserved Future Use)      - Example: 0 - false
  1. 0 - RFU(Reserved Future Use)      - Example: 0 - false

示例给出:00000000。二进制转十六进制 -> 00

将所有 HEX 值放在一起得出:TVR = 0000000000

第 13 步 - 最终命令:

9F66 aaaaaaaa     TTQ      51004000
9F02 bbbbbbbbbbbb Amount   000000001000
9F03 cccccccccccc Cashback 000000000000
9F1A dddd         TCC      0578
95   eeeeeeeeee   TVR      0000000000
5F2A ffff         CC       0978
9A   gggggg       YYMMDD   190325
9C   hh           TT       00
9F37 iiiiiiii     UN       12121212

结果:

51004000 000000001000 000000000000 0578 0000000000 0978 190325 00 12121212

第 14 步 - 获取标签长度值:

获取结果的长度: 5100400000000000100000000000000000578000000000009781903250012121212 = 66 个号码 它是 2 位,所以: 66 / 2 = 33 个字符

Convert 33 to HEX = 21

tlv = 21

tlv 应该在第 13 步的结果之前应用:

21 510040000000000010000000000000000578000000000009781903250012121212

第 15 步 - 添加“83”的 GPO 标签:

83 21 510040000000000010000000000000000578000000000009781903250012121212

所以,数据 = 8321510040000000000010000000000010000578000000000009781903250012121212

第 16 步 - 获取整个命令的标签长度​​值 (Lc):

获取结果长度:

8321510040000000000010000000000000000578000000000009781903250012121212
= 70 numbers
It is 2-bits, so:
70 / 2 = 35 characters

Convert 35 to HEX = 23

Lc = 23

第 17 步 - 将所有内容放在一起:

记住缺少的部分是Lc & Data

CLA INS P1 P2 Lc Data Le
80  A8  00 00 Lc Data 00
80  A8  00 00 23 Data 00

添加数据:

APDU =
80A8000023832151004000000000001000000000000000057800000000000978190325001212121200

问题

我生成的最后一个 apdu 命令返回 no value。 有谁知道我在哪一步跌倒或可以看出我做错了什么?

资源:

https://www.emvlab.org/emvtags/

https://en.wikipedia.org/wiki/Terminal_verification_results

https://www.rapidtables.com/convert/number/decimal-to-hex.html

https://tvr-decoder.appspot.com/t/home

Parsing PDOL for GET PROCESSING OPTIONS command in EMV transaction

Getting Parser error on request for GPO command for EMV card

https://www.iban.com/currency-codes

https://www.iban.com/country-codes

http://www.emvlab.org/tlvutils/

【问题讨论】:

【参考方案1】:

我发现了错误。问题是在 STEP 10 中设置正确的交易功能。

由于我的处理器只是一个 NFC 阅读器,我不得不将第 10 步修改为以下内容:

第 10 步 - 终端交易限定符 (TTQ):

(支持的终端功能设置)

9F66 a1 a2 a3 a4   

A. a1 - Hex to binary -> 00000000
B. a2 - Hex to binary -> 00000000
C. a3 - Hex to binary -> 00000000
D. a4 - Hex to binary -> 00000000 - RFU (Reserved Future Use)

每个零都可以打开或关闭。

A. a1 (hex to binary gives 8 numbers)

  8. 0 - Contactless MSD          - Example: 1 - true
  7. 0 - Contactless VSDC         - Example: 1 - true
  6. 0 - Contactless qVSDC        - Example: 1 - true
  5. 0 - EMV contact chip         - Example: 1 - true
  4. 0 - Offline-only reader      - Example: 0 - false
  3. 0 - Online PIN               - Example: 0 - false
  2. 0 - Signature                - Example: 0 - false
  1. 0 - Offline data auth (ODA)  - Example: 0 - false

示例给出:11110000。二进制转十六进制 -> F0

B. a2 (hex to binary gives 8 numbers)

  8. 0 - Require Online Crypt     - Example: 0 - false
  7. 0 - CVM required .           - Example: 0 - false
  6. 0 - Offline PIN support      - Example: 1 - true
  5. 0 - RFU(Reserved Future Use) - Example: 0 - false
  4. 0 - RFU(Reserved Future Use) - Example: 0 - false
  3. 0 - RFU(Reserved Future Use) - Example: 0 - false
  2. 0 - RFU(Reserved Future Use) - Example: 0 - false
  1. 0 - RFU(Reserved Future Use) - Example: 0 - false

示例给出:00100000。二进制转十六进制 -> 20

C. a3 (hex to binary gives 8 numbers)

  8. 0 - Issuer update process    - Example: 0 - false
  7. 0 - Mobile functionality     - Example: 1 - true
  6. 0 - RFU(Reserved Future Use) - Example: 0 - false
  5. 0 - RFU(Reserved Future Use) - Example: 0 - false
  4. 0 - RFU(Reserved Future Use) - Example: 0 - false
  3. 0 - RFU(Reserved Future Use) - Example: 0 - false
  2. 0 - RFU(Reserved Future Use) - Example: 0 - false
  1. 0 - RFU(Reserved Future Use) - Example: 0 - false

示例给出:01000000。二进制转十六进制 -> 40

D. a4 = RFU(Reserved Future Use) = 00000000 = 00

给出:00000000。二进制到十六进制 -> 00

将 HEX 值放在一起返回:TTQ = F0204000


因此将 TTQ 值更改为 F0204000 使卡响应 GPO 命令。 :)

【讨论】:

+1 表示为解释该问题所做的努力。我猜这个问题只与 B1b6 有关(除非您使用的是非接触式 MSD 路径卡)。 PDOL 和其中的 Tag 0x9F66 指向 VISA PayWave 或 EMV 非接触式内核 3. 查找“Visa 非接触式支付规范”(VCPS)它可以帮助理解流程和强制性的事情。

以上是关于PDOL为EMV卡(APDU)生成“GET PROCESSING OPTIONS”(GPO)的主要内容,如果未能解决你的问题,请参考以下文章

如何从 Javacard 制作 EMV 卡?

从 emv 卡中获取 IBAN 号码

使用 MPCOS EMV r5 进行智能卡编程

EMV:第二次生成 AC 结果导致 6985 SW_Error 访问条件不满足

APDU读取文件java卡程序

APDU 命令更改 IMSI SIM 卡