Announce two new product: SmartCard Reader Rockey200 and USB2.0 Extension Cable

ROCKEY 200 is a handy and portable USB Smart Card reader that can perform read/write operations on any ISO 7816-1/2/3/4 smart cards which are compatible with protocol T=0 and T=1.

USB2.0 Extension Cable With high speed USB 2.0 devices such as USB token ,USB Card Reader and so on.

Come to try it now!

Wallet Applet, I can not select it !!!

Applets Development Guide

Moderator: product

OSSAMA
Posts: 3
Joined: Sun Mar 19, 2017 8:54 am
Points: 102
Contact:

Wallet Applet, I can not select it !!!

Postby OSSAMA » Tue May 22, 2018 7:37 am

hello everone,
I am new to the java card.
I start to learn about it by implmenting the wallet applet. but when I tried to select the applet by sending
>> /select 112233445500
>> 00 A4 04 00 06 11 22 33 44 55 00 00
I got the R-APDU
<< 6A 82 File or application not found
I have checked the AID and it is the same. any suggestion how to select the applet.
by the way, I am using JCIDE without card.
this is the code which I am using now.
best regards




Code: Select all

package bank.purse;
import javacard.framework.*;
//import javacardx.framework.*;
public class Wallet extends Applet {
     /* constants declaration */
  // code of CLA byte in the command APDU header
  final static byte Wallet_CLA =(byte)0x80;
    // codes of INS byte in the command APDU header
  final static byte VERIFY = (byte) 0x20;
  final static byte CREDIT = (byte) 0x30;
  final static byte DEBIT = (byte) 0x40;
  final static byte GET_BALANCE = (byte) 0x50;
  // maximum balance
 
  final static short MAX_BALANCE = 0x7FFF;
 
  // maximum transaction amount
 
  final static byte MAX_TRANSACTION_AMOUNT = 127;
  // maximum number of incorrect tries before the
  // PIN is blocked
  final static byte PIN_TRY_LIMIT =(byte)0x03;
 
  // maximum size PIN
  final static byte MAX_PIN_SIZE =(byte)0x08;
  // signal that the PIN verification failed
  final static short SW_VERIFICATION_FAILED = 0x6300;
   
  // signal the PIN validation is required
  // for a credit or a debit transaction
  final static short SW_PIN_VERIFICATION_REQUIRED = 0x6301;
   
  // signal invalid transaction amount
  // amount > MAX_TRANSACTION_MAOUNT or amount < 0
  final static short SW_INVALID_TRANSACTION_AMOUNT = 0x6A83;
   
  // signal that the balance exceed the maximum
  final static short SW_EXCEED_MAXIMUM_BALANCE = 0x6A84;
   
  // signal the balance becomes negative
  final static short SW_NEGATIVE_BALANCE = 0x6A85;
    /* instance variables declaration */
  OwnerPIN pin;
  short balance;
  private Wallet (byte[] bArray, short bOffset, byte bLength){
   
    // It is good programming practice to allocate
    // all the memory that an applet needs during
    // its lifetime inside the constructor
    pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);
   
    // The installation parameters contain the PIN
    // initialization
    pin.update(bArray, bOffset, bLength);
    register();
  } // end of the constructor
   public static void install(byte[] bArray, short bOffset, byte bLength) {
    // create a Wallet applet instance
    new Wallet(bArray, bOffset, bLength);
  } // end of install method
  public boolean select() {
    // The applet declines to be selected
    // if the pin is blocked.
    if ( pin.getTriesRemaining() == 0 ) return false;
    return true;
  }// end of select method
   public void deselect() {
    // reset the pin value
    pin.reset();
  }
   public void process(APDU apdu) {
    // APDU object carries a byte array (buffer) to
    // transfer incoming and outgoing APDU header
    // and data bytes between card and CAD
    // At this point, only the first header bytes
    // [CLA, INS, P1, P2, P3] are available in
    // the APDU buffer.
    // The interface javacard.framework.ISO7816
    // declares constants to denote the offset of
    // these bytes in the APDU buffer
    byte[] buffer = apdu.getBuffer();
     // check SELECT APDU command
    if ((buffer[ISO7816.OFFSET_CLA] == 0) &&
        (buffer[ISO7816.OFFSET_INS] == (byte)(0xA4))) return;
     // verify the reset of commands have the
    // correct CLA byte, which specifies the
    // command structure
    if (buffer[ISO7816.OFFSET_CLA] != Wallet_CLA)
      ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
     switch (buffer[ISO7816.OFFSET_INS]) {
      case GET_BALANCE: getBalance(apdu);
        return;
      case DEBIT: debit(apdu);
        return;
      case CREDIT: credit(apdu);
        return;
      case VERIFY: verify(apdu);
        return;
      default: ISOException.throwIt (ISO7816.SW_INS_NOT_SUPPORTED);
    }
  } // end of process method
  private void credit(APDU apdu) {
    // access authentication
    if ( ! pin.isValidated()) ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
    byte[] buffer = apdu.getBuffer();
    // Lc byte denotes the number of bytes in the
    // data field of the command APDU
    byte numBytes = buffer[ISO7816.OFFSET_LC];
   
    // indicate that this APDU has incoming data
    // and receive data starting at the offset
    // ISO7816.OFFSET_CDATA following the 5 header
    // bytes.
    byte byteRead = (byte)(apdu.setIncomingAndReceive());
   
    // it is an error if the number of data bytes
    // read does not match the number in Lc byte
    if (byteRead != 1) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
   
    // get the credit amount
    byte creditAmount = buffer[ISO7816.OFFSET_CDATA];
   
    // check the credit amount
    if ( ( creditAmount > MAX_TRANSACTION_AMOUNT) || ( creditAmount < 0 ) )
      ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
   
    // check the new balance
    if ( ( balance + creditAmount) > MAX_BALANCE ) ISOException.throwIt(SW_EXCEED_MAXIMUM_BALANCE);
   
    // credit the amount
    balance = (short)(balance + creditAmount);
 
  } // end of deposit method
        private void debit(APDU apdu) {
   
    // access authentication
    if ( ! pin.isValidated()) ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
   
    byte[] buffer = apdu.getBuffer();
    byte numBytes = (byte)(buffer[ISO7816.OFFSET_LC]);
    byte byteRead = (byte)(apdu.setIncomingAndReceive());
   
    if (byteRead != 1) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
   
    // get debit amount
    byte debitAmount = buffer[ISO7816.OFFSET_CDATA];
   
    // check debit amount
    if ( ( debitAmount > MAX_TRANSACTION_AMOUNT) || (debitAmount < 0 ) )
      ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
   
    // check the new balance
    if ( ( balance - debitAmount) < 0 ) ISOException.throwIt(SW_NEGATIVE_BALANCE);
   
    balance = (short) (balance - debitAmount);
  } // end of debit method
   private void getBalance(APDU apdu) {
    byte[] buffer = apdu.getBuffer();
    // inform system that the applet has finished
    // processing the command and the system should
    // now prepare to construct a response APDU
    // which contains data field
    short le = apdu.setOutgoing();
   
  //  if ( le < 2 ) ISOException.throwItISO7816 (SW_WRONG_LENGTH);
    //informs the CAD the actual number of bytes
    //returned
    apdu.setOutgoingLength((byte)2);
   
    // move the balance data into the APDU buffer
    // starting at the offset 0
    buffer[0] = (byte)(balance >> 8);
    buffer[1] = (byte)(balance & 0xFF);
   
    // send the 2-balance byte at the offset
    // 0 in the apdu buffer
    apdu.sendBytes((short)0, (short)2);
   
 
  } // end of getBalance method
  private void verify(APDU apdu) {
    byte[] buffer = apdu.getBuffer();
    // retrieve the PIN data for validation.
    byte byteRead = (byte)(apdu.setIncomingAndReceive());
   
    // check pin
    // the PIN data is read into the APDU buffer
    // at the offset ISO7816.OFFSET_CDATA
    // the PIN data length = byteRead
    if ( pin.check(buffer, ISO7816.OFFSET_CDATA,byteRead) == false )
      ISOException.throwIt(SW_VERIFICATION_FAILED);
  } // end of validate method
} // end of class Wallet

symag
Posts: 1
Joined: Sat May 26, 2018 2:04 am
Points: 8
Contact:

Re: Wallet Applet, I can not select it !!!

Postby symag » Sat May 26, 2018 2:27 am

Maybe you need setup the aid of applet first, the aid value of applet was set on the user interface of JCOP tools or JCIDE.

leopard
Posts: 1
Joined: Wed May 23, 2018 12:41 pm
Points: 18
Contact:

Re: Wallet Applet, I can not select it !!!

Postby leopard » Sat May 26, 2018 3:32 am

symag wrote:Maybe you need setup the aid of applet first, the aid value of applet was set on the user interface of JCOP tools or JCIDE.


No, I think this problem has relation with install parameter. Please see my screen snapshot in following.

fig1.png

figure 1: The source of reason cause the exception.

fig2.png

figure 2: The right install parameter.
You do not have the required permissions to view the files attached to this post. Please login first.

OSSAMA
Posts: 3
Joined: Sun Mar 19, 2017 8:54 am
Points: 102
Contact:

Re: Wallet Applet, I can not select it !!!

Postby OSSAMA » Tue May 29, 2018 1:55 pm

Dear Leopard,
thanks for your answer which I believe it is about the install parameters. however, I could not fix it until now as you can see in the following

>> install 1122334455 112233445500 112233445500
>> 80 E6 0C 00 1A 05 11 22 33 44 55 06 11 22 33 44 55 00 06 11 22 33 44 55 00 01 00 02 C9 00 00 00
<< 69 85 Conditions of use not satisfied
>> cardinfo
>> 80 F2 80 00 02 4F 00 00
<< 08 A0 00 00 00 03 00 00 00 01 9E 90 00
>> 80 F2 40 00 02 4F 00 00
<< 6A 88 Referenced data or reference data not found
>> 80 F2 10 00 02 4F 00 00
<< 05 11 22 33 44 55 01 00 01 06 11 22 33 44 55 00 90 00
you help is highly appriciated


Return to “Applets Development Guide”

Who is online

Users browsing this forum: No registered users and 0 guests

JavaCard OS : Disclaimer