Android isoDep.transceive on Generate AC 命令总是返回 6D00 不受支持

标签 android nfc apdu emv contactless-smartcard

我正在尝试模拟 PoS,销售点 :),系统并使用在 2013 Nexus 7(无安全元件)v4.4.2 上运行的 Google 钱包完成交易。

我的 PoS 原型(prototype)也在 2013 Nexus 7 v4.4.2 上运行。

我能够从 2PAY_SYS_DDF01 请求获得 NFC 响应。 我可以选择 MasterCard 应用程序 ID。 我能够获得处理选项。 当我阅读记录时,Google 钱包似乎没有返回所有必填的 EMV 字段。 最后,当我请求生成 AC 命令时,它总是返回不受支持的 6D00。

有问题的代码区域:

//set P1 to '40', to request an Transaction Certificate (offline transaction) 
//and execute the Generate AC command.

byte[] generateAC = new byte[] {(byte)0x80, (byte)0xAE, 0x40, 0x00,
                0x1D,                               //data length
                0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //amount1
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //amount2
                0x08, 0x40,                         //term country
                0x00, 0x00, 0x00, 0x00, 0x00,       //tvr
                0x09, 0x62,                         //tx curr
                0x14, 0x04, 0x1B,                   //tx date
                0x00,                               //tx type
                0x12, 0x34, 0x56, 0x78,             //random
                0x00};                              //le
response = isoDep.transceive(generateAC);

我正在关注 Tim Beckers 的视频 https://www.youtube.com/watch?v=qqobg1-HrfY 约46分钟。 和 Tim Beckers 代码示例: https://github.com/a2800276/29c3/blob/master/smartshell.rb

更新:

对 GPO 命令(80 a8 00 00 02 83 00 00)的响应是

770a820200009404080101009000

77 Response Message Template Format 2
    82 Application Interchange Profile
        0000
    94 Application File Locator (AFL)
        08010100

更新:

我试过:

byte[] computeCC = new byte[] {
(byte)0x80, // CLA = proprietary
(byte)0x2A, // INS = COMPUTE CRYPTOGRAPHIC CHECKSUM
(byte)0x8E, // P1
(byte)0x80, // P2
(byte)0x04, // Lc
(byte)0x00, 0x00, (byte)0x00, (byte)0x99, // Unpredicatable Number (numeric)
(byte)0x00, // Le
};
response = isoDep.transceive(computeCC);

希望至少得到一个错误,指示错误的不可预测的数字,但我返回了 6700 个不正确的长度。

早些时候我收到了 Read Record 00 B2 01 0C 00 的回复 该响应的一部分是 卡认证相关数据[9F69]: 数据(二进制):XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX fDDA 版本号:9F (卡片)不可预测的数字:6A 04 9F 7E

所以我尝试了那个不可预测的数字

byte[] computeCC = new byte[] {
(byte)0x80, // CLA = proprietary
(byte)0x2A, // INS = COMPUTE CRYPTOGRAPHIC CHECKSUM
(byte)0x8E, // P1
(byte)0x80, // P2
(byte)0x04, // Lc
(byte)0x6A, 0x04, (byte)0x9F, (byte)0x7E, // Unpredicatable Number (numeric)
(byte)0x00, // Le
};
response = isoDep.transceive(computeCC);

但我仍然得到 6700 个错误的长度

更新:

READ RECORD (Record = 1, SFI = 1) 命令的响应 (00 B2 01 0C 00) 是:

70 7c 9f 6c 02
00 01 9f 62 06
00 00 00 00 00
38 9f 63 06 00
00 00 00 03 c6
56 29 42 35 33
39 36 XX XX XX
XX 31 XX XX 39
XX XX XX XX 5e
20 2f 5e 31 34
30 37 31 30 31
34 30 31 30 30
30 30 30 30 30
30 30 30 9f 64
01 04 9f 65 02
00 38 9f 66 02
03 c6 9f 6b 13
53 96 XX XX 1X
X9 XX XX d1 40
71 01 40 10 00
00 00 00 0f 9f
67 01 04 9f 69
0f 9f 6a 04 9f
7e 01 9f 02 06
5f 2a 02 9f 1a
02 90 00

--------------------------TLV------------------------------- 
Output:
READ RECORD Response Message Template [70]:
    Card Transaction Qualifiers (CTQ) [9F6C]:
    Data (Binary):  00 01 
Bit flags set:
    1Bxb8: 0 - Online PIN not Required
    1Bxb7: 0 - Signature Not Required
    1Bxb6: 0 - Not applicable: Go Online if Offline Data Authentication     Fails and Reader is online capable.
    1Bxb5: 0 - Not applicable: Switch Interface if Offline Data     Authentication fails and Reader supports VIS.
    1Bxb4: 0 - Not applicable: Go Online if Application Expired
    1Bxb3: 0 - Not applicable: Switch Interface for Cash Transactions
    1Bxb2: 0 - Not applicable: Switch Interface for Cashback Transactions
    1Bxb1: 0 - RFU
    2Bxb8: 0 - Consumer Device CVM not Performed
    2Bxb7: 0 - Card doesn't support Issuer Update Processing at the POS
    2Bxb6: 0 - RFU
    2Bxb5: 0 - RFU
    2Bxb4: 0 - RFU
    2Bxb3: 0 - RFU
    2Bxb2: 0 - RFU
    2Bxb1: 1 - RFU
PCVC3 (Track1) [9F62]:
    Data (Binary):  00 00 00 00 00 38 
Offline Counter Initial Value [9F63]:
    Data (Binary):  00 00 00 00 03 C6 
Track 1 Data [56]:

    Data (ASCII):   B5396XXXXXXXXXXXX^ /^14071014010000000000
NATC (Track1) [9F64]:
    Data (Binary):  04 
PCVC3 (Track2) [9F65]:
    Data (Binary):  00 38 
Terminal Transaction Qualifiers (TTQ) [9F66]:
    Data (Binary):  03 C6 
Card CVM Limit [9F6B]:
    Data (Binary):  53 96 48 50 17 69 62 32 D1 40 71 01 40 10 00 00 00 00 0F 
MSD Offset [9F67]:
    Data (Binary):  04 
Card Authentication Related Data [9F69]:
    Data (Binary):  9F 6A 04 9F 7E 01 9F 02 06 5F 2A 02 9F 1A 02 
fDDA Version Number: 9F
(Card) Unpredictable Number: 6A 04 9F 7E
Card Transaction Qualifiers: 01 9F
----------------------------------------

最佳答案

对 GET PROCESSING OPTIONS 命令的响应指示以下应用程序交换配置文件 (AIP):

82 Application Interchange Profile
    0000

Google Wallet 基本上是一张 MasterCard(EMV 非接触式内核 2),因此根据内核 2 的规则解码 AIP 会得到以下结果:

Byte 1, b7 = 0: no SDA supported
        b6 = 0: no DDA supported
        b5 = 0: no cardholder verification supported
        b4 = 0: no terminal risk management to be performed
        b3 = 0: no issuer authentication supported
        b2 = 0: no on-device cardholder verification supported
        b1 = 0: no CDA supported
Byte 2, b8 = 0: no EMV mode supported

重要的是byte 2,bit 8:表示你的卡不支持EMV模式。因此,您的卡/Google 电子钱包是一张仅支持磁条模式的 PayPass 卡。因此,您无法使用 GENERATE AC 验证交易。相反,您只能使用 COMPUTE CRYPTOGRAPHIC CHECKSUM 让卡生成动态卡验证码 (CVC3):

byte[] computeCC = new byte[] {
    (byte)0x80, // CLA = proprietary
    (byte)0x2A, // INS = COMPUTE CRYPTOGRAPHIC CHECKSUM
    (byte)0x8E, // P1
    (byte)0x80, // P2
    (byte)0x04, // Lc
    (byte)0xWW, (byte)0xXX, (byte)0xYY, (byte)0xZZ, // Unpredicatable Number (numeric)
    (byte)0x00, // Le
};
response = isoDep.transceive(computeCC);

注意COMPUTE CRYPTOGRAPHIC CHECKSUM命令的数据字段必须根据UDOL填入值(如果没有UDOL,默认UDOL是9F6A04,表示不可预测的数字,数字).

不可预知的数字(数字)是由磁条数据文件定义的范围内的 BCD 编码数字(参见 AFL)。过去,对于 Google 电子钱包,这是一个介于 0 和 99 之间的值(即 WW='00'XX='00'YY=' 00', ZZ='00'..'99').

更新:

从卡中读取的数据解码如下:

70 7c
  9f6c 02    Mag-stripe application version number = Version 1
    00 01
  9f62 06    Track 1 bit map for CVC3
    00 00 00 00 00 38
  9f63 06    Track 1 bit map for UN and ATC
    00 00 00 00 03 c6
  56 29      Track 1 data
    42         ISO/IEC 7813 structure "B" format
    35333936 XXXXXXXX 31XXXX39 XXXXXXXX    PAN (ASCII)
    5e         Field separator "^"
    202f       Cardholder name " /" (empty, see MC requirements)
    5e         Field separator "^"
    31343037   Expiry date "14"/"07"
    313031     Service code "101"
    34303130303030303030303030    Track 1 discretionary data
  9f64 01    Track 1 number of ATC digits
    04
  9f65 02    Track 2 bit map for CVC3
    00 38
  9f66 02    Track 2 bit map for UN and ATC
    03 c6
  9f6b 13    Track 2 data
    5396 XXXX 1XX9 XXXX    PAN (BCD)
    d          Field separator
    1407       Expiry date
    101        Service code
    4010000000000    Track 2 discretionary data
    f          Padding
  9f67 01      Track 2 number of ATC digits
    04
  9f69 0f      UDOL
    9f6a 04      Unpredictable number (numeric)
    9f7e 01      Mobile support indicator
    9f02 06      Amount authorized (numeric)
    5f2a 02      Transaction currency code
    9f1a 02      Terminal country code

因此卡片确实提供了 UDOL。因此,必须相应地调整 COMPUTE CRYPTOGRAPHIC CHECKSUM 命令:

byte[] computeCC = new byte[] {
    (byte)0x80, // CLA = proprietary
    (byte)0x2A, // INS = COMPUTE CRYPTOGRAPHIC CHECKSUM
    (byte)0x8E, // P1
    (byte)0x80, // P2
    (byte)0x0F, // Lc
    // 9f6a 04      Unpredictable number (numeric)
    (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x12, // two digits according to UN/ATC bit map and number of ATC digits: 6 - 4 = 2
    // 9f7e 01      Mobile support indicator
    (byte)0x00, // no offline PIN required, no mobile support
    // 9f02 06      Amount authorized (numeric)
    (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, // 1.00
    // 5f2a 02      Transaction currency code
    (byte)0x09, (byte)0x78, // Euro
    // 9f1a 02      Terminal country code
    (byte)0x00, (byte)0x40, // Austria
    (byte)0x00, // Le
};
response = isoDep.transceive(computeCC);

关于Android isoDep.transceive on Generate AC 命令总是返回 6D00 不受支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23329585/

相关文章:

android - 如何通过 API 启用 NFC 阅读器?

android - 使用 nfc 解锁应用程序

android - 全屏自定义对话框?

android - 从 Android WebView 启动下载链接后如何自动关闭浏览器?

Android Studio/Gradle 构建问题

nfc - APDU 在 mifare classic 上写入 block 命令

android - Android 中的 Mifare Ultralight C 身份验证 (2.3.6)

android - getContactsFromFirebase() 方法返回一个空列表

Android:NFC 标签技术 -> 是否应该检查它们,如果是,如何检查?

eclipse - 不允许使用命令 - 安装小程序时不满足使用条件