I have created a server to send APDU commands to java card application.
The connection has been established successfully. The only problem that I encounter is that that I send a command successfully but the Java Card aplication doesn't receive it.
The following code represents the client from which I do send commands :
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());
}
}
}
The java card applet is a simple applet created by the IDE.
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
}
}
In the java card I turn on the Device and the port is established. I do not know why the command is successfully sent and the java card server doesn't receive it.
Edit:
I saw the problem about why javacard didn't receive any data. The problem is within the client. When the statement cad.powerUp();
reaches the whole client blocks and nothing more is executed, like in as a sleep();
function was called. So now the really problem is why the cad.powerUp() blocks the client.