What is the alternative of ISO7816.SW_PIN_REQUIRED in JavaCard 2.2.2? -
i using javacard 2.2.2.
the following program not working,because, iso7816.sw_pin_required
not finding library resolve itself.
how can replace iso7816.sw_pin_required
other constant make program run?
package monpackage; import javacard.framework.*; //import javacardx.framework.*; public class wallet extends applet { /* constants declaration */ // code of cla byte in command apdu header final static byte wallet_cla =(byte)0xb0; // codes of ins byte in command apdu header final static byte deposit = (byte) 0x10; final static byte debit = (byte) 0x20; final static byte balance = (byte) 0x30; final static byte validate = (byte) 0x40; // maximum number of incorrect tries before // pin blocked final static byte pintrylimit =(byte)0x03; // maximum size pin final static byte maxpinsize =(byte)0x04; // status word (sw1-sw2) signal // balance becomes negative; final static short sw_negative_balance = (short)0x6910; /* instance variables declaration */ ownerpin pin; byte balance; byte buffer[]; // apdu buffer private wallet() { // programming practice allocate // memory applet needs during // lifetime inside constructor pin = new ownerpin(pintrylimit, maxpinsize); balance = 0; register(); } // end of constructor public static void install(apdu apdu) { // create wallet applet instance new wallet(); } // end of install method public boolean select() { // reset validation flag in pin object // false pin.reset(); // returns true jcre indicate // applet ready accept incoming apdus. return true; }// end of select method public void process(apdu apdu) { // apdu object carries byte array (buffer) // transfer incoming , outgoing apdu header // , data bytes between card , cad buffer = apdu.getbuffer(); // verify if applet can accept // apdu message if (buffer[iso7816.offset_cla] !== wallet_cla) { isoexception.throwit(iso7816.sw_cla_not_supported); } switch (buffer[iso7816.offset_ins]) { case balance: getbalance(apdu); return; case debit: debit(apdu); return; case deposit: deposit(apdu);return; case validate: validate(apdu);return default: isoexception.throwit(iso7816.sw_ins_not_supported); } } // end of process method private void deposit(apdu apdu) { // access authentication if ( ! pin.isvalidated() ) isoexception.throwit (iso7816.sw_pin_required); // lc byte denotes number of bytes in // data field of comamnd apdu byte numbytes = (byte) (buffer[iso7816.offset_lc]); // indicate apdu has incoming data , // receive data starting offset // iso.offset_cdata byte byteread = (byte)(apdu.setincomingandreceive()); // error if number of data bytes // read not match number in lc byte if (byteread != 1) isoexception.throwit(iso7816.sw_wrong_length); // increase balance amount specified // in data field of command apdu. balance = (byte) (balance + buffer[iso7816.offset_cdata]); // return return; } // end of deposit method private void debit(apdu apdu) { // access authentication if ( ! pin.isvalidated() ) isoexception.throwit(iso7816.sw_pin_required); byte numbytes = (byte)(buffer[iso7816.offset_lc]); byte byteread = (byte)(apdu.setincomingandreceive()); if (byteread != 1) isoexception.throwit(iso7816.sw_wrong_length); // balance can not negative if ( ( balance - buffer[iso7816.offset_cdata]) < 0 ) isoexception.throwit(sw_negative_balance); balance = (byte) (balance - buffer[iso7816.offset_cdata]); } // end of debit method private void getbalance(apdu apdu) { // access authentication if ( ! pin.isvalidated() ) isoexception.throwit(iso7816.sw_pin_required); // inform system applet has finished // processing command , system should // prepare construct response apdu // contains data field apdu.setoutgoing(); //indicate number of bytes in data field apdu.setoutgoinglength((byte)1); // move data apdu buffer starting // @ offset 0 buffer[0] = balance; // send 1 byte of data @ offset 0 in apdu // buffer apdu.sendbytes((short)0, (short)1); } // end of getbalance method private void validate(apdu apdu) { // retrieve pin data requires // valid ated. user interface data // stored in data field of apdu byte byteread = (byte)(apdu.setincomingandreceive()); // validate user interface , set // validation flag in user interface // object true if validation. // succeeds. if user interface validation // fails, pinexception thrown // pin.check() method. pin.check(buffer, iso7816.offset_cdata, byteread); } // end of validate method } // end of class wallet
check out java card 2.2.2 api specifications - iso7816 interface again. :)
you see there no field named sw_pin_required
in interface. can add following line in constant declaration section of program, , replace iso.sw_pin_required
sw_pin_required
.
final static short sw_pin_required = 0x6968
moreover can use following defined fields of iso7816
instead of undefined field sw_pin_required
:
iso7816.sw_conditions_not_satisfied
or
iso7816.sw_security_status_not_satisfied
btw these special short values defined in specifications , not forced use same values in program. example iso7816.sw_security_status_not_satisfied
replace 0x6982
(as mentioned in api spec) in compilation time compiler, , see value when communicating applet on card. can define special status words instead of using these values (not recommended).
edit: (thanks mr bodewes)
as mr bodewes said in comments, recommended keep possible status word ranges defined in iso/iec 7816 - 3 standard , 4. if don't may run trouble, t=0 (byte oriented contact mode) operation.
from 7816-3: "if value '6x' or '9x', except '60', sw1 byte. requests no action on data transfer. interface device shall wait character conveying sw2 byte. there no restriction on sw2 value.". needs 6x or 9x compatible t=0.
Comments
Post a Comment