-1

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.

simplify
  • 109
  • 11

1 Answers1

0

I am assuming here that you have pasted the full applet code here. The Applet.register() method is not called in the applet on installation. So, the applet is never registered with JCRE and therefore no APDU can be received by it.

In fact, it will not be available for selection because JCRE does not have any information about it.

modify the code with the following and share the result.

public static void install(byte[] bArray, short bOffset, byte bLength) {
    new Proj();
}

protected Proj(){
    register();
}

Also, make sure to install the applet.

hsg
  • 656
  • 4
  • 10
  • 1
    The register is called in the class. By the way, I saw that I misjudged the behavior of my client. It seems that the server doesn't receive anything because, after I call `cad.powerUp();` the client is blocked and nothing after it is executed. – simplify May 16 '18 at 14:13
  • Please paste your solution in the answer section. – hsg May 16 '18 at 14:46