acshk / acsccid

acsccid is a PC/SC driver for Linux/Mac OS X and it supports ACS CCID smart card readers. This library provides a PC/SC IFD handler implementation and communicates with the readers through the PC/SC Lite resource manager (pcscd).
GNU Lesser General Public License v2.1
106 stars 19 forks source link

CCID: Fix misleading read length #20

Closed vjardin closed 4 years ago

vjardin commented 4 years ago

Currently, when some extended APDU are processed, we get the following error: CCID_Receive() Can't read all data 49174kbytes

In fact, the processing of the length of the APDU is not correct. For example: 00000002 commands.c:1726:CmdXfrBlockAPDU_short() T=0: 9 bytes 00000003 -> 000000 6F 09 00 00 00 00 2D 00 00 00 00 A4 09 04 04 3F 00 D0 03 00033873 <- 000000 80 02 00 00 00 00 2D 00 00 00 61 27 00 00 00 00 00 00 00 [...] 00002330 commands.c:1682:CCID_Receive() Can't read all data (49174 out of 2 expected)

According to the log, the response should be correct but the reader may add too many zeros to the response. The actual response APDU is 61 27. If we check the complete logs/dumps, all the payload till the end is full of 00 .. 00.

In fact, the check of the length of the data should be less strict. Let's be tolerant as along as we get enough payload.

Suggested-by: @godfreychung Fix: issue #19