2016-08-02 138 views
0

我將Android設置爲通過NFC工作來發送APDU命令。 其中一個APDU響應字節被截斷了一些方法。NFC Android截斷APDU響應字節

如剛纔HostAPDUService.sendResponseApdu(bytes[])之前印在日誌語句的響應字節是這個

I/NfcService:通報偵聽狀態:DEBUG_APDU_SENT數據:7F4982010A81820101009F80023FC39926A237680FFFF47060239F4D240C1EBC424428965FADDBBD0BC3B2CB9BF8952AFF24135C5DCEA7931CEB0BF1406B57BE099DBF7F3A36FA6F20B9B244C1C4131CBFA1D088E1F2298845402B2505E28CA52403EFD09882C361A2F63C30C1FFA3160BAB9BE7CF64E1DA6066EEAAB995B3F627676E4FEF32F9FEA5534E472EBF990F7C964BB9FB36DFE995124AC80C306C796A22840A6FC3871508F1B5CCB063D4DDAD252AA9B4E13219ED4C5EA50FF2BBACA937BB0F9CF80472818AE49DE05E8B66D3863EEF3028325812958099C78CD65919A3660592A0BA5E966D6A01A3DD8242BDA5940146C07AE8475F35C88024DE566112

但是在接收端我看到只收到第一個4個字符並且存在通過不應用 APDU響應:

SW = 7F49(無可用的翻譯),NR = 0,APDU響應字節:7f 49

任何想法,爲什麼這可能是?這是由於擴展的APDU功能嗎? https://code.google.com/p/android/issues/detail?id=76598

連接整個APDU命令跟蹤,直到它失敗。請注意,相同的代碼適用於任何其他接口(如通過藍牙,物理卡)等,而不適用於NFC Android(HostAPDUService)。

我看到我無法重寫HostAPDUService.sendResponseAPDU,因此無法找到截斷髮生的位置。我確信在發送到這個方法之前,我的響應字節不會被截斷。

APDU Received: 00A4040008A000000003000000 
APDU Sent: 9000 
APDU Received: 00CA9F7F 
APDU Sent: FF01A3CE00000000000033639D44CFB00C690000000000000000000000000000000000000000000000009000 
APDU Received: 80500000085C313D2C8C29F71C 
APDU Sent: 000033639D44CFB00C6901020001E3AC80DCF8D08E7D5C5C8C4DCAE29000 
APDU Received: 848203001012F927AC6FAC2C247AD0F09679AEC48C 
APDU Sent: 9000 
APDU Received: 00A4040008A000000003000000 
APDU Sent: 9000 
APDU Received: 00CA9F7F 
APDU Sent: FF01A3CE00000000000033639D44CFB00C690000000000000000000000000000000000000000000000009000 
APDU Received: 00A4040008A000000003000000FF 
APDU Sent: 9000 
APDU Received: 80CA9F7F 
APDU Sent: 9F7F2AFF01A3CE00000000000033639D44CFB00C690000000000000000000000000000000000000000000000009000 
APDU Received: 00A4040008A000000003000000FF 
APDU Sent: 9000 
APDU Received: 805000000812D2920F64D6D881 
APDU Sent: 000033639D44CFB00C6901020002F8AC3BC0BA50FA6707901F6B6F7A9000 
APDU Received: 848203001042E02498FB5BD93AC67DAD9D8EC29373 
APDU Sent: 9000 
APDU Received: 84D8018150E38DC8FEDD89C6DE48A1C7489CB8EFC83DC1EA0BBCB73E9782EA1593D9A0A327C12702E7EE179ABA888D265C4CAE637338B403B46E41A234564F0F7EC709770178EC32F019F251964C903753766E1DF4 
APDU Sent: 0329AD5106993C7EB2649000 
APDU Received: 00A404000BA00000030800001000010000 
APDU Sent: 9000 
APDU Received: 00A404000EE86086480186FA6B81480401010000 
APDU Sent: 9000 
APDU Received: 8050000008224CDDC4C29B22C3 
APDU Sent: 000033639D44CFB00C69030200013C56A721DAB51167FA4320F10AD59000 
APDU Received: 84820300101CBA1715E78B70BB20B2032845664977 
APDU Sent: 9000 
APDU Received: 8420000010C2CBE82EDE23A2984BFDAAC8843E150D 
APDU Sent: 9000 
APDU Received: 00A4040008A000000003000000FF 
APDU Sent: 9000 
APDU Received: 805000000885ADBAEFA751CAEB 
APDU Sent: 000033639D44CFB00C69030200025FA69462477F571EAA8F0C14AAE49000 
APDU Received: 848203001043D948E16FDD63A57FBB6E2EA6673EBB 
APDU Sent: 9000 
APDU Received: 00A404000BA00000030800001000010000 
APDU Sent: 9000 
APDU Received: 00A404000EE86086480186FA6B81480401010000 
APDU Sent: 9000 
APDU Received: 8050000008D15F65B2E12B8199 
APDU Sent: 000033639D44CFB00C6903020003048007A68010C2058992616E39529000 
APDU Received: 848203001080E36DC19999AB975320ADA23FEF51DD 
APDU Sent: 9000 
APDU Received: 8400000008309C052FC2AF518700 
APDU Sent: 0001000000020000000100000002000000000000000000000000000000000000000000000000000000000000000000000200FFFF0000000000000000000000009000 
APDU Received: 841600005841A76F1521DADCAD242B18F13335784DCD34C909C87EFD26D547AF69D00D2881E1CEC3189DC9DB27319B7EB1B454035A2FBF4F5BD453001DB0B95856C544AAEF89F1584495423780CE1209AAEB4F27DCA010CFA3955325FD 
APDU Sent: 9000 
APDU Received: 841E0000383D3B679C005602D2533321C5B0CB2BB8CB3E9110FDCE4B5990C84010C2EA71D0FF7FEAC9BE1487A72BBC29F52B7FD695FDB792BBE5A8ED78 
APDU Sent: 9000 
APDU Received: 841A0000080F66BDFF2FD3336F64 
APDU Sent: 30218001008101008201008301078401FF8501038601018701008801008901008A01009000 
APDU Received: 841A800008C14EECF30745521264 
APDU Sent: 30218001008101008201008301078401FF8501038601018701008801008901008A01009000 
APDU Received: 841A810008C6EE731C8374C0A264 
APDU Sent: 30218001008101008201008301078401FF8501038601018701008801008901008A01009000 
APDU Received: 8411010008B1DE5EA8BF8EDF90 
APDU Sent: 9000 
APDU Received: 841301000862299152D7711722 
APDU Sent: 9000 
APDU Received: 8412000018433687E78C0B7552BC3939CEF953881623F601ACC92A52C2 
APDU Sent: 9000 
APDU Received: 8417000008B8C7A9955878DDEB00 
APDU Sent: 7F4982010A8182010100BF32292317297991A0B8606A83DF743625BF5AC7708CE798D74DFCEEB13244D7F40CFCA3DEBC928F52CD868674477C52C3F2615B60EBDDAB6D6B4BD1855ADCE7FA0A45F42529571E32385F9E6485333D5CBF24656AF02AEC586FA4A85FA7CA11321106EDCBEDF51108726371BEDA3D75AB5D5F313D042EB0259890697EBE1D12ADFCCAF8477DDA4083AC53590202BF26388CD038D164AE3758CB1139DA9FDDFC74767C5C39DF0DCA5D91AB0C817DCBDDE35A535B6077644C76E74945EB2FA9F1E9365B1B5F91226719848CF365EA75381DFE319461688ACF317A4B49548CFFA71E593100EA9A245DB430FCE79497FD5E63C69398F8266112 

回答

0

好吧,這是任何人的使用。

Atlast APDU命令或緩衝區沒有問題。它與三星Galaxy S7(Android版本6.0.6),而不是Note 2或Nexus手機(4.4.X版本)運作良好。 4.4。X版本android手機無法發送整個字節,如果超過,它會截斷。

此鏈接可以解釋這個問題 https://code.google.com/p/android/issues/detail?id=76598

0

呈現的512個十六進制字符的數據意味着接收到256字節的緩衝區。

這可能是您的回覆緩衝區大小限制。首先,嘗試增加bytes[]數組大小,以使API將更長的緩衝區放入其中。

在回覆的TLV數據長於256距離TLV數據解析清楚:

TLVs:#"7F4982010A81820101009F80023FC39926A237680FFFF47060239F4D240C..6112" # EMV, Tag + Length + Value (TLV) series 
- x7F49:#"7F4982010A81820101009F80023FC39926A237680FFFF47060239F4D240C..6112" # ISO 7816, Template, Cardholder public key 
    - tag: "7F49" 
    - len: "82010A" # // 266 
    - val:#"81820101009F80023FC39926A237680FFFF47060239F4D240C1EBC424428..6112" 
    - x81:#"81820101009F80023FC39926A237680FFFF47060239F4D240C1EBC424428..6112" # ISO 7816, RSA Modulus (a number denoted as n coded on x bytes), or DSA First prime (a number denoted as p coded on y bytes), or ECDSA Prime (a number denoted as p coded on z bytes) 
     - tag: "81" 
     - len: "820101" # // 257 
     - val: " 
009F80023FC39926A237680FFFF47060239F4D240C1EBC424428965FADDBBD0BC3B2CB9BF8952AFF24135C5DCEA7931CEB0BF1406B57BE099DBF7F3A36FA6F20B9B244C1C4131CBFA1D088E1F2298845402B2505E28CA52403EFD09882C361A2F63C30C1FFA3160BAB9BE7CF64E1DA6066EEAAB995B3F627676E4FEF32F9FEA5534E472EBF990F7C964BB9FB36DFE995124AC80C306C796A22840A6FC3871508F1B5CCB063D4DDAD252AA9B4E13219ED4C5EA50FF2BBACA937BB0F9CF80472818AE49DE05E8B66D3863EEF3028325812958099C78CD65919A3660592A0BA5E966D6A01A3DD8242BDA5940146C07AE8475F35C88024DE566112" 

預期答覆長度:266個字節模板值的+ 3個字節長度的(0x82010A)+ 2字節標籤(0x7F49)+ 2字節,SW1SW2 = 273字節。

如果可以登錄,請提供APDU跟蹤信息。

作爲第二次嘗試,您可以發送Get Response APDU命令(指令「C0」)來讀取下一條回覆緩衝區。例如:

# 1st Get Response 
> 00 C0 00 00 00 
< you will get first 256 bytes 

# 2nd Get Response 
> 00 C0 00 00 00 
< you will get next 256 bytes or the rest of data 
+0

感謝您的答覆。我仍然不確定哪個緩衝區需要增加,它適用於通過藍牙和物理卡通過同一個NFC讀卡器的智能卡完全相同的命令。我是這個TLV數據解析的初學者,你如何通過查看數據來計算長度。例如:82010A的字符長度是多少? – ninja

+0

此外,爲了增加好奇心,我試圖解析這個TLV數據,它在這個鏈接中幾乎類似的錯誤err'd http://www.emvlab.org/tlvutils/ – ninja

+1

由於ASN.1 BER-TLV標籤長度可以用幾個字節編碼。 EMV情況下最多5個字節。如果字節1位8 == 1,那麼在位1-7中將存儲真實長度的後續字節的計數。例如,0x82010A分割爲 - 0x82表示擴展長度格式,後面跟隨2個長度字節。 Value的兩個字節0x010A = 266字節。作爲TLV解析器,我只能建議使用附加的EMV標籤描述來嘗試https://iso8583.info/lib/EMV/TLV。 –