2

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.

Community
  • 1
  • 1
Mohsen Gorgani
  • 420
  • 4
  • 18

2 Answers2

5

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.
Community
  • 1
  • 1
vojta
  • 5,591
  • 2
  • 24
  • 64
  • 1
    Quoted from JC API Documentation : **shareable interface:** _an interface that defines a set of shared methods. These interface methods can be invoked from an applet in one context when the object implementing them is owned by an applet in another context._ Context is somehow a synonym for packages. – Ebrahim Ghasemi Nov 14 '16 at 07:14
  • Thanks all for your responds. i apology you for i cannot understand your answer. I have a simple question? i have two separate applet and i want to use some function in first applet to another one. these applet are completely different. it means they have different package AID and applet AID. Can i implement it by shareable interface? – Mohsen Gorgani Nov 14 '16 at 07:28
  • Thank Abraham and vojta again. what does it mean "They just both need to depend on the same package, which contains the shared interface." can you explain more about it? package means context? how should i install two different applet on a card that to be depended on the same package? – Mohsen Gorgani Nov 14 '16 at 07:35
  • thanks vojta. Is it possible to use only installed applet on card as server? because in real world i haven't access to server applet cap file to add it as library to client . it is only installed on card. is it possible? – Mohsen Gorgani Nov 14 '16 at 07:52
  • 1
    @MohsenGorgani If you don't have the `cap` file, the `exp` file will be enough. – vojta Nov 14 '16 at 09:25
  • how could i create a javacard library from exp file in netbeans? is it possible? – Mohsen Gorgani Nov 14 '16 at 14:26
  • it doesn't need to a jar file? – Mohsen Gorgani Nov 14 '16 at 14:48
  • @MohsenGorgani You need a `jar` file in order to create bytecode (`class` files) from your Java code. Then you need the `exp` file to convert Java bytecode to Java Card cap file using Java Card Converter. – vojta Nov 15 '16 at 09:50
  • should i convert myInterface.class to jar file or should i convert myInterfaceImpl.class? – Mohsen Gorgani Nov 15 '16 at 10:24
  • i copy the server.exp on jcdk_home/api_export_files but unfortunately netbeans can't find it. this is my config file -out EXP JCA CAP -exportpath . -applet 0x01:0x02:0x03:0x04:0x05:0x01 clientpackage.Client clientpackage 0x01:0x02:0x03:0x04:0x05 2.3 would you help me to solve the problem? – Mohsen Gorgani Nov 17 '16 at 08:42
  • @MohsenGorgani Sorry, I don't use Netbeans. Ask a separate question, someone will help you. – vojta Nov 17 '16 at 09:19
0

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ujjwal Roy
  • 500
  • 6
  • 9