This discussion is archived
2 Replies Latest reply: Nov 12, 2012 6:20 PM by safarmer RSS

I cannot load .cap file (SW 6F 00 error)

965207 Newbie
Currently Being Moderated
I am working on Wallet applet, using eclipse I have written the applet and compiled it with no error. When trying to load it to the card using JLoad program
the following error appear
INSTALL ( for install ) response check failed with SW 6F 00.

The applet is here

package WalletPackage;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.OwnerPIN;

public class Wallet extends Applet {

     final static byte Wallet_CLA = (byte) 0xB0;
     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;

     final static short MAX_BALANCE = 0x7FFF;
     final static byte MAX_TRANSACTION_AMOUNT = 127;

     final static byte PIN_TRY_LIMIT = (byte) 0x03;
     final static byte MAX_PIN_SIZE = (byte) 0x08;

     final static short SW_VERIFICATION_FAILED = 0x6300;
     final static short SW_PIN_VERIFICATION_REQUIRED = 0x6301;
     final static short SW_INVALID_TRANSACTION_AMOUNT = 0x6A83;
     final static short SW_EXCEED_MAXIMUM_BALANCE = 0x6A84;
     final static short SW_NEGATIVE_BALANCE = 0x6A85;

     OwnerPIN pin;
     short balance;

     private Wallet(byte bArray[], short bOffset, byte bLength) {
          pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);
          pin.update(bArray, bOffset, bLength);
          register();
     }

     public static void install(byte bArray[], short bOffset, byte bLength) {
          new Wallet(bArray, bOffset, bLength);
     }

     public boolean select() {
          if (pin.getTriesRemaining() == 0)
               return false;
          return true;
     }

     public void deselect() {
          pin.reset();
     }

     public void process(APDU apdu) {
          // TODO Auto-generated method stub
          if (selectingApplet())
               return;
          byte[] buffer = apdu.getBuffer();
          if (buffer[ISO7816.OFFSET_CLA] != Wallet_CLA)
               ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
          switch (buffer[ISO7816.OFFSET_INS]) {

          case GET_BALANCE:
               getBalance(apdu);
               break;
          case CREDIT:
               credit(apdu);
               break;
          case DEBIT:
               debit(apdu);
               break;
          case VERIFY:
               verify(apdu);
               break;
          default:
               ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
               break;

          }
     }

     public void credit(APDU apdu) {

          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);
          byte creditAmount =buffer[ISO7816.OFFSET_CDATA];
          if ((creditAmount > MAX_TRANSACTION_AMOUNT) || (creditAmount < 0))
               ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
          if ((short)(balance + creditAmount) > MAX_BALANCE)
               ISOException.throwIt(SW_EXCEED_MAXIMUM_BALANCE);
          balance = (short) (balance + creditAmount);

     }

     public void debit(APDU apdu) {

          if (!pin.isValidated())
               ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
          byte[] buffer = apdu.getBuffer();
          byte numBytes = buffer[ISO7816.OFFSET_LC];
          byte byteRead = (byte) (apdu.setIncomingAndReceive());
          if (byteRead != 1)
               ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
          byte debitAmount = (byte) (buffer[ISO7816.OFFSET_CDATA]);
          if ((debitAmount > MAX_TRANSACTION_AMOUNT) || (debitAmount < 0))
               ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
          if ((short)(balance - debitAmount) < 0)
               ISOException.throwIt(SW_NEGATIVE_BALANCE);
          balance = (short) (balance - debitAmount);
     }

     public void getBalance(APDU apdu) {

          byte[] buffer = apdu.getBuffer();
          short le = apdu.setOutgoing();
          if (le < 2)
               ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
          apdu.setOutgoingLength((short) 2);
          buffer[0] = (byte) (balance >> 8);
          buffer[1] = (byte) (balance & 0xFF);
          apdu.sendBytes((short) 0, (short) 2);

     }

     public void verify(APDU apdu) {

          byte[] buffer = apdu.getBuffer();
          byte byteRead = (byte) (apdu.setIncomingAndReceive());
          if (pin.check(buffer, ISO7816.OFFSET_CDATA, byteRead) == false)
               ISOException.throwIt(SW_VERIFICATION_FAILED);

     }

}
Any help ??
  • 1. Re: I cannot load .cap file (SW 6F 00 error)
    safarmer Expert
    Currently Being Moderated
    repost with &#123;code} tags:
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.framework.OwnerPIN;
    
    public class Wallet extends Applet {
      final static byte Wallet_CLA = (byte) 0xB0;
      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;
      final static short MAX_BALANCE = 0x7FFF;
      final static byte MAX_TRANSACTION_AMOUNT = 127;
      final static byte PIN_TRY_LIMIT = (byte) 0x03;
      final static byte MAX_PIN_SIZE = (byte) 0x08;
      final static short SW_VERIFICATION_FAILED = 0x6300;
      final static short SW_PIN_VERIFICATION_REQUIRED = 0x6301;
      final static short SW_INVALID_TRANSACTION_AMOUNT = 0x6A83;
      final static short SW_EXCEED_MAXIMUM_BALANCE = 0x6A84;
      final static short SW_NEGATIVE_BALANCE = 0x6A85;
      OwnerPIN pin;
      short balance;
    
      private Wallet(byte bArray[], short bOffset, byte bLength) {
        pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);
        pin.update(bArray, bOffset, bLength);
        register();
      }
    
      public static void install(byte bArray[], short bOffset, byte bLength) {
        new Wallet(bArray, bOffset, bLength);
      }
    
      public boolean select() {
        if (pin.getTriesRemaining() == 0) return false;
        return true;
      }
    
      public void deselect() {
        pin.reset();
      }
    
      public void process(APDU apdu) {
        // TODO Auto-generated method stub
        if (selectingApplet()) return;
        byte[] buffer = apdu.getBuffer();
        if (buffer[ISO7816.OFFSET_CLA] != Wallet_CLA)
          ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
        switch (buffer[ISO7816.OFFSET_INS]) {
          case GET_BALANCE:
            getBalance(apdu);
            break;
          case CREDIT:
            credit(apdu);
            break;
          case DEBIT:
            debit(apdu);
            break;
          case VERIFY:
            verify(apdu);
            break;
          default:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
            break;
        }
      }
    
      public void credit(APDU apdu) {
        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);
        byte creditAmount = buffer[ISO7816.OFFSET_CDATA];
        if ((creditAmount > MAX_TRANSACTION_AMOUNT) || (creditAmount < 0))
          ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
        if ((short) (balance + creditAmount) > MAX_BALANCE)
          ISOException.throwIt(SW_EXCEED_MAXIMUM_BALANCE);
        balance = (short) (balance + creditAmount);
      }
    
      public void debit(APDU apdu) {
        if (!pin.isValidated()) ISOException.throwIt(SW_PIN_VERIFICATION_REQUIRED);
        byte[] buffer = apdu.getBuffer();
        byte numBytes = buffer[ISO7816.OFFSET_LC];
        byte byteRead = (byte) (apdu.setIncomingAndReceive());
        if (byteRead != 1) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        byte debitAmount = (byte) (buffer[ISO7816.OFFSET_CDATA]);
        if ((debitAmount > MAX_TRANSACTION_AMOUNT) || (debitAmount < 0))
          ISOException.throwIt(SW_INVALID_TRANSACTION_AMOUNT);
        if ((short) (balance - debitAmount) < 0) ISOException.throwIt(SW_NEGATIVE_BALANCE);
        balance = (short) (balance - debitAmount);
      }
    
      public void getBalance(APDU apdu) {
        byte[] buffer = apdu.getBuffer();
        short le = apdu.setOutgoing();
        if (le < 2) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
        apdu.setOutgoingLength((short) 2);
        buffer[0] = (byte) (balance >> 8);
        buffer[1] = (byte) (balance & 0xFF);
        apdu.sendBytes((short) 0, (short) 2);
      }
    
      public void verify(APDU apdu) {
        byte[] buffer = apdu.getBuffer();
        byte byteRead = (byte) (apdu.setIncomingAndReceive());
        if (pin.check(buffer, ISO7816.OFFSET_CDATA, byteRead) == false)
          ISOException.throwIt(SW_VERIFICATION_FAILED);
      }
    }
  • 2. Re: I cannot load .cap file (SW 6F 00 error)
    safarmer Expert
    Currently Being Moderated
    The problem is the call to: pin.update(bArray, bOffset, bLength); You need to check the format of the install buffer. There is the instance AID, the privileges of the applet and install parameters in the buffer. You need to get to your install parameters to be able to se the PIN.

    - Shane

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points