Search code examples
appletsmartcardjavacard

Using javacard Shareable class to share an interface between two applet as client and server with different package?


I want to share an interface between two applets as client and server with different package AID. I saw the link: [0x6f00 error casting Javacard Shareable Interface

In the above link is said: both client and server have to be in same package. I have a question now. is it possible client uses server functions if they have different package AID? Thank you very much.


Solution

  • Client and server don't have to be in the same package! They just both need to depend on the same package, which contains the shared interface.

    In the linked question, there was a problem with interfaces: OP declared two interfaces with the same name in two separate packages. That is why casting failed and 6F00 status was thrown.


    How to use Shareable interface:

    1.Declare your shared interface public in your server-side package:

    package com.test.mypackage.a;
    public interface SharedObject extends Shareable {
            public void foo();
    }
    

    2.Use the interface in your client code:

    package com.test.mypackage.b;
    import com.test.mypackage.a.SharedObject;
    
    ...
    SharedObject obj = (SharedObject) JCSystem.getAppletShareableInterfaceObject(svrAid, (byte)0);
    
    1. Use your server applet as a library when building your client applet.
    2. Load your server applet cap file first.
    3. Then load your client applet cap file.