Skip to Main Content

Java Card

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Communication on-card and off-card sides

843851Apr 15 2010 — edited Apr 20 2010
Hi!

I have just started one week ago to implement a project in Java Card, so I am new in this topic.

I am using Java Card 3.0.2 Connected Edition with NetBeans 6.8. I do not get a properly communication between the on-card and off-card sides. First I load the on-card application. And then, I run the off-card side which establishes a connection by a socket (to localhost and port 9025 which is the contact port), create an instance of the cad, powerup the card and send an select APDU command which get a response with the SW = 0x6999. Before developing off-card side, I build the on-card, which worked by means of scripts like the following (it selects the applet and choose one of the methods within it).
powerup;
// Select VerifyPolicyAndClaimsApplet //aid/1A68A22B3D/64
0x00 0xA4 0x04 0x00 0x06 0x1A 0X68 0XA2 0X2B 0X3D 0X65 0x7F;
//Send the APDU here
0x80 0x10 0x00 0x00 0x03 0x4A 0x43 0x33 0x7F;
powerdown;
The code which I use for the connection and send the APDU command is the following:
CadClientInterface cad;

        Socket sock;

        sock = new Socket("localhost", 9025);

        InputStream is = sock.getInputStream();

        OutputStream os = sock.getOutputStream();

        cad=CadDevice.getCadClientInstance(CadDevice.PROTOCOL_T0, is, os);

        cad.powerUp();
        // C-APDU: [CLA, INS, P1, P2, LC, [ AID]]

        Apdu apdu = new Apdu();
        apdu.command[Apdu.CLA] = (byte) 0x00;
        apdu.command[Apdu.INS] = (byte) 0xA4;
        apdu.command[Apdu.P1] = (byte) 0x04;
        apdu.command[Apdu.P2] = (byte) 0x00;

        byte[] AID = new byte[6];

        AID[0] = (byte) 0x1A;
        AID[1] = (byte) 0x68;
        AID[2] = (byte) 0xA2;
        AID[3] = (byte) 0x2B;
        AID[4] = (byte) 0x3D;
        AID[5] = (byte) 0x65;

        apdu.setDataIn(AID, 6);

        System.out.println(apdu);
        cad.exchangeApdu(apdu);
        System.out.println(apdu);

        if (apdu.getStatus() == SW_NO_ERROR) {
            System.out.println("OK");
        } else {
            System.out.println("Error: " + apdu.getStatus());
        }

        cad.powerDown();
Am I doing something wrong? I am not so sure about what is the final byte (0x7F) of the APDUs which I send in the scripts, so I don't send it in the communication by the socket, what is it?

I am sure it is a stupid detail why it does not work, but I need to solve it to follow with the project because I am so stuck. If someone could help me, I would be very grateful.

Thank you in advance.

Regards,
E_L

P.D. I have edited the post in order to try be more specific.

Edited by: E_L on Apr 16, 2010 2:47 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 18 2010
Added on Apr 15 2010
2 comments
407 views