1 Reply Latest reply on Mar 28, 2013 2:19 PM by fgrieu

    Please help. I didn't touch the AID since the applet was created, but...

    936354
      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;
            /**
             * Installs this applet.
             * 
             * @param bArray
             *            the array containing installation parameters
             * @param bOffset
             *            the starting offset in bArray
             * @param bLength
             *            the length in bytes of the parameter data in bArray
             */
            public static void install(byte[] bArray, short bOffset, byte bLength) {
                new TimeAttendApplet();
            }
           
             
              public boolean select() {
      
                  // The applet declines to be selected
                  // if the pin is blocked.
                
      
                  return true;
      
              }// end of select method
      
             
              public void deselect() {
      
                  // reset the pin value
                   
      
              }
             
            public void process(APDU apdu) {
                     //Insert your code here
                 //    if (selectingApplet()) {
                 //        return;
                 //    }
                   byte buffer[] = apdu.getBuffer();
      
                      // check SELECT APDU command
                   /*   if ((buffer[ISO7816.OFFSET_CLA] == 0) &&
                              (buffer[ISO7816.OFFSET_INS] == (byte) (0xA4))) {
                          return;
                      }*/
      
                      //short bytesRead = apdu.setIncomingAndReceive();
                     /* short echoOffset = (short) 0;
      
                      while (bytesRead > 0) {
                          Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, echoBytes, echoOffset, bytesRead);
                          echoOffset += bytesRead;
                          bytesRead = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
                      }*/
                      
                      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;
            }
       
      }
      ant -f D:\\Jacky\\Documents\\NetbeansProjects\\TestApplet run-for-debug
      __set_for_debug__:
      init-platform-properties:
      Using JavaCard Platform Definition at C:\Users\Jacky\AppData\Roaming\NetBeans\7.2.1\config\Services\Platforms\org-netbeans-api-java-Platform\javacard_default.jcplatform
      Java Card Home is D:\JCDK3.0.4_ClassicEdition\classic_simulator (Java Card Platform)
      init-ri-properties:
      init-device-properties:
      Platform device property name is jcplatform.javacard_default.devicespath
      Computed device folder path is C:\Users\Jacky\AppData\Roaming\NetBeans\7.2.1\config\org-netbeans-modules-javacard\servers\javacard_default
      Platform device file path property name is C:\Users\Jacky\AppData\Roaming\NetBeans\7.2.1\config\org-netbeans-modules-javacard\servers\javacard_default\Default Device.jcard
      Deploying to device Default Device http port 8019
      init-keystore:
      Keystore is D:\JCDK3.0.4_ClassicEdition\classic_simulator/samples/keystore/a.keystore
      build-dependencies:
      unpack-dependencies:
      compile:
      compile-with-preprocessor:
      compile-proxies:
      create-descriptors:
      create-static-pages:
      do-pack:
      Resolved dist.bundle as relative file D:\Jacky\Documents\NetbeansProjects\TestApplet\dist\TestApplet.cap
      Resolved build.dir as relative file D:\Jacky\Documents\NetbeansProjects\TestApplet\build
      
      Packager [v3.0.4]
          Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
      
      
      
      [ INFO: ] Validating Command Line
      [ INFO: ] Setting packaging information
      [ INFO: ] Package is being created
      [ INFO: ] Converter [v3.0.4]
      [ INFO: ]     Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
          
          
      [ INFO: ] conversion completed with 0 errors and 0 warnings.
      [ INFO: ] Printing diagnostics..
      [ INFO: ] Packager/create SUCCESS [0 error(s) and 0 warning(s)]
      pack:
      do-sign:
      sign:
      build:
      load-dependencies:
      
      OffCard Installer [v3.0.4]
      Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
      [Unloading the bundle TestApplet from http://localhost:8019/cardmanager/]
      [ INFO: ] "Off Card Installer validating unload information"
      [ INFO: ] "Off Card Installer sending unload request"
      [ INFO: ] Operation completed successfully.
      load-bundle:
      
      OffCard Installer [v3.0.4]
      Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
      [ INFO: ] [Deleting an instance //aid/1B85451EEB/C9BE from http://localhost:8019/cardmanager/]
      [ INFO: ] "Off Card Installer validating delete request information"
      [ INFO: ] "Off Card Installer sending delete request"
      [ INFO: ] Attempt to delete a non-existed instance //aid/1B85451EEB/C9BE.
      Resolved dist.bundle as relative file D:\Jacky\Documents\NetbeansProjects\TestApplet\dist\TestApplet.cap
      Resolved dist.bundle.sig as relative file D:\Jacky\Documents\NetbeansProjects\TestApplet\dist\TestApplet.signature
      
      OffCard Installer [v3.0.4]
      Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
      [ INFO: ] Begin load........
      [ INFO: ] [Loading app bundle D:\Jacky\Documents\NetbeansProjects\TestApplet\dist\TestApplet.cap onto http://localhost:8019/cardmanager/ with name TestApplet]
      [ INFO: ] "Off Card Installer Validating load information"
      [ INFO: ] "Off Card Installer sending load request"
      [ INFO: ] Operation completed successfully.
      create-instance:
      
      OffCard Installer [v3.0.4]
      Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
      [ INFO: ] [Creating an instance of TestApplet with instance ID //aid/1B85451EEB/C9BE on http://localhost:8019/cardmanager/]
      [ INFO: ] "Off Card Installer validating create information"
      [ INFO: ] "Off Card Installer preparing create information"
      [ INFO: ] "Off Card Installer sending create request"
      [ INFO: ] Operation completed successfully.
      An instance //aid/1B85451EEB/C9BE is created for //aid/1B85451EEB/C9BD.
      run-client:
      run-script:
      Invoking apdutool on D:\Jacky\Documents\NetbeansProjects\TestApplet/scripts/testapplet.scr
      ApduTool [v3.0.4]
          Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
          
          
      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: 6d, SW2: 00
      Invalid Token after "0x7F", was expecting: <INTEGER_LITERAL>  
      run-for-debug:
      BUILD SUCCESSFUL (total time: 5 seconds)
      adpu.scr
      //Test script for Applet 'TestApplet'
      
      powerup;
      // Select TestApplet //aid/1B85451EEB/C9BD
      0x00 0xA4 0x04 0x00 0X07 0X1B 0X85 0X45 0X1E 0XEB 0XC9 0XBE 0x7F;
      
      //Send the APDU here, just want to send a 0x00 command to the applet 
      0x80 0x00 0x7F;
      //0x80 0x00;
      
      powerdown;
      Edited by: 933351 on 2013/3/28 上午 2:19
        • 1. Re: Please help. I didn't touch the AID since the applet was created, but...
          fgrieu
          It would help if you finished the question rather than using ellipsis in the title with ", but... "

          Is your problem:

          a) the mismatch between
          <tt> An instance //aid/1B85451EEB/C9<b>BE</b> is created for //aid/1B85451EEB/C9<b>BD</b>.</tt>
          [I wish I understood that madness too.]

          b) that you are getting
          <tt> Invalid Token after "0x7F", was expecting: &lt;INTEGER_LITERAL&gt;</tt>
          This one could be because of
          //Test script for Applet 'TestApplet'
           
          powerup;
          // Select TestApplet //aid/1B85451EEB/C9BD
          0x00 0xA4 0x04 0x00 0X07 0X1B 0X85 0X45 0X1E 0XEB 0XC9 0XBE 0x7F;
           
          //Send the APDU here, just want to send a 0x00 command to the applet 
          0x80 0x00 0x7F;
          //0x80 0x00;
           
          powerdown;
          The first C-APDU should probably be
          <tt>0x00 0xA4 0x04 0x00 0x07 0x1B 0x85 0x45 0x1E 0xEB 0xC9 0xBE 0x<b>00</b>;</tt>
          with Le=0x00 coding "please return the maximum possible number of bytes".
          and I would not bet on<tt> 0xBE </tt>versus<tt> 0xBD </tt>.

          The second C-APDU should probably be
          <tt>0x80 0x00 <b>0x00 0x00 0x05</b>;</tt>
          with Le=0x05 coding "please return 5 bytes", since that's hopefully<tt> hello.length </tt>(and leaving P1 and P2 at 0x00 by default is good practice).