我编写了以下程序,在接收到每个APDU命令时返回所有APDU缓冲区内容:
package testPack;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
public class BufferReturner extends Applet {
private BufferReturner() {
}
public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
new BufferReturner().register();
}
public void process(APDU arg0) throws ISOException {
if(selectingApplet()){
return;
}
arg0.setOutgoingAndSend((short)0, (short)255);
}
}
当我使用T=0
协议通过联系人界面发送命令时,我收到以下结果:
Connect successful. Send: 00 A4 04 00 06 01 02 03 04 05 00 00 Recv: 90 00 Time used: 8.000 ms Send: 00 00 00 00 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 00 Send Apdu error: A device attached to the system is not functioning. Send: 00 00 00 00 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 00 Recv: 6C FF Time used: 5.000 ms Send: 00 00 00 00 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 FF Recv: 6C FF Time used: 5.000 ms Send: 00 00 00 00 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 FF Recv: 6C FF Time used: 5.000 ms Send: 00 00 00 00 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 FF Recv: 6C FF Time used: 6.000 ms Send: 00 C0 00 00 FF Send Apdu error: A device attached to the system is not functioning. Send: 00 C0 00 00 FF Send Apdu error: A device attached to the system is not functioning.
如您所见,我无法收到APDU缓冲区内容。怎么了?
答案 0 :(得分:4)
与Transmission error for T=0 JavaCards一样,您的卡片没有任何问题,这是一种“预期”行为。
对于uniform_int_distribution
方法(setOutgoing()
只是一个包装setOutgoingAndSend()
的便捷方法),Java Card API规范明确指出:
在case 4命令中,必须在调用此方法之前调用
setOutgoing()
。否则,错误行为可能导致T = 0协议。
因此,您看到的正是API规范中指出的“错误行为”。