6 Replies Latest reply: Jul 24, 2012 1:51 AM by 946900 RSS

    APDU Error

    946900
      Hi.
      I am a new in Java cards. So do not hit me to much :).
      Everything is happening in Linux.
      I am trying to run HelloWorld example.
      1. I compiled HelloWorld.java to HelloWorld.class
      2. I converted HelloWorld.class to HelloWorld.cap
      3. I created HelloWorld.cap to HelloWorld.scr
      4. I changed HelloWorld.scr by adding some lines to this script, like powerup, powerdown,output off/on, create-apdu and select-apdu
      After this i run "cref -o epromee" and i run "apdutool -nobanner -noatr HelloWorld.scr".

      I received following response:
      On Create-Applet-APDU - SW1: 64, SW2: 43
      On Select-Applet-APDU - SW1: 6d, SW2: 00

      0x6443 - means Applet not found for installation.
      •Cause: An attempt was made to create an applet instance, but theapplet code was not installed on the card.
      •Solution: Verify that the applet package has been downloaded to the card

      0x6d00 - INS value not supported

      1.How to solve this?
      2.How can i verify "that the applet package has been downloaded to the card"?
      3. Could be,that error on select-apdu because create-apdu failed?If no, what is the season of apdu-select failure?
        • 1. Re: APDU Error
          Umer
          Can you share your code please ? (not hitted hard ;))
          • 2. Re: APDU Error
            946900
            No problems.It usual HelloWorld.java code.I did not change nothing:


            /*
            * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
            * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
            */

            // /*
            // Workfile:@(#)HelloWorld.java     1.7
            // Version:1.7
            // Date:01/03/06
            //
            // Archive: /Products/Europa/samples/com/sun/javacard/samples/HelloWorld/HelloWorld.java
            // Modified:01/03/06 19:01:06
            // Original author: Mitch Butler
            // */

            //package com.sun.javacard.samples.HelloWorld;
            package HelloWorld;

            import javacard.framework.*;

            /**
            */

            public class HelloWorld extends Applet
            {
            private byte[] echoBytes;
            //private static final short LENGTH_ECHO_BYTES = 256;
            private static final short LENGTH_ECHO_BYTES = 256;

            /**
            * Only this class's install method should create the applet object.
            */
            protected HelloWorld()
            {
            echoBytes = new byte[LENGTH_ECHO_BYTES];
            register();
            }

            /**
            * 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 HelloWorld();
            }

            /**
            * Processes an incoming APDU.
            * @see APDU
            * @param apdu the incoming APDU
            * @exception ISOException with the response bytes per ISO 7816-4
            */
            public void process(APDU apdu)
            {
            byte buffer[] = apdu.getBuffer();

                      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);
            }

            apdu.setOutgoing();
            apdu.setOutgoingLength( (short) (echoOffset + 5) );

            // echo header
            apdu.sendBytes( (short)0, (short) 5);
            // echo data
            apdu.sendBytesLong( echoBytes, (short) 0, echoOffset );
            }

            }
            • 3. Re: APDU Error
              Umer
              If you are looking for a Hello World Example just look below:
              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);
                   }
              
              }
              And for your code everything seems fine, I just made little changes. See below your updated code:
              package org.OTN.app;
              
              import javacard.framework.*;
              
              /**
              */
              
              public class HelloWorld extends Applet {
                   private byte[] echoBytes;
                   // private static final short LENGTH_ECHO_BYTES = 256;
                   private static final short LENGTH_ECHO_BYTES = 256;
                   private static final byte INS_HELLO_WORLD = (byte)0x01;
              
                   protected HelloWorld() 
                   {
                        echoBytes = new byte[LENGTH_ECHO_BYTES];
                        register();
                   }
              
                   public static void install(byte[] bArray, short bOffset, byte bLength) 
                   {
                        new HelloWorld();
                   }
              
                   public void process(APDU apdu) 
                   {
                        byte buffer[] = apdu.getBuffer();
              
                        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 (byte)0x01:                    
                             apdu.setOutgoing();
                             apdu.setOutgoingLength((short) (echoOffset + 5));
                   
                             // echo header
                             apdu.sendBytes((short) 0, (short) 5);
                             // echo data
                             apdu.sendBytesLong(echoBytes, (short) 0, echoOffset);
                             break;
                        }
                   }
              
              }
              Output for your code:
              cm>  card-info
               => 80 F2 80 00 02 4F 00 00                            .....O..
               (450962 nsec)
               <= 08 A0 00 00 00 03 00 00 00 01 9E 90 00             .............
              Status: No Error
               => 80 F2 40 00 02 4F 00 00                            ..@..O..
               (425223 nsec)
               <= 09 68 65 6C 6C 6F 2E 61 70 70 07 00 90 00          .hello.app....
              Status: No Error
               => 80 F2 10 00 02 4F 00 00                            .....O..
               (622986 nsec)
               <= 07 A0 00 00 00 03 53 50 01 00 01 08 A0 00 00 00    ......SP........
                  03 53 50 41 0A 68 65 6C 6C 6F 2E 70 61 63 6B 01    .SPA.hello.pack.
                  00 01 09 68 65 6C 6C 6F 2E 61 70 70 90 00          ...hello.app..
              Status: No Error
              
              Card Manager AID   :  A000000003000000
              Card Manager state :  OP_READY
              
                  Application:  SELECTABLE (--------) "hello.app"     
                  Load File  :      LOADED (--------) A0000000035350   (Security Domain)
                   Module    :                        A000000003535041
                  Load File  :      LOADED (--------) "hello.pack"    
                   Module    :                        "hello.app"
              cm>  /select |hello.app
               => 00 A4 04 00 09 68 65 6C 6C 6F 2E 61 70 70 00       .....hello.app.
               (1689 usec)
               <= 90 00                                              ..
              Status: No Error
              cm>  /send 800100000000
               => 80 01 00 00 00 00                                  ......
               (213991 nsec)
               <= 80 01 00 00 00 90 00                               .......
              Status: No Error
              • 4. Re: APDU Error
                946900
                Solved.
                Thank you very much. I found the problem.My bad.I did not notice,AID was not correct.
                • 5. Re: APDU Error
                  safarmer
                  As a warming: be very careful with code like this in a method call:
                  byte[] blah = { ... };
                  It still allocates memory on the heap EVERY call to the method. You will eventually run out of EEPROM.

                  Shane
                  • 6. Re: APDU Error
                    946900
                    The problem solved. Thanks for all replys.