Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCID_Receive() Can't read all data 49xyzkbytes #66

Closed
vjardin opened this issue Mar 27, 2020 · 1 comment
Closed

CCID_Receive() Can't read all data 49xyzkbytes #66

vjardin opened this issue Mar 27, 2020 · 1 comment

Comments

@vjardin
Copy link

vjardin commented Mar 27, 2020

Some PKCS11 smart cards return some trailing 00 so we get this error,
CCID_Receive() Can't read all data 49174kbytes
that lead to a failure of this test:

/* we have read less (or more) data than the CCID frame says to contain */

if (length-10 != dw2i(cmd, 1))

In fact, we should tolerate that the length is valid as long as we have enough payload, so it could become:
if (length-10 != dw2i(cmd, 1))

Without this patch, the following reader could not support some PKCS11 smart cards:

  • Gemalto (was Gemplus) GemPC Twin
  • Alcor Micro Corp. AU9540
  • Feitian R502

Once it gets applied, they work fine.

The same fix was validated on some ACR with their CCID:
acshk/acsccid@e23befb

vjardin added a commit to vjardin/CCID that referenced this issue Mar 27, 2020
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.

This fix has been tested with:
  - Gemalto (was Gemplus) GemPC Twin
  - Alcor Micro Corp. AU9540
  - Feitian R502

Suggested-by: @godfreychung
Fix: issue LudovicRousseau#66
@LudovicRousseau
Copy link
Owner

The discussion happens in the PR #67
So closing this issue.

vjardin added a commit to vjardin/CCID that referenced this issue Aug 3, 2020
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.

This fix has been tested with:
  - Gemalto (was Gemplus) GemPC Twin
  - Alcor Micro Corp. AU9540
  - Feitian R502

Suggested-by: @godfreychung
Fix: issue LudovicRousseau#66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants