Throw an error for incorrect CLAs

This commit is contained in:
Manuel Thalmann 2023-10-13 01:28:12 +02:00
parent 22b11b1ee8
commit 995ba68bdf

View file

@ -52,39 +52,43 @@ public class MyApplet extends Applet {
short length; short length;
byte[] buffer = apdu.getBuffer(); byte[] buffer = apdu.getBuffer();
byte instruction = buffer[ISO7816.OFFSET_INS]; if (buffer[ISO7816.OFFSET_CLA] != 0x80) {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
} else {
byte instruction = buffer[ISO7816.OFFSET_INS];
switch (instruction) { switch (instruction) {
case 0x00: case 0x00:
case 0x04: case 0x04:
byte[] response; byte[] response;
length = apdu.setOutgoing(); length = apdu.setOutgoing();
if (instruction == 0x00) { if (instruction == 0x00) {
response = AuthorName; response = AuthorName;
} else { } else {
response = storage; response = storage;
} }
if (length > response.length) { if (length > response.length) {
length = (short) response.length; length = (short) response.length;
} }
apdu.setOutgoingLength(length); apdu.setOutgoingLength(length);
apdu.sendBytesLong(response, (short) 0, length); apdu.sendBytesLong(response, (short) 0, length);
break; break;
case 0x02: case 0x02:
length = apdu.setIncomingAndReceive(); length = apdu.setIncomingAndReceive();
if (length > 20) { if (length > 20) {
// ToDo: Handle too much data. // ToDo: Handle too much data.
} else { } else {
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length); Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short) 0, length);
} }
break; break;
default: default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
break; break;
}
} }
} }
} }