Java卡无需获取数据发送数据APDU [英] Java Card to send data without get data APDU

查看:319
本文介绍了Java卡无需获取数据发送数据APDU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来这个领域,所以原谅我,如果我的问题是幼稚的。

I'm new to this field, so forgive me if my question is naive.

我要发布一个具有自动选择小应用程序,几乎所有的APDU要得到这个小程序处理的Java卡。我需要这个小程序来发送数据未使用的Java卡标准通常的格式(即CAD而不发送 0x61 0xbytesToRead 并等待 0×00将0xC0 )。结果
比如我要寄 0x23 字节在回答 0xA0A40000027F20 这几乎是一个SELECT命令但有错在先字节!

I want to issue a Java card which has an auto-select applet and almost all APDUs are going to get handled in this applet. I need this applet to send data to CAD not using the usual format in Java card standard (i.e. without sending 0x61 0xbytesToRead and waiting for 0x00 0xc0).
For example I'd like to send 0x23 bytes in answer to 0xA0A40000027F20 which is almost a SELECT command but with wrong first byte!

所以,这是可能做到这一点?如果有可能,请告诉我怎么了。

So is this possible to do this? and if it's possible please tell me how.

感谢。

推荐答案

是的,这是可能的。瞄准你的目标,你有两个步骤如下:

Yes, it is possible. To aim your goal, you have two steps as below :


  1. 您必须使你的小应用程序的默认选择。

  2. 您必须返回一些数据,这个​​命令的接收,和/或SELECT APDU命令的接收。

有关的第一步骤中,因为它是回答<一href=\"http://stackoverflow.com/questions/22934621/mark-javacard-applet-as-implicit-selectable-default-applet-after-install\">here:

For the first step, as it is answered here:

这取决于卡 - 不是所有的人似乎都支持安装后做一个小程序的默认。但是你可以使用Java的开源工具的全球平台有--make-默认选项:

It depends on cards - not all of them seem to support making an applet default after installation. But you can use the open source GlobalPlatform tool for Java that has --make-default option:

java -jar gp.jar --make-default A000100201100001

IIRC JCOP是,实际上它支持的卡之一。

IIRC JCOP was one of the cards that actually supported it.

和用于第二步骤,作为回答<一href=\"http://stackoverflow.com/questions/28030205/is-it-possible-to-return-some-data-along-with-the-status-word-9000-on-selecting\">here

And for the second step, as answered here :

我猜你做的过程中,如果selectingApplet(),然后返回中的良好做法?您需要处理传入的APDU,而不是简单的回归。
您可以返回数据,选择正常的方式,但要注意回到0×9000,如果选择成功。

I guess you do the "good practice" of "if selectingApplet() then return" in process? You need to process the incoming APDU instead of simple return. You can return data to select the normal way, but be careful to return 0x9000 if the select was successful.

必须是这样的:

public void process(APDU apdu)
    { 
       byte[] buf = apdu.getBuffer();
       if (selectingApplet())
          { 
          //send the data in buffer return;
          }
    } 

更新:

要回答这个问题的答案在下面您的评论:

To answer your comment below this answer :

我写了下面的程序:

package test;

import javacard.framework.APDU;
import javacard.framework.ISO7816;
import javacard.framework.Applet;
import javacard.framework.ISOException;
import javacard.framework.Util;

public class Test extends Applet {

    public static final byte[] res = { (byte) 0x00, (byte) 0x00, (byte) 0x3B,
            (byte) 0xAD, (byte) 0x3F, (byte) 0x00, (byte) 0x01, (byte) 0x00,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x16,
            (byte) 0xB3, (byte) 0x03, (byte) 0x06, (byte) 0x04, (byte) 0x00,
            (byte) 0x83, (byte) 0x8A, (byte) 0x83, (byte) 0x8A, (byte) 0x00,
            (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x3B, (byte) 0xAD,
            (byte) 0x00, (byte) 0x00, (byte) 0x3B, (byte) 0xAD, (byte) 0x2F,
            (byte) 0x06, (byte) 0x02 };

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

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

        byte[] buf = apdu.getBuffer();

        if (buf[ISO7816.OFFSET_CLA] == (byte)0xA0 && buf[ISO7816.OFFSET_INS] == (byte) 0xA4 && buf[ISO7816.OFFSET_P1] == (byte) 0x00&& buf[ISO7816.OFFSET_P2] == (byte) 0x00 
                && buf[ISO7816.OFFSET_LC] == (byte) 0x02 && buf[ISO7816.OFFSET_LC + 1] == (byte) 0x7F  && buf[ISO7816.OFFSET_LC + 2] == (byte) 0x20) {
            ISOException.throwIt((short) 0x9F23);
        } else if (buf[ISO7816.OFFSET_CLA] == (byte) 0xA0 && buf[ISO7816.OFFSET_INS] == (byte) 0xC0  && buf[ISO7816.OFFSET_P1] == (byte) 0x00 
                && buf[ISO7816.OFFSET_P2] == (byte) 0x00  && buf[ISO7816.OFFSET_P2+1] == (byte) 0x23 ) {
            Util.arrayCopyNonAtomic(res, (short) 0, buf, (short) 0, (short) 35);
            apdu.setOutgoingAndSend((short) 0, (short) 35);

        } else {
            ISOException.throwIt((short) 0x9090);
        }
    }
}

然后我安装为默认选中的applet:

Then I installed it as default selected applet :

CommandLine> gp -install e:\soq.cap --default

CommandLine>

然后我送APDU命令它:

And then I send the APDU commands to it :

CommandLine> OSC.exe -s A0A40000027F20 -s a0c0000023
Using reader with a card: ACS CCID USB Reader 0
Sending: A0 A4 00 00 02 7F 20
Received (SW1=0x9F, SW2=0x23)
Sending: A0 C0 00 00 23
Received (SW1=0x90, SW2=0x00):
00 00 3B AD 3F 00 01 00 00 00 00 00 16 B3 03 06 ..;.?...........
04 00 83 8A 83 8A 00 03 00 00 3B AD 00 00 3B AD ..........;...;.
2F 06 02                                        /..

看来,它可以作为你想要的。

It seems that it works as you wanted.

这篇关于Java卡无需获取数据发送数据APDU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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