Here are my code.
Code: Select all
package cp.sampleapplet;
import javacard.framework.*;
public class Epurse extends Applet {
private short balance;
public static final byte CLA = (byte)0x80;
public static final byte insCredit = (byte)0xA1;
public static final byte insDebit = (byte)0xA2;
public static final byte insGetBalance = (byte)0xA3;
public static final byte insSetPin = (byte)0xB1;
public static final byte insGetAuth = (byte)0xB2;
public static final byte insDelog = (byte)0xB3;
OwnerPIN pin;
public boolean select () {
return (true);
}
public void deselect(){
pin.reset();
}
public Epurse() {
super();
this.balance = 0;
pin = new OwnerPIN((byte)3, (byte)8);
pin.update( new byte[] {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}, (byte)0, (byte)4); //default PIN is 00 00 00 00
}
public static void install (byte [] bArray, short bOffset, byte bLength ) throws ISOException {
Epurse = new Epurse();
s.register();
}
public void process(APDU apdu) throws ISOException{
byte[] buffer = apdu.getBuffer();
if (selectingApplet()) return;
if(buffer[0]!=CLA) ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
ISOException.throwIt(ISO7816.SW_FILE_INVALID);
switch (buffer[ISO7816.OFFSET_INS]){
case insCredit :
if(pin.isValidated()) credit(apdu, buffer);
else
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);
break;
case insDebit :
if(pin.isValidated())
debit(apdu, buffer);
else
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);//6986
break;
case insGetBalance :
if(pin.isValidated())
getbal(apdu, buffer);
else
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);//6986
break;
case insGetAuth :
checkPIN(apdu, buffer);
break;
case insSetPin :
if(pin.isValidated())
setPIN(apdu, buffer);
else
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);//6986
break;
case insDelog :
pin.reset();
break;
default:
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);//6986
}
}
private void credit(APDU apdu, byte[] buffer ) {
}
private void debit(APDU apdu, byte[] buffer ) {
}
private void getbal(APDU apdu, byte[] buffer) {
}
private void checkPIN(APDU apdu, byte[] buffer){
short Le = apdu.setIncomingAndReceive();
byte[] data = new byte[Le];
try{
for (short i=0; i<Le; i++)
{
data[i] = buffer[(short)(i+ISO7816.OFFSET_CDATA)];
}
if (pin.check(data, (short)0, (byte)Le)) return;
else
ISOException.throwIt(ISO7816.SW_RECORD_NOT_FOUND);//6A83 //6985->SW_CONDITIONS_NOT_SATISFIED
} catch(NullPointerException e) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED); //6982
} catch(ArrayIndexOutOfBoundsException a) {
ISOException.throwIt(ISO7816.SW_FILE_FULL); //6A84
}
}
private void setPIN(APDU apdu, byte[] buffer){
}
}
When I sent APDU command 80 B2 00 00 04 01 02 03 04 to verify the PIN, it fails with status word 0x6983.
But I cant find where caused this problem. Does anyone help to figure out it ?