Javacard Shareable Interface: lookupAID returns AID but getAppletShareableInterface returns null

StackOverflow https://stackoverflow.com/questions/12394579

  •  01-07-2021
  •  | 
  •  

Question

edit 2: Found the mistake. I tried to initialize the Shareable object in the constructor. At that time the client's register method is not yet called, so the JCRE doesn't have its AID. While my server's getShareableInterfaceObject(AID clientaid, byte parameter) method doesn't require the client's AID to be != null the JCRE probably does, since it calls this method for my client. I now initialize my Shareable object when I process my first APDU and it now works.

And btw, thank you owlstead for helping with formatting of my post. Definitely made it easier to read!


I'm new to Java Card development and I can't get my Shareable interface to work.

I have an interface class declaring a function my client applet wants to use. My server applet implements this class. My client applet looks up the AID and tries to acquire the interface by calling getAppletShareableInterface(). But this always returns null.

My server applet's getShareableInterface() consists of just return this;, so I guess the fault lies elsewhere. But I have no idea where.

I'm using the JCWDE and stepping through the code I see that my server applet calls register so the client applet should be able to find it. Can anyone give me some pointers what could be going wrong?

edit:

public interface IF extends Shareable {
    public void method();
}

public class Server extends Applet implements IF {
    public getShareableInterfaceObject {
        return this;
    }
}

public class Client extends Applet {

    private Client() {
        AID ServerAID = JCSystem.lookupAID(byteArrayAID, (short)0, (byte)byteArrayAID.length);
        interface = (IF)JCSystem.getAppletShareableInterfaceObject(ServerAID, (byte)0x00);
    }

    public void process(APDU apdu) {
        interface.method();
    }
}

lookupAID returns the correct AID, but getAppletShareableInterfaceObject returns null as if the server applet didn't exist.

Was it helpful?

Solution

Found the mistake. I tried to initialize the Shareable object in the constructor. At that time the client's register method is not yet called, so the JCRE doesn't have its AID. While my server's getShareableInterfaceObject(AID clientaid, byte parameter) method doesn't require the client's AID to be != null the JCRE probably does, since it calls this method for my client. I now initialize my Shareable object when I process my first APDU and it now works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top