-
-
Notifications
You must be signed in to change notification settings - Fork 239
Open
Description
With SCP02, trying to send an extended length APDU (> 255 bytes) with GPSession.transmit() always results in IllegalArgumentException:
java.lang.IllegalArgumentException: Invalid APDU: length=261, b1=0, b2||b3=55810
at apdu4j.CommandAPDU.parse(CommandAPDU.java:337)
at apdu4j.CommandAPDU.<init>(CommandAPDU.java:92)
at pro.javacard.gp.SCP02Wrapper.wrap(SCP02Wrapper.java:163)
at pro.javacard.gp.GPSession.transmit(GPSession.java:514)
With SCP03 everything works fine.
It appears, that the SCP02Wrapper doesn't know how to deal with 3-byte lenghts (Nc) in APDUs. Both when composing a partial APDU for the MAC calculation, and when composing the final APDU, it does this:
// Construct new APDU
t.write(newCLA);
t.write(origINS);
t.write(origP1);
t.write(origP2);
if (newLc > 0) {
t.write(newLc); // <-- this works only with single-byte lengths
t.write(newData);
}
The code in SCP03Wrapper is aware of extended lengths:
bo.write(command.getINS());
bo.write(command.getP1());
bo.write(command.getP2());
bo.write(GPUtils.encodeLcLength(lc, command.getNe())); // <-- encodes Lc properly
bo.write(data);
Is there a reason to not support extended length APDUs with SCP02?
Metadata
Metadata
Assignees
Labels
No labels