Javacard Shareable Interface: lookupAID returns AID but getAppletShareableInterface returns null

安稳与你 提交于 2020-01-21 13:56:27

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/12394579/javacard-shareable-interface-lookupaid-returns-aid-but-getappletshareableinterf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!