EMV JavaCard APDU Response in TLV Format

ぃ、小莉子 提交于 2019-12-06 14:53:04

问题


I have a simple JavaCard HelloWorld script, i execute it in JCIDE with virtual reader then i send apdu commands from pyapdutool: 00a404000e aid then 80000000 and i receive javacard string, everything runs fine. My question is: how can i return a tlv format data instead of that response ? I was looking in the emv book 4.3 about this and also on google haven't found a single example to implement emv tlv tags in javacard script. Can someone put me on correct path to understand this ?

package helloworld;
import javacard.framework.*;

public class helloworld extends Applet
{
private static final byte[] javacard = {(byte)'J',(byte)'a',(byte)'v'(byte)'a',(byte)' ',(byte)'C',(byte)'a',(byte)'r',(byte)'d',(byte)'!',};
private static final byte JC_CLA = (byte)0x80;
private static final byte JC_INS = (byte)0x00;

public static void install(byte[] bArray, short bOffset, byte bLength)
{
   new helloworld().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}

public void process(APDU apdu)
{
   if (selectingApplet())
  {
     return;
  }

  byte[] buf = apdu.getBuffer();

  byte CLA = (byte) (buf[ISO7816.OFFSET_CLA] & 0xFF);
    byte INS = (byte) (buf[ISO7816.OFFSET_INS] & 0xFF);

    if (CLA != JC_CLA)
    {
        ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
    }

  switch (buf[ISO7816.OFFSET_INS])
  {
  case (byte)0x00:
     OutPut(apdu);
     break;
  default:
     ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
  }
}

private void OutPut( APDU apdu)
    {
    byte[] buffer = apdu.getBuffer();
    short length = (short) javacard.length;
    Util.arrayCopyNonAtomic(javacard, (short)0, buffer, (short)0, (short)  length);
    apdu.setOutgoingAndSend((short)0, length);
     }
   }

In short: I want to be able to send response in this format, something like: 6F1A840E315041592E5359532E4444463031A5088801025F2D02656E then when i go to http://www.emvlab.org/tlvutils/ to be able to decode it.


回答1:


There is several TLV classes in Javacard, but they are optional and to my knowledge there is not any card issuer that implemented these classes. So you can either:

  • hardcode any TLV objects if they don't change at all
  • you can build the parts manually and concatenate them in your code for every new TLV object occurance or
  • you build your own TLV parser/encoder

Last option is pretty difficult to be error-free and performant in javacard, so if you are a beginner stick with the first options and once you are too annoyed you can try to build a tlv parser



来源:https://stackoverflow.com/questions/36375710/emv-javacard-apdu-response-in-tlv-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!