-2

just looking to see if i could get some help on this, i'm only about two weeks into working with javacard and lets say its fun! haha, but seriously. heres the bit of code that im calling in my function, its real simple, i have a bit of randomly generated data and im ciphering one of the arrays into the apdu to be sent back as a response, other commands work just fine like the mem method but that one just consistently fails.

 private void initi(APDU apdu){

            byte[] buf = apdu.getBuffer();

          cdataoffset = (short)buf[ISO7816.OFFSET_CDATA];
          len = Util.getShort(buf, cdataoffset);


        try{
            rd.generateData(tempbuf, (short) 0, (short) 32);
            rd.generateData(serial, (short) 0, (short) 16);
            rd.generateData(salt, (short) 0, (short) 6);
         }
         catch(CryptoException e){
         ISOException.throwIt((short)(0x6900 | e.getReason()));
         }

        try{
         privKey.setKey(tempbuf, (short) 0);
         }
         catch(ArrayIndexOutOfBoundsException e){}
         catch(NullPointerException e){}

         try{
        cipherPriv.init(privKey, Cipher.MODE_ENCRYPT);
        }
         catch(CryptoException e){
         ISOException.throwIt((short)(0x6900 | e.getReason()));

         }

        try{
          cipherPriv.doFinal(serial, (short) 0, (short) 30, buf, cdataoffset);
        }
        catch(CryptoException e){
        ISOException.throwIt((short)(0x6900 | e.getReason()));

        }

        apdu.setOutgoingAndSend((short) 0, len);




  private void mem(APDU apdu){

    byte[] buf = apdu.getBuffer();

    short availableNVM = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_PERSISTENT);

    short availableVM = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT);

    Util.setShort(buf, (short) 0, availableNVM);

    Util.setShort(buf, (short) 2, availableVM);

    apdu.setOutgoingAndSend((short) 0, (short) 4);
    }

BTW im using a JCOP J3A081 card and gppro/antbuilder by martin for build/install

the response from the card:

A>> T=1 (4+0000) B0120000 A<< (0000+2) (89ms) 6901 SCardDisconnect("Identiv SCR3500 A Contact Reader", true)

my other theory is that im actually receiving my exception throw plus a value but i dont find that to be likely but im really not sure haha

j doe
  • 1
  • 2

1 Answers1

-1

Change the values of the different catch lines, so that they were all different and BAM my theory that i wasnt sure about was right. it's my exceptions being caught and by changing the short values (i.e. 6900, 6800, 6700) i managed to catch which section was giving me trouble!

j doe
  • 1
  • 2
  • Besides the above, as an option for debugging, you can create a special command (INS) and an array that holds some values you like, like trace vars, counters, etc. This way when you get a 6D00 or any uncaught exception, you can then send the debug command (INS) and retrieve the internal log. – jlanza Dec 07 '18 at 09:14
  • also please post your code as a solution as help for the future – Paul Bastian Dec 07 '18 at 13:04