Monday 15 August 2011

smartcard - Reading big file from a javacard applet -


I am writing an applet that stores 5 kb, 7 kb and 11 kb in 3 different sizes. I have no problem storing the files inside the applet. But when I try to read them back, I can only read the first two (small files). The third file throws an exception:

  javax.smartcardio.CardException: could not receive a response to the sun. Security. Smartcardio Sun.security.smartcardio.ChannelImpl on ChannelImpl.Dotrmansmit (unknown source). Sent (unknown source)   

I have tried to detect this problem and I have found that it has to do with file size. So I created a test file size of 7 and extended this file bit by bit. By the time I reached 7905 byte, I worked. This means that the maximum number of bytes 795 bytes can be read from applet. I'm handling responses using the sample code:

  public void readFile (APDU apdu, short [] offset, short selectFile, short MAX_APDU_SEN, byte OFFSET_SENT) {byte [] file = GetFile (selectedFile); If (file == null) {+ ISOException.throwIt (ISO7816.SW_FILE_NOT_FOUND); +} // How many bytes work to send at this time and how much will remain = (small) (file.length - offset [OFFSET_SENT]); Boolean chain = staying & gt; MAX_APDU_SEN; Less sendLen = Chain? MAX_APDU_SEN: stay; Apdu.setOutgoing (); Apdu.setOutgoingLength (sendLen); Apdu.sendBytesLong (file, offset [OFFSET_SENT], sendLen); // Check to see if more APDU is to send if (chain) {+ offset [OFFSET_SENT] = transmitted lane; // bytes were sent to ISOException.throwIt (ISO7816.SW_BYTES_REMAINING_00); // indicate that there are more bytes to come} and {+ offset [OFFSET_SENT] = 0; // to send and no bytes}}   

I have tried two different types of cards i.e. Jesse 2.2.1 (36 KB) and Jesse 2.2.2 (80 KB) ) Compatible cards, but they all behave the same.

Any help please?

Generally chaining is not used by reading a file, because the host application is easily Specify offset starting at P1 / P2 - as specified in ISO 7816-4 in at least one read binaries command. I believe, even for a chain reaction, the card wants to prepare data in the buffer, whose limited size I consider the cause of your problem.

No comments:

Post a Comment