本文介绍了扩展的APDU和T = 0/1通信协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JCOP V2.4.2 R3 Java卡,该卡在其数据表中提到该卡同时支持T=1T=0通信协议"

I have a JCOP V2.4.2 R3 java card that it is mentioned in its datasheet "The card support both T=1 and T=0 communication protocols"

我还有一个ACR38智能卡读卡器,它同时支持T = 0和T = 1协议. (我成功与一张卡进行T = 0通讯,并且与这张卡成功进行T = 1通讯.)

I have also an ACR38 smart card reader that it support both T=0 and T=1 protocols. (I have T=0 communication with one card successfully and T=1 communication with this card successfully.)

我编写了以下程序,并将其上传到卡上以发送和接收扩展的APDU:

I wrote the below program and upload it on the card to send and receive extended APDUs:

package extAPDU;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
import javacardx.apdu.ExtendedLength;

public class ExAPDU extends Applet implements ExtendedLength {

    private ExAPDU() {
    }


    public static void install(byte bArray[], short bOffset, byte bLength)
            throws ISOException {
        new ExAPDU().register();
    }

    public void process(APDU arg0) throws ISOException {
        short number = arg0.setIncomingAndReceive();
        arg0.setOutgoingAndSend((short)0, (short)(number+7));
    }

}

在CAD端,我使用python脚本将不同的APDU发送到卡上.问题是:

In the CAD-side I used python scripts to send different APDUs to card. The questions is:

1-为什么我无法开始使用T = 0协议进行通信(虽然提到该卡支持该协议):

python脚本:

from smartcard.scard import *
import smartcard.util
from smartcard.System import readers
from smartcard.CardConnection import CardConnection

r=readers()
print r
connection =r[0].createConnection()
connection.connect(CardConnection.T0_protocol)

normalCommand=[0x00,0xa4,0x04,0x00,0x06,0x01,0x02,0x03,0x04,0x05,0x06]
data,sw1,sw2=connection.transmit(normalCommand)
print "SW for Normal Command:"
print data,hex(sw1),hex(sw2)

输出:

>>> ================================ RESTART ================================
>>>
['ACS CCID USB Reader 0']

Traceback (most recent call last):
  File "C:\extAPDU.py", line 13, in <module>
    connection.connect(CardConnection.T0_protocol)
  File "D:\PythonX\Lib\site-packages\smartcard\CardConnectionDecorator.py", line 54, in connect
    self.component.connect(protocol, mode, disposition)
  File "D:\PythonX\Lib\site-packages\smartcard\pcsc\PCSCCardConnection.py", line 118, in connect
    raise CardConnectionException('Unable to connect with protocol: ' + dictProtocol[pcscprotocol] + '. ' + SCardGetErrorMessage(hresult))
CardConnectionException: Unable to connect with protocol: T0. The requested protocols are incompatible with the protocol currently in use with the smart card.
>>>

2-为什么该卡在T = 1协议上不能以扩展形式的Select APDU命令正常工作:

python脚本:

from smartcard.scard import *
import smartcard.util
from smartcard.CardConnection import CardConnection
from smartcard.System import readers

r=readers()
print r
connection =r[0].createConnection()
connection.connect(CardConnection.T1_protocol)

normalCommand=[0x00,0xa4,0x04,0x00,0x00,0x00,0x06,0x01,0x02,0x03,0x04,0x05,0x06]
data,sw1,sw2=connection.transmit(normalCommand)
print "SW for Normal Command:"
print data,hex(sw1),hex(sw2)

输出:

>>> ================================ RESTART ================================
>>>
['ACS CCID USB Reader 0']
SW for Normal Command:
[] 0x67 0x0
>>>

我想我误解了这个概念,我将扩展APDU与T=1T=0协议混合了!

I think I misunderstood this concept and I mixed up Extended APDUs with T=1 and T=0 protocols!

每个兼容T=1的智能卡,都可以发送和接收扩展APDU吗?我们不能通过T=0协议发送和接收扩展的APDU?如果要向安全域发送扩展的SELECT APDU命令,SD必须实现ExtendedLength接口吗?

Every T=1 compatible smart card, can send and receive Extended APDUs? and we can't send and receive extended APDUs over T=0 protocols? If we want to send Extended SELECT APDU commands to the Security Domain, the SD must implement ExtendedLength interface?

对于扩展APDU传输有什么要求?

For an Extended APDU transmission what are the requirements?

  1. 兼容T = 1的读卡器
  2. 兼容T = 1的智能卡
  3. 实现ExtendedLength接口的小程序
  1. A T=1 compatible card reader
  2. A T=1 compatible smart card
  3. An applet that implemented ExtendedLength interface

对吗?

我对智能卡的扩展兼容性和T=0/1兼容性感到非常困惑.任何光将不胜感激.

I am really confused about Extended compatibility and T=0/1 compatibility in smart cards. Any light will appreciated.

请注意,我可以使用T=1协议将扩展APDU成功发送到上述applet!

Note that, I can successfully send Extended APDUs to the above applet with T=1 protocol!

推荐答案

第一季度:可以更改协议.通过ATR/ATS收发卡所支持的协议信息.终端然后可以决定使用哪个.因此,无论协议是否可选,它都是来自终端外壳的依赖项.对于JCOP Shell,这是/change-protocol.但是一般不建议T = 0.

Q1: Changing Protocol is possible. Information which protocols are supported by hte card is transceived via ATR/ATS. The terminal then can decide which one to use. So it is dependend from your Terminal shell if protocols are selectable or not. For JCOP Shell this is /change-protocol.However is do not recommend T=0 in general.

第二季度::如果您通过发送ATR/ATS来启动卡,则卡管理器处于活动状态,仅支持Global Platform命令.全球平台从不支持扩展长度.通过发送一个Select命令(因为它必须是简单的长度),该applet被选中,并且实际的Select命令也被转发到Applet的process()方法中(并且可以由selectingApplet()方法检测到).现在您已经在Applet中,您可以根据需要发送任意多个扩展长度"命令.通过将小程序安装为默认选中状态,可以绕过初始的非扩展长度选择".

Q2: If you start the card via sending ATR/ATS the Card Manager is active which only supports Global Platform commands. Global Platform does not support Extended Length what so ever. By sending a Select command(which must be simple length because of that) the applet gets selected and that actual Select commands is also forwarded into your Applet's process() method (and can be detected by the selectingApplet() method). Now that you are in your Applet you can send as many Extended Length commands as you want. You can bypass the initial Non-Extended-Length-Select by installing your applet as default selected.

这篇关于扩展的APDU和T = 0/1通信协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 03:15