i made java card classic applet using netbeans
when i program the read operation i check for the first byte in the APDU to be 0x80 then the second to be 0xB0
then take the offset that i will read from in the file from the byte 2 and 3 then take the number of bytes to be read from byte 4
to be the APDU as the default one
0x80 0xB0 0x00 0x03 0x60
this read 60 bytes from the current file starting by offset number 3
when i try this command it returned error Input data length != Lc around line 12
.
after some retrying i find the problem
the problem is that the compiler assume that byte 4 is the length of data so in my command he wait for 60 bytes
when i search i find that byte 4 does not mean the sending data length when the INS=B0
i do not know why it made like this and when i try to debug the compiler did not enter the process function even.
my script file is
0x00 0xA4 0x04 0x00 0X06 0X87 0XF1 0X3F 0X5E 0X22 0X47 0x7F;
0x80 0xA4 0x00 0x00 0x02 0x3F 0x00 0x7F;
0x80 0xA4 0x00 0x00 0x02 0x50 0x15 0x7F;
0x80 0xA4 0x00 0x00 0x02 0x53 0x00 0x7F;
0x80 0xA4 0x00 0x00 0x02 0x50 0x31 0x7F;
0x80 0xB0 0x00 0x00 0x33 0x7F ;
powerdown;
the read function is
void read(APDU apdu)
{
if(current.isDF())//can not read DF file
{
ISOException.throwIt((short)27014);
}
EFile f = (EFile)current;
byte[]data=apdu.getBuffer();
short offset = Util.getShort(data, (short)2);
if(offset < 0 || offset > f.length)//can not read
{
ISOException.throwIt((short)27270);
}
data=apdu.getBuffer();
short len = (short)(data[4]&0xFF);
if(offset + len > f.length)//can not read
{
ISOException.throwIt((short)26368);
}
apdu.setOutgoing();
apdu.setOutgoingLength(len);
apdu.sendBytesLong(f.data, (short)(f.offset + offset),len);//return the data
}
the first one to select the program and then select files and then try to read data that is not work
but if i do
0x80 0xB0 0x00 0x00 0x02 0x00 0x00
it read 2 bytes write from offset 0 although the final 0x00 0x00
is not used even in the standard
my problem why i must to but data in the command to be as length of the data needed to be red
how can i fix this error?
ISO7816
class for the constants, usingdata[4]
instead ofsetOutgoing()
, and using hard coded literals instead of constants. You may find a lot about this in the ubiquitous (now slightly dated) Java Card book – Maarten Bodewes