4 Replies Latest reply: Aug 1, 2012 5:59 AM by 953218 RSS

    GPShell: How to use the -instParam correctly?

    953218
      Good day,
      I want (actually have to for Bachelor's Thesis) to pass some arguments in the install command. (Later it should be the AES-Key and the ID of the card).
      For testing purposes, I wrote the following short applet :
      package challengeresponse;
      
      import javacard.framework.Applet;
      import javacard.framework.ISO7816;
      import javacard.framework.ISOException;
      import javacard.framework.Util;
      import javacard.framework.APDU;
      
      
      
      public class ChallengeResponse extends Applet {
           
           // Instruction- and class-bytes
           final static byte CLASS = (byte) 0x80;
           final static byte INS_START = (byte) 0x01;
              static byte[] testdata;
          
           private ChallengeResponse(byte bArray[], short bOffset, byte bLength) {
             
                testdata = new byte[2];
                Util.arrayCopy(bArray, (short)0, testdata, (short)bOffset, (short)bLength);
                
                register();
                      
           }
      
           public static void install(byte bArray[], short bOffset, byte bLength)
                     throws ISOException {
                
                new ChallengeResponse(bArray,bOffset,bLength);
           
           }
      
           public void process(APDU apdu) throws ISOException {
                
                byte[] apdu_buffer = apdu.getBuffer();
                apdu.setIncomingAndReceive();
              
                switch(apdu_buffer[ISO7816.OFFSET_INS]) {
                
                case INS_START:
                     
                     // When start-command is received do:
                     
                     Util.arrayCopy(testdata, (short)0, apdu_buffer, (short)ISO7816.OFFSET_CDATA, (short)2);
                     apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, (short)2);
                     
      
                default:
                     ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
                     
                }
                
      
           }
      
      }
      This should just send what I give the applet as install parameter, doesn't it?
      And I install it using gpshell with the following file:
      mode_211
      enable_trace
      enable_timer
      
      establish_context
      card_connect
      select -AID a000000003000000
      open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
      delete -AID D0D1D2D3D4D50101
      delete -AID D0D1D2D3D4D501
      delete -AID 0202030405060708090303
      delete -AID 02020304050607080900
      install -file C:\Users\Mark\workspace\ChallengeResponse\bin\challengeresponse\javacard\challengeresponse.cap -nvDataLimit 2000 -instParam C9021234 -priv 2
      
      card_disconnect
      release_context
      The instParam should mean:
      C9: instructions for applet
      02: length of data (2 Bytes)
      12 34: Data

      However, I get the following response:
      install_for_install_and_make_selectable() returns 0x80206A80 (6A80: Wrong data /
       Incorrect values in command data.)
      What do I do wrong? Please help!
        • 1. Re: GPShell: How to use the -instParam correctly?
          Umer
          Hi,
          The problem is with your following part of the code:
               private ChallengeResponse(byte bArray[], short bOffset, byte bLength) 
               {
                 
                    testdata = new byte[2];
                    Util.arrayCopy(bArray, (short)0, testdata, (short)bOffset, (short)bLength);
                    
                    register();
                          
               }
          Here your testdata size is 2 but you are storing more data than its size (bLength). If you use
                              Util.arrayCopy(bArray, (short)0, testdata, (short)0, (short)2);
          your applet will work fine.
          • 2. Re: GPShell: How to use the -instParam correctly?
            953218
            Hi Ulmer,
            thanks a lot for your fast reply! I thought the bOffset and bLength would be set automatically according to the -instParam, where you also code the lenght...
            It works now!
            But, my output is: 0B 02 instead of 12 34.
            How does that come? nowhere in the hole apdu-install-command I can find "0B02"... Is it something encrypted?
            • 3. Re: GPShell: How to use the -instParam correctly?
              Umer
              By the way why you are expecting 1234 as response ?

              oB is your AID length
              02 your AID's first byte
              • 4. Re: GPShell: How to use the -instParam correctly?
                953218
                Thank you a lot!
                You are totally right, as in the gp 2.1.1 spec "Data Field for INSTALL [for install]" my desired "12 34" comes after some other bytes! :)