kaoh / globalplatform

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

Large STORE DATA impossible to send #94

Open antonio-fr opened 7 months ago

antonio-fr commented 7 months ago

Since a line is limited to 1024, and data is hex encoded, it is not possible to send data larger than ~490 bytes. The buffer size is defined at compile time, and hardcoded.

One of our own applet uses direct personalization and STORE DATA to setup a x509 certificate, which is around 600 bytes large. This is not possible to use a store_data command line to upload it using this software. This is sad, as this software correctly -and automatically- performs the commands chaining to send multiple data blocks. Also, the data buffer is set to 4096 bytes. But this is limited by this hard limit of 1024 bytes per command line.

We are using the standard input to send command lines to the binary exe. The issue is that it cuts the lines which are greater to 1024 bytes. What is after 1024 bytes, is seen as new line.

I think of several ways to solve this issue:

Technically, the main culprit seems to be here: https://github.com/kaoh/globalplatform/blob/4f26a8e30058d059aa6b7e7c8c65b07346f04494/gpshell/src/gpshell.c#L276 This is used in handleCommands, and also in handleOptions.

antonio-fr commented 7 months ago

It may also come from this part: https://github.com/kaoh/globalplatform/blob/4f26a8e30058d059aa6b7e7c8c65b07346f04494/gpshell/src/gpshell.c#L991 The parsed buffer "buf" is limited in size.

koh-osug commented 7 months ago

Hi Antonio, you are using the install_for_personalization and store_data -dataFormat format -dataEncryption encryption -data data command? I can look into increasing the buffer size then. Can you try to make your suggested changes (increase BUFLEN) and give it a try?

antonio-fr commented 7 months ago

No. I'm using direct perso store_data. More precisely, after selecting the applet (not SD), and opening a secure channel with it: store_data -dataFormat 0x08 -data xxxx

I didn't want to spend time to compile, I can give a quick try bc I have the VC tools and cmake already.

antonio-fr commented 7 months ago

I modified to #define BUFLEN 8192 and compiled (was not so hard). And store_data works with the 550 bytes payload (1200 bytes command line).

koh-osug commented 7 months ago

Great! I have pushed an update to main and the next release will contain the enhancement.