My first silly and card-killing mistake (as I think) was following:
Code: Select all
// In Applet class
private static byte[] bLog;
private static short logNewIndex = 0x0;
In Applet's install() was:
Code: Select all
bLog = new byte[15000];
for (short i = 0; i < 15000; i++) {
bLog[i] = 0x0;
}
logNewIndex = 0x0;
And, in process(), in different code nodes, I:
Code: Select all
//
// ...clearing it
byte[] buffer = apdu.getBuffer();
...
// Here is NO apdu.setIncomingAndReceive(); call
for (short i = 0; i < 15000; i++) {
bLog[i] = 0x0;
}
logNewIndex = 0;
le = apdu.setOutgoing();
apdu.setOutgoingLength( (short)4 );
buffer[0] = (byte)'O'; buffer[1] = (byte)'K'; buffer[2] = (byte)'A'; buffer[3] = (byte)'Y';
apdu.sendBytes ( (short)0 , (short)4 );
//
// ...writing it record-by-record to response
byte[] buffer = apdu.getBuffer();
...
// Here is NO apdu.setIncomingAndReceive(); call
du.setOutgoing();
//if (le < (short)2) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH );
apdu.setOutgoingLength( (short)200 );
byte bId = buffer[6];
for (short i = 0; i < 200; i++) {
buffer[i] = bLog[(short)((bId * (short)300) + i)];
}
apdu.sendBytes ( (short)0 , (short)200 );
return;
How I installing applet? Unfortunately I did not found some IDE plugin for so old platform or guide how to configure it, therefore I installing my applet with GPShell. As following:
Code: Select all
mode_211
enable_trace
enable_timer
establish_context
card_connect
select -AID a000000003000000
open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f // Keys are default
delete -AID ***
install -file Applet\javacard\Applet.cap -nvDataLimit 2000 -instParam 00 -priv 4
card_disconnect
release_context
-priv 4 is for installing as default.
And there are phantomous bugs!!!
I clearing my static byte[].
I requesting it to response - it is clear.
I disconnecting the card, connecting again.
I requesting again = bingo, it is full!
I deleting applet (and even no applets on card at all) and installing - clear. Re-connecting - full! Now it is full with info which just cannot be on the card. Applet is removed, and I used another PC and cardreader.
Moreover, the length of fillage is random for every time.
It just becomes not re-writeable. I trying rewrite it all possible ways, but no effect.
One of first tries was removing of the "static" modifier and place variables init into class' constructor. No effect.
Unfortunately I have not another card to just test new code on it.
But... I just reinstalled applet with -priv 2 - and no problems more...
Also I tried it many times before changed to -priv 4 and it was working. But non-default applet is not good solution because I need 3 selectable files, and this way I need 3 applets...
What should I do with this card? Is it because of static fields, or another? How to clean this card?