我是APDU和智能卡通信的新手,我无法弄清楚如何成功发送APDU命令。当我尝试这个命令时:
00 A4 00 00 02 3F 00 00
我收到6E 00
回复。我试图找出我必须使用哪个班级的卡片,但对于我在00-FF
范围内尝试过的每个班级,我总是得到'Class not supported'错误。
我认为这可能与卡中的某些身份验证有关,但我不知道如何正确执行此操作。
我使用了以下Python(pyscard)代码:
from smartcard.System import readers
from smartcard.util import toHexString
r = readers()
con = r[0].createConnection()
con.connect()
for c in range(0x00, 0xFF):
comm = [c, 0xA4, 0x00, 0x00, 0x02, 0x3F00, 0x00]
data, sw1, sw2 = con.transmit(comm)
if sw1 != 0x6e:
print comm
print 'Response:'
print data, '\n'
print 'Status:'
print '%x %x' % (sw1, sw2)
修改:
该卡的ATR为3B 04 49 32 43 2E
答案 0 :(得分:2)
解决了这个问题,我的卡是一张I2C卡,因此APDU命令无法使用它。我通过C ++使用Omnisoft的Synchronous API。不是我的想法,但到目前为止它似乎是唯一的选择。
感谢所有帮助过我的人!
答案 1 :(得分:0)
不是专家,但是看the pyscard documentation,我认为你正在玩错误的字节。在给定的示例中(您的代码似乎基于),它表示
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]
data, sw1, sw2 = connection.transmit( SELECT + DF_TELECOM )
看起来A0 A4 00 00 02
是命令(不应该被修改),而7F 10
标识要与之交谈的卡的类型(这几乎肯定会有所不同,具体取决于您拥有的卡类型)。
尝试改为:
from itertools import product
for x,y in product(range(256), repeat=2):
data, sw1, sw2 = con.transmit([0xA0, 0xA4, 0x00, 0x00, 0x02, x, y])
if sw1 != 0x6e:
print("Your card responds to {:02X} {:02X}".format(x, y))
print("Response: {}".format(data))
print("Status: {:02X} {:02X}".format(sw1, sw2))
我还找到了summary table of commands;希望你觉得它很有用。
答案 2 :(得分:0)
由于您尝试发送SELECT APDU,为什么不尝试最简单的APDU,即选择Issuer Security Domain?
尝试此命令:
00 A4 04 00 00
此时您无需担心身份验证。 SELECT应该适用于所有安全级别。