Skip to content

Commit

Permalink
more tolerant SET NDEF
Browse files Browse the repository at this point in the history
  • Loading branch information
bitgamma committed Apr 4, 2019
1 parent c574944 commit 0d650d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/main/java/im/status/keycard/KeycardApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,17 @@ private void setNDEF(APDU apdu) {
}

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();
}

Expand Down
7 changes: 3 additions & 4 deletions src/test/java/im/status/keycard/KeycardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,9 @@ void setNDEFTest() throws Exception {
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
Expand Down

0 comments on commit 0d650d0

Please sign in to comment.