我创建了一个服务器来向Java卡应用程序发送APDU命令。
已成功建立连接。我遇到的唯一问题是我成功发送命令,但Java Card应用程序没有收到它。
以下代码表示我发送命令的客户端:
Callable
}
Java卡小程序是由IDE创建的简单小程序。
public class Client {
public static void main(String[] args) {
Socket sock;
try {
sock = new Socket("localhost", 9025);
InputStream is = sock.getInputStream();
OutputStream os = sock.getOutputStream();
CadClientInterface cad = CadDevice.getCadClientInstance(CadDevice.PROTOCOL_T0, is, os);
Apdu apdu = new Apdu();
System.out.println("Initialized apdu !");
byte[] installer = new byte[]{0x00, (byte) 0xA4, 0x04, 0x00, 0x09, (byte) 0xA0, 0x00, 0x00, 0x00, 0x62, 0x03, 0x01, 0x08, 0x01, 0x7F};
System.out.println("Prepare installer of cap !");
apdu.setDataIn(installer, installer.length);
System.out.println("Apdu set !");
System.out.println("Apdu sent !");
System.out.println(apdu);
cad.powerUp();
System.out.println("Powered up !");
cad.exchangeApdu(apdu);
cad.powerDown();
System.out.println("Powered down !");
} catch (IOException | CadTransportException e) {
e.printStackTrace();
System.out.println("Fail! " + e.getMessage());
}
}
}
在java卡中,我打开设备并建立端口。我不知道为什么命令成功发送且java卡服务器没有收到它。
修改
我看到了为什么javacard没有收到任何数据的问题。问题出在客户端内部。当语句public class Proj extends Applet {
/**
* Installs this applet.
*
* @param bArray
* the array containing installation parameters
* @param bOffset
* the starting offset in bArray
* @param bLength
* the length in bytes of the parameter data in bArray
*/
public static void install(byte[] bArray, short bOffset, byte bLength) {
new Proj();
}
/**
* Only this class's install method should create the applet object.
*/
protected Proj() {
register();
}
/**
* Processes an incoming APDU.
*
* @see APDU
* @param apdu
* the incoming APDU
*/
@Override
public void process(APDU apdu) {
//Insert your code here
}
到达整个客户端块时,不再执行任何操作,就像调用cad.powerUp();
函数一样。所以现在真正的问题是cad.powerUp()阻止客户端的原因。
答案 0 :(得分:0)
我在这里假设你已经在这里粘贴了完整的applet代码。安装时,小程序中不会调用Applet.register()
方法。因此,applet从未在JCRE中注册,因此它不能接收APDU。
事实上,它不可供选择,因为JCRE没有任何相关信息。
使用以下内容修改代码并共享结果。
public static void install(byte[] bArray, short bOffset, byte bLength) {
new Proj();
}
protected Proj(){
register();
}
此外,请务必安装小程序。