This discussion is archived
6 Replies Latest reply: Jun 6, 2012 6:02 AM by 941723 RSS

Create / Select - Applet Error

941723 Newbie
Currently Being Moderated
Hello,

I have this source,


package com.br.apphello;

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

public class JCHelloApp extends Applet {
     

final static byte CLA_APPLET = (byte) 0xB0;
final static byte INS_GET = (byte) 0x01;
     private JCHelloApp() {
     }

     public static void install(byte bArray[], short bOffset, byte bLength)
               throws ISOException {
          new JCHelloApp().register();
     }

     
     public void process(APDU apdu) throws ISOException {

byte[] buffer = apdu.getBuffer();



if (buffer[ISO7816.OFFSET_CLA] != CLA_APPLET)

ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);



switch (buffer[ISO7816.OFFSET_INS]) {

case INS_GET:

getHello(apdu);

return;

default:

ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);

}

     }

     private void getHello(APDU apdu) {
          // TODO Auto-generated method stub
byte[] hello = { 't', 'e', 's', 't','e' };


apdu.setOutgoing();

short totalBytes = (short) hello.length;

apdu.setOutgoingLength(totalBytes);

apdu.sendBytesLong(hello, (short) 0, (short) hello.length);          
          
     }

}


...but, confused by script

Step 1

//create-JCHelloApp.script
powerup;
// Select the installer applet
0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;
// create JCHelloApp applet
0x80 0xB8 0x00 0x00 0xd 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x00 0x7F;
powerdown;

Step 2
//select-JCHelloApp.script
powerup;
// select JCHelloApp applet
0x00 0xA4 0x04 0x00 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x7F;
powerdown;

Step 3
Result Run Script create-JCHelloApp.script

Java Card 2.2.2 APDU Tool, Version 1.3
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
Opening connection to localhost on port 9025.
Connected.
Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, a0, 00, 00, 00, 62, 03, 01, 08, 01, Le: 00, SW1: 90, SW2: 00
CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 0d, 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 00, 00, Le: 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 00, SW1: 90, SW2: 00

==> SW1: 90, SW2: 00

Step 4
Result Run Script select-JCHelloApp.script
Java Card 2.2.2 APDU Tool, Version 1.3
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
Opening connection to localhost on port 9025.
Connected.
Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 00, Le: 00, SW1: 6d, SW2: 00

==> SW1: 6d, SW2: 00

My Question:

final static byte CLA_APPLET = (byte) 0xB0;
final static byte INS_GET = (byte) 0x01;

Is Corret :
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 00, Le: 00, SW1: 6d, SW2: 00

Or

CLA: b0, INS: 01, P1: 04, P2: 00 ???

I am using Eclipse 3.7.2. + Eclipse JCWDE Plugin.


Then, I generated. CAP and Send My Card. But, same error : SW1: 6d, SW2: 00

PS: Select Card, A4 04 00 00 OK! 90 00 - problem, call method...

Thanks!
  • 1. Re: Create / Select - Applet Error
    Umer Journeyer
    Currently Being Moderated
    Please use:
              if (selectingApplet())
                   return;
              
    in the process(); before processing anything else.

    And change your function as below:
         private void getHello(APDU apdu) 
         {
              // TODO Auto-generated method stub
              byte[] hello = { 't', 'e', 's', 't','e' };
              byte[] buffer = apdu.getBuffer();
              Util.arrayCopy(hello, (short)0, buffer, (short)0, (short)hello.length);
              apdu.setOutgoingAndSend((short)0, (short)hello.length);
         }
    The complete working code will be:
    package org.OTN.app;
    
    import javacard.framework.APDU;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.framework.Util;
    
    public class HelloWorld extends Applet 
    {
         final static byte CLA_APPLET = (byte) 0xB0;
         final static byte INS_GET = (byte) 0x01;
         
         private HelloWorld() 
         {
              
         }
    
         public static void install(byte bArray[], short bOffset, byte bLength)
         {
              new HelloWorld().register();
         }
    
         public void process(APDU apdu) throws ISOException 
         {
    
              if (selectingApplet())
                   return;
              
              byte[] buffer = apdu.getBuffer();
         
              if (buffer[ISO7816.OFFSET_CLA] != CLA_APPLET)
                   ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
         
         
              switch (buffer[ISO7816.OFFSET_INS]) 
              {
         
                   case INS_GET:     
                        getHello(apdu);
                   break;
              
                   default:
                        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
         
              }
    
         }
         private void getHello(APDU apdu) 
         {
              // TODO Auto-generated method stub
              byte[] hello = { 't', 'e', 's', 't','e' };
              byte[] buffer = apdu.getBuffer();
              Util.arrayCopy(hello, (short)0, buffer, (short)0, (short)hello.length);
              apdu.setOutgoingAndSend((short)0, (short)hello.length);
         }
    
    }
  • 2. Re: Create / Select - Applet Error
    941723 Newbie
    Currently Being Moderated
    Hello!

    Thanks Umer...

    Done according to the source.
    But, my question:

    I have the source

    {

         final static byte CLA_APPLET = (byte) 0xB0;
         final static byte INS_GET = (byte) 0x01;

    }

    So my APDU is:
    CLA = 0XB0
    INS = 0x01
    P1 = 0x00
    P2 = 0x00

    I'm confused, because the generated script:

    CREATE . . .

    powerup;
    // Select the installer applet
    0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;
    // create JCHelloApp applet
    0x80 0xB8 0x00 0x00 0xd 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x00 0x7F;
    powerdown;

    SELECT . . .
    powerup;
    // select JCHelloApp applet
    0x00 0xA4 0x04 0x00 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x7F;
    powerdown;


    But, did not generate ==> 0xB0 0x01 0x00 0x00 ????


    Thanks !
  • 3. Re: Create / Select - Applet Error
    Umer Journeyer
    Currently Being Moderated
    938720 wrote:
    But, did not generate ==> 0xB0 0x01 0x00 0x00 ????
    Sorry, I could not understand the question. Kindly can you explain little more ?
  • 4. Re: Create / Select - Applet Error
    941723 Newbie
    Currently Being Moderated
    Umer, JCWDE'm using Eclipse to generate the scripts.
    The JCWDE generated:


    apphello.cap
    apphello.exp
    apphello.jca
    cap-download.script
    create-JCHelloApp.script
    select-JCHelloApp.script


    Question: It was not to generate 0XB0 0X01 0x00 0x00 in my script?

    I did the input within the script file. But the run (RunScript) the return is: SW1 SW2 6d 00

    I'm really confused! = (

    Thanks!
  • 5. Re: Create / Select - Applet Error
    Umer Journeyer
    Currently Being Moderated
    938720 wrote:
    Umer, JCWDE'm using Eclipse to generate the scripts.
    The JCWDE generated:


    apphello.cap
    apphello.exp
    apphello.jca
    cap-download.script
    create-JCHelloApp.script
    select-JCHelloApp.script

    Question: It was not to generate 0XB0 0X01 0x00 0x00 in my script?

    I did the input within the script file. But the run (RunScript) the return is: SW1 SW2 6d 00
    Are you trying to execute the APDU 0XB0 0X01 0x00 0x00 and getting response of 6d 00 ?
    Or something else is wrong ?
    The code I provided is working fine, you can use that.
  • 6. Re: Create / Select - Applet Error
    941723 Newbie
    Currently Being Moderated
    Umer, thank you for your patience.

    Please, this is my full source. + Java scripts




    1 )

    cap-download.script
    powerup;
    //Select the installer applet
    0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;
    0x80 0xB0 0x00 0x00 0x00 0x7F;

    //com/br/apphello/javacard/Header.cap
    0x80 0xB2 0x01 0x00 0x00 0x7F;
    0x80 0xB4 0x01 0x00 0x17 0x01 0x00 0x14 0xDE 0xCA 0xFF 0xED 0x01 0x02 0x04 0x00 0x01 0x0A 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x7F;
    0x80 0xBC 0x01 0x00 0x00 0x7F;

    //com/br/apphello/javacard/Directory.cap
    0x80 0xB2 0x02 0x00 0x00 0x7F;
    0x80 0xB4 0x02 0x00 0x20 0x02 0x00 0x1F 0x00 0x14 0x00 0x1F 0x00 0x0F 0x00 0x15 0x00 0x2A 0x00 0x0C 0x00 0x80 0x00 0x0A 0x00 0x10 0x00 0x00 0x00 0x66 0x00 0x00 0x00 0x00 0x00 0x00 0x02 0x7F;
    0x80 0xB4 0x02 0x00 0x02 0x01 0x00 0x7F;
    0x80 0xBC 0x02 0x00 0x00 0x7F;

    //com/br/apphello/javacard/Import.cap
    0x80 0xB2 0x04 0x00 0x00 0x7F;
    0x80 0xB4 0x04 0x00 0x18 0x04 0x00 0x15 0x02 0x03 0x01 0x07 0xA0 0x00 0x00 0x00 0x62 0x01 0x01 0x00 0x01 0x07 0xA0 0x00 0x00 0x00 0x62 0x00 0x01 0x7F;
    0x80 0xBC 0x04 0x00 0x00 0x7F;

    //com/br/apphello/javacard/Applet.cap
    0x80 0xB2 0x03 0x00 0x00 0x7F;
    0x80 0xB4 0x03 0x00 0x12 0x03 0x00 0x0F 0x01 0x0B 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x00 0x08 0x7F;
    0x80 0xBC 0x03 0x00 0x00 0x7F;

    //com/br/apphello/javacard/Class.cap
    0x80 0xB2 0x06 0x00 0x00 0x7F;
    0x80 0xB4 0x06 0x00 0x0F 0x06 0x00 0x0C 0x00 0x80 0x03 0x00 0xFF 0x00 0x07 0x01 0x00 0x00 0x00 0x15 0x7F;
    0x80 0xBC 0x06 0x00 0x00 0x7F;

    //com/br/apphello/javacard/Method.cap
    0x80 0xB2 0x07 0x00 0x00 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x07 0x00 0x80 0x00 0x01 0x10 0x18 0x8C 0x00 0x00 0x7A 0x02 0x30 0x8F 0x00 0x01 0x3D 0x8C 0x00 0x02 0x8B 0x00 0x03 0x7A 0x02 0x21 0x18 0x8B 0x00 0x04 0x60 0x03 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x7A 0x19 0x8B 0x00 0x05 0x2D 0x1A 0x03 0x25 0x10 0xB0 0x6A 0x08 0x11 0x6E 0x00 0x8D 0x00 0x06 0x1A 0x04 0x25 0x73 0x00 0x10 0x00 0x01 0x00 0x01 0x00 0x09 0x18 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x19 0x8C 0x00 0x07 0x70 0x08 0x11 0x6D 0x00 0x8D 0x00 0x06 0x7A 0x05 0x22 0x08 0x90 0x0B 0x3D 0x03 0x10 0x74 0x38 0x3D 0x04 0x10 0x65 0x38 0x3D 0x05 0x10 0x73 0x7F;
    0x80 0xB4 0x07 0x00 0x20 0x38 0x3D 0x06 0x10 0x74 0x38 0x3D 0x07 0x10 0x65 0x38 0x2D 0x19 0x8B 0x00 0x05 0x2E 0x1A 0x03 0x1B 0x03 0x1A 0x92 0x8D 0x00 0x08 0x3B 0x19 0x03 0x1A 0x92 0x8B 0x7F;
    0x80 0xB4 0x07 0x00 0x03 0x00 0x09 0x7A 0x7F;
    0x80 0xBC 0x07 0x00 0x00 0x7F;

    //com/br/apphello/javacard/StaticField.cap
    0x80 0xB2 0x08 0x00 0x00 0x7F;
    0x80 0xB4 0x08 0x00 0x0D 0x08 0x00 0x0A 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x7F;
    0x80 0xBC 0x08 0x00 0x00 0x7F;

    //com/br/apphello/javacard/ConstantPool.cap
    0x80 0xB2 0x05 0x00 0x00 0x7F;
    0x80 0xB4 0x05 0x00 0x20 0x05 0x00 0x2A 0x00 0x0A 0x06 0x80 0x03 0x00 0x01 0x00 0x00 0x00 0x06 0x00 0x00 0x01 0x03 0x80 0x03 0x01 0x03 0x80 0x03 0x03 0x03 0x80 0x0A 0x01 0x06 0x80 0x07 0x7F;
    0x80 0xB4 0x05 0x00 0x0D 0x01 0x06 0x00 0x00 0x4A 0x06 0x80 0x10 0x01 0x03 0x80 0x0A 0x08 0x7F;
    0x80 0xBC 0x05 0x00 0x00 0x7F;

    //com/br/apphello/javacard/RefLocation.cap
    0x80 0xB2 0x09 0x00 0x00 0x7F;
    0x80 0xB4 0x09 0x00 0x13 0x09 0x00 0x10 0x00 0x00 0x00 0x0C 0x05 0x06 0x04 0x03 0x07 0x07 0x0E 0x11 0x08 0x24 0x0A 0x08 0x7F;
    0x80 0xBC 0x09 0x00 0x00 0x7F;

    0x80 0xBA 0x00 0x00 0x00 0x7F;
    powerdown;

    2 )
    [ create-JCHelloApp.script ]

    powerup;
    //Select the installer applet
    0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;
    //create JCHelloApp applet
    0x80 0xB8 0x00 0x00 0xd 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x00 0x7F;
    powerdown;

    3 )

    [ select-JCHelloApp.script ]
    powerup;
    //select JCHelloApp applet
    0x00 0xA4 0x04 0x00 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x7F;
    powerdown;


    4 )
    package com.br.apphello;



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

    public class JCHelloApp extends Applet
    {
         final static byte CLA_APPLET = (byte) 0xB0;
         final static byte INS_GET = (byte) 0x01;
         
         private JCHelloApp()
         {
              
         }

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

         public void process(APDU apdu) throws ISOException
         {

              if (selectingApplet())
                   return;
              
              byte[] buffer = apdu.getBuffer();
         
              if (buffer[ISO7816.OFFSET_CLA] != CLA_APPLET)
                   ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
         
         
              switch (buffer[ISO7816.OFFSET_INS])
              {
         
                   case INS_GET:     
                        getHello(apdu);
                        break;
              
                   default:
                        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
         
              }

         }
         private void getHello(APDU apdu)
         {
              // TODO Auto-generated method stub
              byte[] hello = { 't', 'e', 's', 't','e' };
              byte[] buffer = apdu.getBuffer();
              Util.arrayCopy(hello, (short)0, buffer, (short)0, (short)hello.length);
              apdu.setOutgoingAndSend((short)0, (short)hello.length);
         }

    }



    I do not know if the problem is in JCWDE or do I have to manually script that accepts APDU 0XB0 0X01 0x00 0x00

Legend

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