PBOC/EMV-交易流程详解--POS与卡片的数据交互进行分析

符号说明:


RFU:预留使用


近期在调试pboc的交易,就萌生了把所有数据交互进行分析的想法,目的是抛砖引玉,希望有高手指正本文错误,或者理解不透彻的地方。

事不宜迟,下面是pboc交易的开始:


检测插片,检测卡片存在后:
(1):选择支付环境pse:1PAY.SYS.DDF01
选择(SSELECT)报文,00 A4 xx(通过命令选择) xx(第一个或仅有一个)
a4############################################
[IC LEN : 20]
[00] [a4] [04] [00] 
[0e] [31] [50] [41] [59] [2e] [53] [59] [53] [2e] [44] [44] [46] [30] [31] [00]
SELECT SEND END dd
qwe#######################################################


#######################################################
[GET LEN : 40]
[6f] [24] 
[84] [0e] [31] [50] [41] [59] [2e] [53] [59] [53] [2e] [44] [44] [46] [30] [31]
[a5] [12] 
[88] [01] [01] 
[5f] [2d] [08] [7a] [68] [65] [6e] [66] [72] [64] [65] 
[9f] [11] [01] [01] 
[90] [00] SELECT GET END dd
#######################################################
对PSE支付环境的响应 
6F:FCI模板 
84:DF名称 
A5:FCI专用模板
88:目录基本文件的SFI (高三位为0,后面补100,进行读取文件数据)
5F2D:首选语言
9F11:发卡行代码表索引
BF0C:发卡行自定义数据--(该卡没有带此数据)


FCI(文件控制信息)包含FCI(短文件标识符),目录中的每个应用列出一个应用。




--至此,PSE选择完成。如果卡片对选择支付环境的响应不是 90 00,POS需要尝试逐个选择AID


(2): 选择与PSE相关联的一个基本文件,该文件会列出所支持的支付应用。
(读记录)READ RECORD 00 b2 xx(记录号) xx(表明读记录号)
b2############################################
[IC LEN : 5]
[00] [b2] [01] [0c] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 49]
[70] [2d] 
[61] [2b] 
[4f] [07] [a0] [00] [00] [03] [33] [01] [01] 
[50] [0b] [50] [42] [4f] [43] [20] [43] [72] [65] [64] [69] [74] 
[87] [01] [01] 
[9f] [12] [0f] [43] [41] [52] [44] [20] [49] [4d] [41] [47] [45] [20] [30] [30] [30] [31] 
[90] [00] SELECT GET END dd
#######################################################
卡片的响应: 70 xx(长度) xx(记录模板)
70:基本数据模板
61:应用模板,有pse才会存在,包含应用目录入口相关的数据对象
4F:应用标识符 = RID + PIX (应用提供商和专用应用标识符)
50:应用标签,EMV规定为必备数据,用于应用选择,与AID相关的便于记忆的数据 此处为PBOC Credit
87:应用优先指示器,如果卡片有多个应用,指出同一目录中应用的优先级。
    bit8=》1:没有持卡人确认应用不能选择;0:没有持卡人确认可以选择应用
    bit7-bit5:RFU
    bit4-bit10000:不指定优先级。:xxxx:1-15,1优先级最高
9f12:应用首选名称 此处是:CARD IMAGE 0001


获得一个AID后,应该选入AID列表


继续读取文件的下一个记录
b2############################################
[IC LEN : 5]
[00] [b2] [02] [0c] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 2]
[6a] [83] SELECT GET END dd
#######################################################
直到没有任何记录可读取


(3):根据读取的记录的应用标识符加入AID列表,然后根据用户按键进行选择应用或者根据优先级选择应用。
a4############################################
[IC LEN : 13]
[00] [a4] [04] [00] [07] [a0] [00] [00] [03] [33] [01] [01] [00] SELECT SEND END dd
qwe#######################################################


#######################################################
[GET LEN : 48]
[6f] [2c] 
[84] [07] [a0] [00] [00] [03] [33] [01] [01] [a5] [21] [87] [01] [01] 


[9f] [38] [0c] 
[9f] [1a] [02] 
[9f] [7a] [01] 
[9f] [02] [06] 
[5f] [2a] [02] 


[5f] [2d] [08] [7a] [68] [65] [6e] [66] [72] [64] [65] 
[9f] [11] [01] [01] 
[90] [00] SELECT GET END dd
#######################################################
--选择ADF的响应报文
6F: FCI模板
84: DF名称
9F38: PDOL的数据(9F1A:终端国家代码;9F7A: 电子现金指示器,9F02:授权金额,5F2A:交易货币代码)
5F2D:首选语言
9F11: 发卡行代码表索引


进行最终选择,要求用户输入金额,判断POS是否能走电子现金交易路径,表示电子现金指示器。


(4):获取处理选项(GPO) 通知卡片交易开始。根据PDOL选项进行组包。
GPO指令的发送 80 a8 00 00 xx(长度) 83(PDOL标签)xx(PDOL长度)xx xx(数据)
a8############################################
[IC LEN : 19]
[80] [a8] [00] [00] [0d] 
[83] [0b] 


[01] [56] 
[01] 
[00] [00] [00] [00] [00] [09]
[01] [56] 
[00] SELECT SEND END ss
#######################################################


#######################################################
[GET LEN : 18]
[80] [0e] 
[58] [00] 
[08] [01] [01] [00] 
[10] [01] [04] [01] 
[18] [01] [03] [00] 
[90] [00] SELECT GET END ss
#######################################################
GPO的响应格式包括: 80 xx(长度) xx(应用交互特征) xx(AFL)
如上,应用交互特征为: 58 00 
解析:
bit8:RFU; 
bit7:1=支持SDA; 
bit6:1=支持DDA;
bit5:1=支持持卡人认证
bit4:执行终端风险管理
bit3:支持发卡行认证
bit2:RFU
bit1:1=支持CDA
字节2:RFU


AFL(应用文件定位器),每个AFL包括4个字节
字节1:bit8-bit4:SFI(短文件标识符)
       bit3-bit1:000
字节2:文件中要读的第1个记录的记录号(不能为0)
字节3:文件中要读的最后一个记录的记录号(大于或等于字节2)
字节4:从字节2的记录好开始,用于静态数据记录的个数(从0开始,不大于(字节3)-(字节2)+1)


根据GPO返回的AFL,读文件。读文件号格式为:SFI左移3位,右边补100。
比如上面的08 十六进制就是 0000 1000 bit8-bit4才是SFI,所以真实的是:0000 0001 ,读取文件的时候,右补0100(表明读取指定记录) ,得到0000 1100,就是0x0c。同理,02文件就是:0x14
b2############################################
[IC LEN : 5]
[00] [b2] [01] [0c] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 66]
[70] [3e] 
[5f] [20] [0f] [46] [55] [4c] [4c] [20] [46] [55] [4e] [43] [54] [49] [4f] [4e] [41] [4c] 
[57] [11] [62] [28] [00] [01] [00] [00] [11] [17] [d1] [01] [22] [01] [01] [23] [45] [67] [89] [9f] [1f] [16] [30] [31] [30] [32] [30] [33] [30] [34] [30] [35] [30] [36] [30] [37] [30] [38] [30] [39] [30] [41] [30] [42] 
[90] [00] 
SELECT GET END dd
#######################################################
70:模板
5f20:持卡人姓名:FULL FUNCTIONAL
57: 二磁道等价数据(包括主账户 分隔符 失效日期 服务码 PIN验证域 自定义数据 如果不是偶数,补充F)
9F1F: 磁道一自定义数据


b2############################################
[IC LEN : 5]
[00] [b2] [01] [14] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 18]
[70] [0e] 
[5a] [08] [62] [28] [00] [01] [00] [00] [11] [17] 
[5f] [34] [01] [01] 
[90] [00] 
SELECT GET END dd
#######################################################
5a:应用主账号(PAN)
5F34: 应用主账号(应用PAN的序列号)


b2############################################
[IC LEN : 5]
[00] [b2] [02] [14] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 89]
[70] [55] 
[8c] [1d] [9f] [34] [03] [9f] [02] [06] [9f] [03] [06] [9f] [1a] [02] [95] [05] [9b] [02] [5f] [2a] [02] [9a] [03] [9f] [21] [03] [9c] [01] [9f] [37] [04] 
[8d] [1c] [8a] [02] [9f] [02] [06] [9f] [03] [06] [9f] [1a] [02] [95] [05] [9b] [02] [5f] [2a] [02] [9a] [03] [9f] [21] [03] [9c] [01] [9f] [37] [04] 
[9f] [0e] [05] [00] [00] [00] [00] [00] 
[9f] [0f] [05] [00] [00] [00] [00] [00] 
[9f] [0d] [05] [00] [00] [00] [00] [00] 
[90] [00] SELECT GET END dd
#######################################################
8C: 卡片风险管理数据对象列表1 CDOL1
8d: 卡片风险管理数据对象列表2 CDOL2
9F0E: 发卡行行为代码-拒绝
9F0F: 发卡行行为代码-联机
9F0D: 发卡行行为代码-缺省


b2############################################
[IC LEN : 5]
[00] [b2] [03] [14] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 53]
[70] [31] 
[5f] [25] [03] [95] [07] [01] 
[5f] [24] [03] [10] [12] [31] 
[5f] [28] [02] [01] [56] 
[9f] [07] [02] [ff] [c0] 
[9f] [08] [02] [00] [8c] 
[8e] [0a] [00] [00] [00] [00] [00] [00] [00] [00] [1f] [00] 
[5f] [30] [02] [02] [01] 
[9f] [42] [02] [01] [56] 
[90] [00] SELECT GET END dd
#######################################################
5F25: 应用生效日期
5F24: 应用失效日期
5F28: 发卡行国家代码
9F07: 应用用途控制
9f08:应用版本号
8e:持卡人验证方法
5F30: 服务码
9F42:应用货币代码


b2############################################
[IC LEN : 5]
[00] [b2] [04] [14] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 13]
[70] [09] 
[9f] [74] [06] [45] [43] [43] [31] [31] [31] 
[90] [00] SELECT GET END dd
#######################################################
9F74:电子现金发卡行授权码 (如果没有9F74 不能进行电子现金交易)


b2############################################
[IC LEN : 5]
[00] [b2] [01] [1c] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 139]
[70] [81] 
[86] 
[8f] [01] [80] 
[90] [81] 
[80] [22] [91] [03] [a5] [e3] [12] [0f] [2d] [28] [62] [09] [11] [76] [aa] [2b] [d4] [e2] [4d] [69] [e7] [ee] [f7] [b9] [19] [5c] [91] [ea] [00] [88] [ae] [cf] [f4] [7e] [df] [a0] [be] [ef] [7c] [39] [1d] [f3] [b0] [5f] [71] [7d] [cc] [06] [ff] [c8] [ee] [ff] [90] [ba] [14] [21] [2b] [8a] [52] [ad] [48] [b3] [32] [77] [b2] [e2] [30] [d4] [0b] [3e] [76] [dc] [59] [77] [89] [26] [f1] [d8] [73] [9e] [10] [6c] [d7] [41] [de] [06] [a7] [42] [3d] [fb] [a2] [5e] [02] [f1] [2e] [54] [3d] [13] [d1] [b4] [71] [80] [65] [26] [02] [49] [81] [b7] [d2] [6b] [4b] [f6] [e5] [55] [86] [04] [cc] [c2] [89] [f5] [9e] [8a] [80] [2f] [45] [fb] [3d] [9e] [67] 
[90] [00] SELECT GET END dd
#######################################################
8F: 公钥索引
90:发卡行公钥证书--用于脱机数据认证


b2############################################
[IC LEN : 5]
[00] [b2] [02] [1c] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 46]
[70] [2a] 
[9f] [32] [01] [03] 
[92] [24] [8b] [64] [3d] [1e] [af] [2e] [a7] [84] [ac] [20] [53] [03] [c9] [0e] [74] [5e] [a2] [ef] [a5] [cb] [f0] [2c] [c4] [7d] [47] [83] [3b] [b7] [b2] [7e] [cc] [69] [62] [38] [5a] [4b]
[90] [00] SELECT GET END dd
#######################################################
9F32: 发卡行公钥指数
92:发卡行公钥余数


b2############################################
[IC LEN : 5]
[00] [b2] [03] [1c] [00] SELECT SEND END dd
#######################################################


asd#######################################################
[GET LEN : 136]
[70] [81] 
[83] 
[93] [81] 
[80] [33] [5d] [0c] [c2] [4c] [19] [70] [a2] [69] [bc] [a7] [9b] [d9] [2c] [ad] [12] [68] [35] [9d] [10] [5f] [af] [a1] [d0] [c5] [29] [46] [f3] [64] [5f] [bc] [d4] [6a] [45] [e6] [23] [a4] [37] [f6] [1e] [d7] [b4] [5d] [8f] [32] [42] [76] [7e] [69] [53] [4d] [ee] [7b] [a0] [35] [cd] [c0] [64] [9e] [14] [95] [cf] [7a] [13] [89] [03] [ae] [4f] [28] [05] [e5] [18] [b1] [12] [31] [88] [ed] [cc] [74] [52] [42] [e5] [f4] [c5] [2e] [e9] [34] [d9] [57] [df] [0d] [79] [e1] [4c] [c6] [12] [62] [7c] [ab] [bd] [f5] [fd] [1b] [a1] [a5] [dd] [23] [4e] [0e] [54] [0b] [59] [74] [91] [dd] [b5] [cb] [77] [50] [85] [61] [0d] [75] [83] [77] [a7] [fe] [c3] 
[90] [00] SELECT GET END dd
#######################################################
93: 签名的静态应用数据-SDA


文件中的记录已经读取完毕


POS已经检查可以做电子现金交易,读取可用余额值:9F79
9F4F############################################
[IC LEN : 5]
[80] [ca] [9f] [79] [00] SELECT SEND END EE
#######################################################
#######################################################
[GET LEN : 11]
[9f] [79] [06] [00] [00] [00] [01] [00] [00] [90] [00] SELECT GET END EE
#######################################################


POS已经检查可以做电子现金交易,读取重置阀值:9F6D
9F4F############################################
[IC LEN : 5]
[80] [ca] [9f] [6d] [00] SELECT SEND END EE
#######################################################
#######################################################
[GET LEN : 11]
[9f] [6d] [06] [00] [00] [00] [00] [15] [00] [90] [00] SELECT GET END EE
#######################################################
如果可用余额减去授权金额,小于重置阀值,POS将强制联机,需要用户输入后台账户。


至此,获取随机数,进行脱机数据认证(SDA/DDA),获取卡号信息,进行使用控制,失效日期检查,生效日期检查,执行CVM,进行终端风险管理,卡片行为分析,以及各种牛逼检查。


(5):Generate AC(获取应用密文)80 AE xx(控制参数) 00 
AE############################################
[IC LEN : 43]
[80] [ae] [40] [00] 
[25] 
[3f] [00] [01] 
[00] [00] [00] [00] [00] [09] 
[00] [00] [00] [00] [00] [00] 
[01] [56] 
[00] [00] [80] [00] [00] [c0] [00] 
[01] [56] 
[10] [04] [10] [20] [19] [02] [00] 
[b8] [4f] [ba] [07] 
[00] 
SELECT SEND END oo
#######################################################
控制参数 40: bit8,bit7 :00=AAC--拒绝
                           01=TC--脱机
                           10=ARQC--联机
                           11=RFU
生成密文的数据源:第五部分附录D: 授权金额
#######################################################
[GET LEN : 34]
[80] [1e] 
[40] 
[00] [01] 
[df] [db] [ca] [78] [4f] [f1] [54] [66] 
[07] --长度
[01] --分散密钥索引
[01] --密文版本号
[03] [94] [00] [00] --卡片验证结果CVR
[01] --算法标识
[0a] [01] [00] [00] [00] [08] [00] [11] [22] [33] [44] --自定义数据
[90] [00] 
SELECT GETOUT OF PAPER. END oo
#######################################OUT OF PAPER.################
80: 模板
此模板的响应数据为: 密文信息数据(L:1) + 应用交易计数器(L:2) + 应用密文(L:8) + 发卡行应用数据


交易结束

你可能感兴趣的:(EMV/PBOC)