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

Length of Install Parameters field is not coded correctly for install_for_install #92

Open
davidmru opened this issue Mar 14, 2024 · 7 comments

Comments

@davidmru
Copy link

The length of the parameters field is not coded as ber-len in the command install_for_install
Ref 11.5.2.3.2 Data Field for INSTALL [for install]
GlobalPlatform Technology
Card Specification
Version 2.3.1
image

@koh-osug
Copy link

Only a single byte is used which is good enough for 128 bytes. So far this was always sufficient. Do you have a card supporting more? Then I would need one to verify a patch for this.

@davidmru
Copy link
Author

I have an applet which install Parameters field is more than 128 bytes (147 0x93).
The install for install command is successful when the Length is coded as berlen (8193).
I have a card which accept Length of Install Parameters field > 0x80

@koh-osug
Copy link

So, this means you have already patched the source code? Can you please share the code snippet?

@davidmru
Copy link
Author

No, I built the apdu command install for install manually, then I used the command send_apdu to send it to the card.
However I checked the source code [ https://github.com/kaoh/globalplatform/blob/master/globalplatform/src/globalplatform.c#L3261 ]
I think the correction below might solve the issue:

//[line 3291] buf[i++] = 0x02; // install parameter field length hiByte = 0x02; // tag C9 + length byte (C9LL) if (installParametersLength > 0) { hiByte += (BYTE)installParametersLength; } if (uiccSystemSpecParamsLength > 0) { hiByte += 2; hiByte += (BYTE)uiccSystemSpecParamsLength; }
if (nonVolatileDataSpaceLimit > 0 || volatileDataSpaceLimit > 0 || simSpecParamsLength > 0) {
	hiByte += 2; // 0xEF LL
}
if (nonVolatileDataSpaceLimit > 0) {
	hiByte += 4;
}
if (volatileDataSpaceLimit > 0) {
	hiByte += 4;
}
if (simSpecParamsLength > 0) {
	hiByte += (BYTE)simSpecParamsLength + 2;
}

//Set Length of Install Parameters field
if(hiByte > 255){
buf[i++] = 0x82
buf[i++] = hiByte >> 8;
buf[i++] = hiByte & 0x00FF;
}else if(hiByte > 127){
buf[i++] = 0x81;
buf[i++] = hiByte;
}else{
buf[i++] = hiByte;
}

But I have not tested

@koh-osug
Copy link

I have pushed a fix to the branch https://github.com/kaoh/globalplatform/tree/install_params_size. Do you need a binary to test it or can you compile it on your own for testing it?
The README in https://github.com/kaoh/globalplatform/tree/install_params_size should give the instructions how to build it, Windows build be more involved.

@davidmru
Copy link
Author

I checked the fix, I noticed that it is the Application Specific Parameters (tag C9) which length has been coded as ber-tlv.
However the tag C9 should never be greater than (127 - LV(ControlInfo) - LV(InstanceAID) [ see install method ] . May be the comment:
hiByte = 0x02; // tag C9 + length byte (C9LL) in the snippet I posted is confusing. The value 02 represent the tag and the length byte of the tag C9.

The length which has to be corrected is the length of the parameters field (see table 11-43 in the first post). The table below show the content of the parameters field:
image
REF:
GlobalPlatform Technology
Card Specification
Version 2.3.1

@koh-osug
Copy link

Next try. Pushed an update.

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