简体   繁体   English

Java Card发送数据而不获取数据APDU

[英]Java Card to send data without get data APDU

I'm new to this field, so forgive me if my question is naive. 我是这个领域的新手,如果我的问题很幼稚,请原谅我。

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. 我要发行一个具有自动选择小程序的Java卡,并且几乎所有APDU都将在此小程序中处理。 I need this applet to send data to CAD not using the usual format in Java card standard (ie without sending 0x61 0xbytesToRead and waiting for 0x00 0xc0 ). 我需要此applet来将数据发送到CAD,而不使用Java卡标准中的常规格式(即,不发送0x61 0xbytesToRead并等待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! 例如,我想发送0x23字节作为对0xA0A40000027F20答复,这几乎是一个SELECT命令,但首字节错误!

So is this possible to do this? 那么这有可能做到吗? and if it's possible please tell me how. 如果可能的话,请告诉我怎么做。

Thanks. 谢谢。

Yes, it is possible. 对的,这是可能的。 To aim your goal, you have two steps as below : 为了实现您的目标,您需要执行以下两个步骤:

  1. You must make your applet default selected. 您必须使小程序默认为选中状态。
  2. You must return some data on reception of this command, and/or reception of SELECT APDU command. 您必须在接收该命令和/或接收SELECT APDU命令时返回一些数据。

For the first step, as it is answered here : 对于第一步,因为它是回答在这里

It depends on cards - not all of them seem to support making an applet default after installation. 这取决于卡-安装后,并非所有卡似乎都支持将applet设置为默认值。 But you can use the open source GlobalPlatform tool for Java that has --make-default option: 但是您可以使用具有--make-default选项的Java开源GlobalPlatform工具:

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

IIRC JCOP was one of the cards that actually supported it. IIRC JCOP是实际上支持它的卡之一。

And for the second step, as answered here : 对于第二步,在这里回答:

I guess you do the "good practice" of "if selectingApplet() then return" in process? 我猜您正在执行“如果选择Applet()然后返回”的“良好做法”? You need to process the incoming APDU instead of simple return. 您需要处理传入的APDU,而不是简单的返回。 You can return data to select the normal way, but be careful to return 0x9000 if the select was successful. 您可以返回数据以选择正常方式,但是如果选择成功,请小心返回0x9000。

It must be looked like this: 它必须看起来像这样:

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

Update: 更新:

To answer your comment below this answer : 在此答案下面回答您的评论:

I wrote the below program : 我写了下面的程序:

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

Then I installed it as default selected applet : 然后我将其安装为默认选择的applet:

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

CommandLine>

And then I send the APDU commands to it : 然后我将APDU命令发送给它:

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. 看来它可以按照您的要求工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Card中的Applet ID和APDU - Applet ID's and APDU in Java Card 使用JavaCard和APDU从智能卡读取数据时未得到响应 - Not getting response while reading data from smart card using JavaCard and APDU 测试发送APDU时无法选择AID卡管理器 - Can't select AID Card Manager when testing to send APDU 如何将数据数组发送到Applet并由Applet对其进行操作,并在响应apdu中返回新数据? - How to send a data array to my Applet and manipulation it by Applet and return new data in response apdu? 使用APDU将小程序上传到真实的智能卡 - Upload an Applet to a real smart card using APDU 如何使用Java Applet将原始数据发送到打印机 - How to send raw data to Printer with Java Applet 如何从我的SAM卡中选择Hello World Applet,然后如何发送APDU以接收“48 65 6C 6C 6F”,它等同于“Hello”字符串 - How can i select Hello World Applet from my SAM card and then how send APDU for receive “48 65 6C 6C 6F” that it is equivalent with “Hello” String 将数据从html表单发送到Java Applet? - Send data from html form to Java Applet? 如何将音频数据从Java Applet发送到Rails控制器 - How to send audio data from Java Applet to Rails controller 为什么我在卡上安装.cap文件时收到“6400”APDU响应? - Why I receive “6400” APDU response while installing a .cap file on card?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM