Page 1 of 1

wallet applet: how does the pin work ?

Posted: Tue Aug 25, 2015 10:41 pm
by KevinAli
The code below is part of wallet sample applet.

Code: Select all

package com.sun.javacard.samples.wallet;
import javacard.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 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_AMOUNT 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 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);
       
        byte iLen = bArray[bOffset]; // aid length
        bOffset = (short) (bOffset+iLen+1);
        byte cLen = bArray[bOffset]; // info length
        bOffset = (short) (bOffset+cLen+1);
        byte aLen = bArray[bOffset]; // applet data length
       
        // The installation parameters contain the PIN
        // initialization value
        pin.update(bArray, (short)(bOffset+1), aLen);
        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();
       
    }


I have doubts about how the pin works. When and where do you set the pin?
Any answer is appreciated.

Re: wallet applet: how does the pin work ?

Posted: Tue Nov 03, 2015 9:01 am
by Tolice
The PIN is using in this function: private Wallet (byte[] bArray,short bOffset,byte bLength), and it is incoming through the installation parameters.

Re: wallet applet: how does the pin work ?

Posted: Thu Nov 12, 2015 10:46 pm
by UNKNwYSHSA
1 You can debug the install process using a debugger (JCOP or JCIDE), debug each step, and look the data you passed as applet install parameter is correct or not;
2 The applet install parameters shall be formatted as the GP specification says.

Re: wallet applet: how does the pin work ?

Posted: Sat Dec 05, 2015 10:50 am
by amrsalah
Hi UNKNwYSHSA, Can you refer to me the link that I can download the document which describe the INSTALL Command Data Field, Thanks.

Re: wallet applet: how does the pin work ?

Posted: Sun Dec 06, 2015 10:45 pm
by UNKNwYSHSA
Here's links for v2.2 and v2.1.1, i found from google.
http://www.win.tue.nl/pinpasjc/docs/GPCardSpec_v2.2.pdf
http://www.win.tue.nl/pinpasjc/docs/Car ... 0v0303.pdf

You can find the description of install command by search keyword "install command".

Re: wallet applet: how does the pin work ?

Posted: Thu Dec 10, 2015 6:17 pm
by amrsalah
Thanks for your kind Support!