TLV格式的EMV JavaCard APDU响应 [英] EMV JavaCard APDU Response in TLV Format

查看:139
本文介绍了TLV格式的EMV JavaCard APDU响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的JavaCard HelloWorld脚本,我在JCIDE中使用虚拟读取器执行该脚本,然后从pyapdutool发送apdu命令:00a404000e help然后80000000,然后收到javacard字符串,一切运行正常.我的问题是:如何返回tlv格式的数据而不是该响应?我正在看有关此的emv书4.3,在Google上也没有找到一个在javacard脚本中实现emv tlv标签的示例. 有人可以让我走上正确的道路来理解这一点吗?

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);
     }
   }

简而言之:我希望能够以这种格式发送响应,例如:6F1A840E315041592E5359532E4444463031A5088801025F2D02656E然后当我转到 http://www.emvlab.org/tlvutils/即可对其进行解码.

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.

推荐答案

Javacard中有几个TLV类,但是它们是可选的,据我所知,没有任何发卡行来实现这些类.因此,您可以:

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:

  • 如果所有TLV对象完全不变,则对其进行硬编码
  • 您可以手动构建零件,并在每次新的TLV对象出现时将其连接到代码中 或
  • 您构建自己的TLV解析器/编码器
  • 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

最后一个选项很难在Javacard中准确无误地表现出来,因此,如果您是初学者,并且对第一个选项比较满意,那么一旦感到烦恼,就可以尝试构建tlv解析器

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

这篇关于TLV格式的EMV JavaCard APDU响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆