Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Finding a constant that can be replaced with ISO7816.SW_PIN_REQUIRED to make my javacard work fine

JavaCard Applet Development Related Questions and Answers.
user143842157722377
Posts: 1
Joined: Sat Aug 01, 2015 5:32 am
Points :4
Contact:

Finding a constant that can be replaced with ISO7816.SW_PIN_REQUIRED to make my javacard work fine

Post by user143842157722377 » Mon Sep 14, 2015 2:58 am

Hello everyone.
I'm trying to implement wallet applet using JCIDE. But now i am experiencing a problem.
Maybe this is just a stupid mistake.
MY CODE:

Code: Select all

package walletapp;

import javacard.framework.*;

public class wallet extends Applet
{
     /* constants declaration */
    final static byte CLA =(byte)0x80;
    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 the
    // PIN is blocked
    final static byte PinTryLimit =(byte)0x03;
    // maximum size PIN
    final static byte MaxPinSize =(byte)0x04;
    final static short SW_NEGATIVE_BALANCE = (short)0x6910;
    /* instance variables declaration */
    OwnerPIN pin;
    byte balance;
    byte buffer[];
    private wallet()
    {
        //constructor
        pin = new OwnerPIN(PinTryLimit, MaxPinSize);
        balance = 0;
        register();
    } // end of the constructor

    public static void install(APDU apdu)
    {
        // create a wallet app instance
        new wallet();
    }

    public boolean select()
    {
        pin.reset();
        return true;
    }

    public void process(APDU apdu)
    {
        // transfer incoming and outgoing APDU commands between card and smart card reader
        buffer = apdu.getBuffer();

        if (buffer[ISO7816.OFFSET_CLA] != 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);
        }
    }   

    private void deposit(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 = (byte)(balance + buffer[ISO7816.OFFSET_CDATA]);
        return;
        }

    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 be negative
        if ( ( balance - buffer[ISO7816.OFFSET_CDATA]) < 0 )
          ISOException.throwIt(SW_NEGATIVE_BALANCE);
        balance = (byte)
          (balance - buffer[ISO7816.OFFSET_CDATA]);
     }

    private void getBalance(APDU apdu)
    {
        // access authentication
        if ( ! pin.isValidated() )
          ISOException.throwIt(ISO7816.SW_PIN_REQUIRED);
        apdu.setOutgoing();
        apdu.setOutgoingLength((byte)1);
        buffer[0] = balance;
        apdu.sendBytes((short)0, (short)1);
     }
     
    private void validate(APDU apdu)
    {
        byte byteRead =(byte)(apdu.setIncomingAndReceive());
        pin.check(buffer, ISO7816.OFFSET_CDATA, byteRead);
    }
}


The applet runs with the error:
C:\WORKSP~1\WALLET~2\src\WALLET~1\wallet.java:76: cannot find symbol
symbol : variable SW_PIN_REQUIRED
location: interface javacard.framework.ISO7816
ISOException.throwIt (ISO7816.SW_PIN_REQUIRED);

Is there any other default constant that can be replaced with ISO7816.SW_PIN_REQUIRED? I want my applet to work fine.
Thx a lot.

User avatar
Tolice
Posts: 40
Joined: Wed May 20, 2015 2:41 am
Points :254
Contact:

Re: Finding a constant that can be replaced with ISO7816.SW_PIN_REQUIRED to make my javacard work fine

Post by Tolice » Mon Nov 02, 2015 7:59 am

The ISO7816.SW_PIN_REQUIRED is not accord with ISO7816. You can use the constant existed in ISO7816 standard or you can redefine it yourself.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 64 guests

JavaCard OS : Disclaimer