more tolerant SET NDEF

This commit is contained in:
Michele Balistreri 2019-04-04 11:27:20 +03:00
parent c574944153
commit 0d650d0838
2 changed files with 9 additions and 6 deletions

View File

@ -463,13 +463,17 @@ public class KeycardApplet extends Applet {
}
short dataLen = Util.makeShort((byte) 0x00, apduBuffer[ISO7816.OFFSET_LC]);
short offset;
if (Util.makeShort(apduBuffer[ISO7816.OFFSET_CDATA], apduBuffer[(short)(ISO7816.OFFSET_CDATA + 1)]) != (short)(dataLen - 2)) {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
offset = ISO7816.OFFSET_P2;
apduBuffer[ISO7816.OFFSET_P2] = 0;
} else {
offset = ISO7816.OFFSET_CDATA;
}
JCSystem.beginTransaction();
Util.arrayCopy(apduBuffer, ISO7816.OFFSET_CDATA, SharedMemory.ndefDataFile, (short) 0, dataLen);
Util.arrayCopy(apduBuffer, offset, SharedMemory.ndefDataFile, (short) 0, dataLen);
JCSystem.commitTransaction();
}

View File

@ -498,10 +498,9 @@ public class KeycardTest {
response = cmdSet.setNDEF(ndefData);
assertEquals(0x9000, response.getSw());
// Wrong length
ndefData[1]++;
response = cmdSet.setNDEF(ndefData);
assertEquals(0x6A80, response.getSw());
// Good case with no length.
response = cmdSet.setNDEF(Arrays.copyOfRange(ndefData, 2, ndefData.length));
assertEquals(0x9000, response.getSw());
}
@Test