Reputation: 53
I set up my Android to work over NFC to send APDU commands back and forth. One of the APDU response bytes is truncated some how.
The response bytes as printed in the log statements just before HostAPDUService.sendResponseApdu(bytes[])
is this
I/NfcService: Notifying listener status: DEBUG_APDU_SENT data:7F4982010A81820101009F80023FC39926A237680FFFF47060239F4D240C1EBC424428965FADDBBD0BC3B2CB9BF8952AFF24135C5DCEA7931CEB0BF1406B57BE099DBF7F3A36FA6F20B9B244C1C4131CBFA1D088E1F2298845402B2505E28CA52403EFD09882C361A2F63C30C1FFA3160BAB9BE7CF64E1DA6066EEAAB995B3F627676E4FEF32F9FEA5534E472EBF990F7C964BB9FB36DFE995124AC80C306C796A22840A6FC3871508F1B5CCB063D4DDAD252AA9B4E13219ED4C5EA50FF2BBACA937BB0F9CF80472818AE49DE05E8B66D3863EEF3028325812958099C78CD65919A3660592A0BA5E966D6A01A3DD8242BDA5940146C07AE8475F35C88024DE566112
But at the receiving end I see only first 4 chars received and there by failing the app APDU Response:
SW=7F49 (No translation available), Nr=0, APDU Response Bytes: 7f 49
Any idea why this could be? Is this due to extendedAPDU capability? https://code.google.com/p/android/issues/detail?id=76598
Attached the entire APDU command trace until it failed. Please note that the same code works for any other interface (like over bluetooth,physical card) etc., just not with NFC Android (HostAPDUService).
I see I can't override the HostAPDUService.sendResponseAPDU so I can't find where the truncation happens. I am sure before I send to this method, my response bytes is not truncated.
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
Upvotes: 0
Views: 2079
Reputation: 53
Ok this is for anyone's use.
Atlast there is nothing wrong with the APDU commands or the buffer. It worked well with Samsung Galaxy S7 (Android version 6.0.6), not the Note 2 or Nexus phones (4.4.X versions). The 4.4.X version android phones fails to send the entire bytes,it truncates if exceeded.
This link may explain the issue https://code.google.com/p/android/issues/detail?id=76598
Upvotes: 0
Reputation: 2270
The presented data of 512 Hexadecimal chars meant the buffer of 256 bytes was received.
It is probably your reply buffer size limitation. At first, try to increase the bytes[]
array size to let API put longer buffer into it.
The TLV data in the reply is longer than 256. It is clear from TLV data parsing:
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"
The expected reply length: 266 bytes of Template Value + 3 bytes of Length (0x82010A
) + 2 bytes Tag (0x7F49
) + 2 bytes for SW1SW2 = 273 bytes.
Please provide APDU traces if you can log it.
As second try you may send Get Response APDU Command (Instruction "C0") to read next piece of Reply buffer. Something like:
# 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
Upvotes: 0