Mohsen Gorgani
Mohsen Gorgani

Reputation: 420

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.

Upvotes: 2

Views: 1336

Answers (2)

Ujjwal Roy
Ujjwal Roy

Reputation: 550

Shareable interface cannot be used for applets in same package.Since it works for applets with different contexts.

Shareable interface is used when one applet(Client Applet) need to access methods from another applet(Server applet) provided both the applets are located in different packages.Applets in different packages are separated by a firewall to prevent access to applet data across package.

Please check this simple implementation for shareable interface it will clear your doubts about its use case. https://stackoverflow.com/a/57200926/4752262

Upvotes: 0

vojta
vojta

Reputation: 5651

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.

Upvotes: 5

Related Questions