Page 1 of 1

SELECT command

Posted: Thu Jun 15, 2017 2:10 am
by Robertdul
Can we override a select AID command and cause it to pass some data as response data? Thanks for any help.

Re: SELECT command

Posted: Thu Jun 15, 2017 10:24 pm
by mabel
Can you describe your problem more detailed so that we can provide specific help for you.

Re: SELECT command

Posted: Fri Jun 16, 2017 3:15 am
by Robertdul
Just like this:

Code: Select all

// "some data " 
    private static final byte[] somedata= new byte[] {
        (byte)0x47, (byte)0x72, (byte)0x65, (byte)0x65,
            (byte)0x74, (byte)0x69, (byte)0x6E, (byte)0x67,
            (byte)0x73, (byte)0x20
    };


public void process(APDU apdu) {
          // Good practice: Return 9000 on SELECT
          if (selectingApplet()) {
               
               response=somedata;
               responseApdu=JCSystem.makeTransientByteArray(
                    (short)(response.length),
                    JCSystem.CLEAR_ON_DESELECT);
               apdu.setOutgoing();
               apdu.setOutgoingLength((short)response.length);
               apdu.sendBytesLong(responseApdu, (short)0, (short)responseApdu.length);
                         
          }

          byte[] buf = apdu.getBuffer();
          switch (buf[ISO7816.OFFSET_INS]) {
          case (byte) 0x00:
               break;
          default:
               // good practice: If you don't know the INStruction, say so:
               ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
          }
     }


Re: SELECT command

Posted: Fri Jun 16, 2017 5:37 am
by mabel
Your code has told the OS to get ready to send the required data and then keeps executing through to your switch statement which does not understand the INS and throws the appropriate error. Please add a "return" statement after sendBytesLong().