This discussion is archived
3 Replies Latest reply: Apr 16, 2012 3:27 AM by 801926 RSS

GPSystem.lockCard returned false although it had Card Lock Privilege?

921719 Newbie
Currently Being Moderated
Hi all, I try to lock card with Card Lock Privilege (I set Card Lock Privilege). But it returned false, it means it can't lock the card. Please show me why?
Here is my source code.
package Test_GPSystem_lockCard;

import org.globalplatform.GPSystem;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;

public class Test_GPSystem_lockCard extends Applet
{

   public static void install(byte[] bArray, short bOffset, byte bLength)
   {
      // GP-compliant JavaCard applet registration
      new Test_GPSystem_lockCard().register(bArray, (short) (bOffset + 1),
            bArray[bOffset]);
   }

   public void process(APDU apdu)
   {
      // Good practice: Return 9000 on SELECT
      if (selectingApplet())
      {
         return;
      }

      byte[] baCommand = apdu.getBuffer();
      boolean isCardLockPrivilege = true;

      switch (baCommand[ISO7816.OFFSET_INS])
      {
         case (byte) 0x00:
            TestLockCard(isCardLockPrivilege);
            break;

         case (byte) 0x01:
            isCardLockPrivilege = false;
            TestLockCard(isCardLockPrivilege);
            break;

         default:
            // good practice: If you don't know the INStruction, say so:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
      }
   }

   public static final short GP_RESPONSE_SW_9F00 = (short) 0x9F00;
   public static final short GP_ERROR_RESPONSE_DATA = (short) 0x8F00;
   public static final short GP_SW_OTHER_ERRORS = (short) 0x8FFF;

   public void TestLockCard(boolean isCardLockPrivilege)
   {
      boolean isLockCard = false;

      /* Call lockCard method without Card Lock Privilege */
      if (isCardLockPrivilege == false)
      {
         try
         {
            isLockCard = GPSystem.lockCard();
         } catch (Exception e)
         {
            ISOException.throwIt(GP_RESPONSE_SW_9F00);
         }
         if (isLockCard == false)
         {
            ISOException.throwIt(GP_RESPONSE_SW_9F00);
         }
         ISOException.throwIt(GP_SW_OTHER_ERRORS);
      }

      try
      {
         isLockCard = GPSystem.lockCard();
      } catch (Exception e)
      {
         ISOException.throwIt(GP_ERROR_RESPONSE_DATA);
      }
      if (isLockCard == false)
      {
         ISOException.throwIt(GP_ERROR_RESPONSE_DATA);
      }
   }
}

Legend

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