Skip to content

Commit

Permalink
Non-extlen broken after 88f4179
Browse files Browse the repository at this point in the history
The logic added for JC221 was incorrectly sign-extending the
value of Lc.
  • Loading branch information
arekinath committed May 29, 2020
1 parent f984e3b commit 339e473
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/net/cooperi/pivapplet/PivApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,15 @@ public class PivApplet extends Applet
return (false);
}

/*#if !APPLET_EXTLEN
private short
getIncomingLengthCompat(final APDU apdu)
{
final byte[] buf = apdu.getBuffer();
return ((short)((short)buf[ISO7816.OFFSET_LC] & 0x00FF));
}
#endif*/

private void
lockPINAlwaysSlots()
{
Expand Down Expand Up @@ -948,7 +957,7 @@ else if (key == (byte)0x81)
//#if APPLET_EXTLEN
final short lc = apdu.getIncomingLength();
/*#else
final short lc = buf[ISO7816.OFFSET_LC];
final short lc = getIncomingLengthCompat(apdu);
#endif*/
if (recvLen != lc) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
Expand Down Expand Up @@ -1019,7 +1028,7 @@ else if (key == (byte)0x81)
//#if APPLET_EXTLEN
final short inLc = apdu.getIncomingLength();
/*#else
final short inLc = buffer[ISO7816.OFFSET_LC];
final short inLc = getIncomingLengthCompat(apdu);
#endif*/
if (lc != inLc) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
Expand Down Expand Up @@ -1588,7 +1597,7 @@ else if (key == (byte)0x81)
//#if APPLET_EXTLEN
final short inLc = apdu.getIncomingLength();
/*#else
final short inLc = buffer[ISO7816.OFFSET_LC];
final short inLc = getIncomingLengthCompat(apdu);
#endif*/
if (lc != inLc) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
Expand Down Expand Up @@ -2261,7 +2270,7 @@ else if (key == (byte)0x81)
//#if APPLET_EXTLEN
final short inLc = apdu.getIncomingLength();
/*#else
final short inLc = buffer[ISO7816.OFFSET_LC];
final short inLc = getIncomingLengthCompat(apdu);
#endif*/
if (lc != inLc) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
Expand Down Expand Up @@ -2342,7 +2351,7 @@ else if (key == (byte)0x81)
//#if APPLET_EXTLEN
final short inLc = apdu.getIncomingLength();
/*#else
final short inLc = buffer[ISO7816.OFFSET_LC];
final short inLc = getIncomingLengthCompat(apdu);
#endif*/
if (lc != inLc) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
Expand Down Expand Up @@ -2414,7 +2423,7 @@ else if (key == (byte)0x81)
//#if APPLET_EXTLEN
final short inLc = apdu.getIncomingLength();
/*#else
final short inLc = buffer[ISO7816.OFFSET_LC];
final short inLc = getIncomingLengthCompat(apdu);
#endif*/
if (lc != inLc) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
Expand Down Expand Up @@ -2677,7 +2686,7 @@ else if (key == (byte)0x81)
//#if APPLET_EXTLEN
final short inLc = apdu.getIncomingLength();
/*#else
final short inLc = buffer[ISO7816.OFFSET_LC];
final short inLc = getIncomingLengthCompat(apdu);
#endif*/
if (lc != inLc) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
Expand Down

0 comments on commit 339e473

Please sign in to comment.