kaoh / globalplatform

C library + command-line for Open- / GlobalPlatform smart cards
https://kaoh.github.io/globalplatform/
Other
72 stars 30 forks source link

Increasing max receive apdu length to 64K #39

Closed dmercer-google closed 3 years ago

dmercer-google commented 3 years ago

Increases the max received APDU length for send_apdu and get_data to 64k. This addresses the issue where PCSC (at least on a Mac) was seg faulting when the response consists of chained APDUs

kaoh commented 3 years ago

The GP spec 2.3.1, sect. 1.3.2 only allows short APDUs for GET DATA. The whole internal code is handling Lc and Le only for short APDUs. Just increasing the buffer size should not help in general. Can you please give an example when this is failing?

dmercer-google commented 3 years ago

The GP spec 2.3.1, sect. 1.3.2 only allows short APDUs for GET DATA. The whole internal code is handling Lc and Le only for short APDUs. Just increasing the buffer size should not help in general. Can you please give an example when this is failing?

Good catch. I have reverted the change to get_data.

kaoh commented 3 years ago

Great. I will take care of the extended APU support then also in the PC/SC connection layer to make this complete. I assume you are talking about extended APDUs when saying "chained APDU"?

dmercer-google commented 3 years ago

Great. I will take care of the extended APU support then also in the PC/SC connection layer to make this complete. I assume you are talking about extended APDUs when saying "chained APDU"?

Yup, it happens with Extended APDUs responding to a send_apdu. As far as I can tell the seg fault was happening in Apples PCSC layer so it may not be something we can fix. Looks like they were not checking the size of the buffer that was being passed and were writing past it.

kaoh commented 3 years ago

Which of the cards have you used for extended APDUs? A NXP or Infineon? I might have access to a MacOS Catalina, where I could replicate this issue.

dmercer-google commented 3 years ago

NXP.