-1

I have a little problem with my applet.It works fine ,as it should, on some of my Java cards, but on some other cards it works sketchy! It is written in a way to sends back an array, but it sends back only the first byte of it. I tried different ways, but it sends only that first byte always. Is it a card error or something with my app? Here is an example function.This function works fine and sends the whole array in half of my cards only and not in all of them!

public void testA(APDU apdu)
{
    Util.arrayCopyNonAtomic(keyParameters.getA(), (short) 0, apdu.getBuffer(), (short) 0, (short) keyParameters.getA().length);
    apdu.setOutgoingAndSend((short) 0, (short)keyParameters.getA().length);
}

PS. I'm using 2 types of Gemalto cards, one of them probably has NFC.

clearlight
  • 12,255
  • 11
  • 57
  • 75
TajnosAgentos
  • 167
  • 1
  • 1
  • 10
  • 2
    I don't think we've got enough information to answer this. Please show more code and the exact output as APDU trace. Please reread you question (especially the title) before posting. – Maarten Bodewes Apr 09 '15 at 20:43
  • I think in the other parts of your program you used a special API method that some of your card support it and some others not. And that you receive in the bad situations is not the first byte of your array, it is a status word that show an error! It's just a guess! – Ebrahim Ghasemi Apr 10 '15 at 04:49

1 Answers1

0

Following are the solutions, from most possible to least possible:

  1. since you didn't attach the full source codes, i could suspect that the "(short)keyParameters.getA().length" is actually 1.

  2. if you are certain about the value of ...getA().length, you can try modify your codes to:

    Util.arrayCopyNonAtomic(keyParameters.getA(), (short) 0, apdu.getBuffer(), ISO7816.OFFSET_CDATA, (short) keyParameters.getA().length);
    apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, (short)keyParameters.getA().length);
    

see, normally APDU header (first 5 bytes of the apdu buffer) is not allowed to be altered in some java cards. So it is a safe play to store the data to be sent from CDATA (offset =5) of the APDU buffer. it should work fine.