1 2 Previous Next 16 Replies Latest reply: Apr 15, 2013 5:50 AM by 925183 RSS

    How to activate this applet

    936354
      adpu:
      //Test script for Applet 'TimeAttendApplet'

      powerup;
      // Select TimeAttendApplet //aid/1B85451EEB/C9FB
      0x00 0xA4 0x04 0x00 0X07 0X1B 0X85 0X45 0X1E 0XEB 0XC9 0XFB 0x7F;

      //Send the APDU here
      0x80 0x00 0x7F;

      powerdown;
      package com.walker;
      
      import javacard.framework.APDU;
      import javacard.framework.Applet;
      import javacard.framework.ISO7816;
      import javacard.framework.ISOException;
      import javacard.framework.Util;
      
      public class TimeAttendApplet extends Applet {
      
           private TimeAttendApplet() {
                register();
           }
      
            private static byte[] hello = { (byte)'1', (byte)'2', (byte)'3'
               ,(byte)'4',(byte)'5',  
            };
       
            private static final byte HW_CLA = (byte) 0x80;
            private static final byte HW_INS = (byte) 0x00;
             public static void install(byte[] bArray, short bOffset, byte bLength) {
                new TimeAttendApplet();
            }
             public void process(APDU apdu) {
                    byte buffer[] = apdu.getBuffer();
      
                       
                      switch (buffer[ISO7816.OFFSET_INS])
                   {
                    case HW_INS:
                        getHello(apdu);
                        break;
                    default:
                        ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
                        
                }
            }
                 
            private void getHello(APDU apdu)
            {
                byte[] buffer = apdu.getBuffer();
                short length = (short) hello.length;
                
                Util.arrayCopyNonAtomic(hello, (short)0, buffer, (short)0, length);
                apdu.setOutgoingAndSend((short)0, length);
            }
            
            public void setHello(byte[] empId)
            {
                 hello = empId;
            }
       
      }
      Receiving:
      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: 07, 1b, 85, 45, 1e, eb, c9, fb, Le: 00, SW1: 69, SW2: 99
      Invalid Token after "0x7F", was expecting: <INTEGER_LITERAL>

      Seems like the select has succeeded, but the command/data string was incorrect.
      Also tried
      0x80 0x00;
      Let me know

      Edited by: 933351 on 2013/3/21 上午 3:01
        • 1. Re: How to activate this applet
          safarmer
          933351 wrote:
          Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00
          CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 07, 1b, 85, 45, 1e, eb, c9, fb, Le: 00, SW1: 69, SW2: 99
          Invalid Token after "0x7F", was expecting: <INTEGER_LITERAL>

          Seems like the select has succeeded, but the command/data string was incorrect.
          The select failed. The SW is 6999 (selection failed). If it worked you would expect a 9000 status word.

          - Shane
          • 2. Re: How to activate this applet
            936354
            Then shane,
            How do I select it correctly? I have this in my manifest.mf and applet.xml files
            Manifest-Version: 1.0
            Runtime-Descriptor-Version: 3.0
            Application-Type: classic-applet
            Classic-Package-AID: //aid/1B85451EEB/3CB7
            <?xml version="1.0" encoding="UTF-8"?>
            <applet-app xmlns="http://java.sun.com/xml/ns/javacard"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="http://java.sun.com/xml/ns/javacard http://java.sun.com/xml/ns/javacard/applet-app_3_0.xsd"
                        version="3.0">
                <applet>
                    <!-- The applet application deployment descriptor conveys APDU-based application
                    model elements and configuration information of an application between application
                    developers, application assemblers, and deployers. -->
                    <display-name>Time Attend Applet</display-name>
                    <applet-class>com.walker.TimeAttendApplet</applet-class>
                    <applet-AID>//aid/1B85451EEB/C9FB</applet-AID>
                </applet>
            </applet-app>
            Thanks in advance
            • 3. Re: How to activate this applet
              936354
              [del]

              Edited by: 933351 on 2013/3/21 下午 7:53
              • 4. Re: How to activate this applet
                936354
                Any one would like to share his/her insights with this poor guy like me...
                Thanks
                Jack
                • 5. Re: How to activate this applet
                  936354
                  Please help. There is no document on the net on how to go about selecting the applet this way (using SWING)
                  • 6. Re: How to activate this applet
                    Umer
                    Plz try adding following code in the process() and try again:
                                   if (selectingApplet()) 
                                   {
                                        return;
                                   }
                    • 7. Re: How to activate this applet
                      936354
                      When I added these 2 statements to my program, I got these errors which I believed they were still some selection errors.
                      However, I've changed the adpu script from 0x80 0x00 0x7F to 0x80 0x00, if that makes a difference.
                      Thanks
                      Jack
                      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: 07, 1b, 85, 45, 1e, eb, c9, be, Le: 00, SW1: 90, SW2: 00
                      Invalid Token after "0x00", was expecting: <INTEGER_LITERAL>  
                      Edited by: 933351 on 2013/4/3 下午 8:16
                      • 8. Re: How to activate this applet
                        Umer
                        No man this is not an error. You have successfully selected the applet. chill now :)
                        • 9. Re: How to activate this applet
                          936354
                          Thanks Umer,
                          But it seems like it doesn't return the "12345" string from the method "getHello".
                          How do I get "12345" out of the console?
                          Thanks
                          Jack
                          • 10. Re: How to activate this applet
                            Umer
                            933351 wrote:
                            But it seems like it doesn't return the "12345" string from the method "getHello".
                            How do I get "12345" out of the console?
                            Just Selecting the applet will not return Get Hello message. To get this you need to send another APDU which will instruct the applet to return you byte array of Hello World string.
                            • 11. Re: How to activate this applet
                              936354
                              Hi,
                              Now I've got one adpu file, which consists those command strings.
                              Do I separate out the 0x80 0x00 0x7F into other files?
                              How do I invoke them? One after one? and Shouldn't I poweroff the simulator after the selection? That means to comment out
                              that "poweroff" line. That will go?
                              Thanks
                              Jack

                              Edited by: 933351 on 2013/4/5 上午 2:12
                              • 12. Re: How to activate this applet
                                936354
                                Umer, are you there? I need your help please.
                                Thanks
                                Jack
                                • 13. Re: How to activate this applet
                                  Umer
                                  To get the hello world from your applet you need to perform following steps in sequence:

                                  1. Select the reader
                                  2. Connect to the card which is inside the reader you selected
                                  3. Select the applet by sending SELECT Applet APDU
                                  4. Upon 0x9000, Send get hello world APDU.

                                  Now for the step-4, you need to prepare an APDU which will instruct your applet to return a byte array of hello world characters.

                                  Suppose you are sending:
                                  80 00 00 00 00
                                  from the host application and in the applet, in process(), you should do something like:
                                                case HW_INS:
                                                    getHello(apdu);
                                                    break;
                                  And please note, i have not mentioned any power-off or reset.
                                  • 14. Re: How to activate this applet
                                    936354
                                    Let me try to figure out, tell you back later.

                                    Update:
                                    I created a secondary apdu, and debug the applet (select it), when it returns okay.
                                    I sent another adpu to the applet, I haven't powered down the java card.
                                    But I still get
                                    Invalid Token after "0x00", was expecting: <INTEGER_LITERAL>
                                    //powerup;
                                    
                                    // Select the applet
                                    // 0x00 0xA4 0x04 0x00 <length> <aid bytes> 0x7F;
                                    
                                    // Send command APDUs here
                                    // 0x80 0xCA 0x00 0x00 <length> <data> 0x7F;
                                    0x80 0x00;
                                    
                                    powerdown;
                                    Thanks

                                    Edited by: 933351 on 2013/4/12 上午 12:59

                                    Edited by: 933351 on 2013/4/12 上午 1:01

                                    Edited by: 933351 on 2013/4/12 上午 1:02
                                    1 2 Previous Next