How can I implement delegate for Object sharing in java card?

Hello everyone,

I work on JCOP31 smart card and I wrote two packages on tha card with eclipse 3.1.2 ,I need share a variable that it is return value of a function between two packages.as far as I know I can do this with delegate but I do not know how can I use and implement delegate,I just see one article in internet ("Secure Object sharing in java card"),it was very useful for me but when I want to implement its code in the eclipse I get some errors . My code is same as below :

public class ABCLoyaltyDelegate extends Delegate {

}

I get an error on Delegate word ,the error is "Delegate can not resolved to a type ",maybe I need to import something but I do not know.

in this article there is "import OSResources" but what is OSResources ?

I'd appriciate for any help about delegate.

yours sincerely,

Orchid.

[870 byte] By [NewOrchida] at [2007-11-26 17:18:21]
# 1

Can't you use the Shareable interface?

As far as I understand the article you are referencing, it is not JC compliant. quoting the abstract:

An approach to object sharing is baden on delegates id described, which provides needed improvements with minimal modifications to Java Card 2.1. ..

The delegate approach is not part of JC. That is why you are getting the error.

lexdabeara at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 2

Dear lexdabear,

thanks alot for your reply.

I have some questions:

First,how can you understand the article is not JC compliant?

Second,I study Shareable Interface but as far as I understand ,I can not return an Object from server to client with this way ,for example I need to share the Pin variable that it is defined with "OwnerPin" type but Shareable Interface cannot do this or I do not know how can do this.

if it is possible for you please describe me how can I share Pin between 2 packages .

I 'd appriciated for your help,

yours sincerely,

Orchid

NewOrchida at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 3
Dear lexdabear,Sorry, I did not attention exactly , you answered the first question completely please help me on second question.yours sincerely ,OrchidMessage was edited by: NewOrchid
NewOrchida at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 4
Dear lexdabear,Sorry, I did not attention exactly , you answered the first question completely please help me on second question.yours sincerely ,OrchidMessage was edited by: NewOrchid
NewOrchida at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 5

Test case from the JC-TCK (Sun IP)

package1:

- Applet1 extends Applet

- Shareable Interface1(includes methods that have to pass the Applet firewall)

- Library1 extends OwnerPin, implements Interface1

Applet1 creates in the constructor a pin object of type Library1and initialized the pin with update().

package2, imports Library1

- Applet2 extends Applet

Applet 2 fetches (during select) the shareable interface object (pin) via JCSystem method:myPIN = (Library1)JCSystem.getAppletShareableInterfaceObject(JCSystem.lookupAID(..<Applet1 AID>...);

lexdabeara at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 6

Dear lexdabear,

Thanks a lot for your reply,

you mentioned ,"Library1 extends OwnerPin, implements Interface1",my question is about Library1 ,how can I create a library in eclipse ?I created an applet and an Interface but I do not know how can I create a Library,if it is possible for you ,please describe it clearly.

thanks a alot again and again,

yours sincerely ,

Orchid.

NewOrchida at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 7
It is just a name I chose: A library is a class that is not an Applet (does not extend Applet).
lexdabeara at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 8

Dear lexdabear,

I created 2 applet on different packages ,my code is same as below:

In Applet1:

public class Applet1 extends Applet{

Library1 pin;

private Applet1 (byte[] bArray,short bOffset,byte bLength) {

pin =new Library1(PIN_TRY_LIMIT,MAX_PIN_SIZE);

byte PinTemp[] = new byte[4];

PinTemp[0] = (byte) 0x31;PinTemp[1] = (byte) 0x31;

PinTemp[2] = (byte) 0x31;PinTemp[3] = (byte) 0x31;

pin.update(PinTemp, (short) (0), (byte) PinTemp.length);

register();

}

public Shareable getShareableInterfaceObject(AID clientAID,byte parameter)

{

return this;

}

public void process(APDU apdu) {

..........

}

}

//

In Interface1:

[code]public interface GinaInterface extends Shareable

{

// There is not any method to pass applet firewall except Pin,I leave thisinterface empty

}

//-

in Library1:

public class Library1 extends OwnerPIN implements Interface1{

public Library1(byte tryLimit, byte maxPINSize)

{

super(tryLimit,maxPINSize);

}

}

In Applet2:

import MyPackages1.Library1;

public class Applet2 extends Applet {

private UserCardApplet(byte[] bArray, short bOffset, byte bLength) {

....

public boolean select() {

final byte[] Applet1_AID={(byte)0x47,(byte)0x69,(byte)0x6e,(byte)0x61,(byte)0x41,(byte)0x70,(byte)0x70,(byte)0x6c,(byte)0x65,(byte)0x74};

AID GinaAID = JCSystem.lookupAID( Gina_AID, ( short )0,( byte)Gina_AID.length );

if ( Applet1_AID == null ) // probably not loaded on card

{

ISOException.throwIt( ISO7816.SW_FUNC_NOT_SUPPORTED );//6a 80

}

OwnerPIN ff;

ff = (Library1) JCSystem.getAppletShareableInterfaceObject(Applet1_AID,(byte)0);

if( ff == null )

{

ISOException.throwIt((short)0x0903);

}

}

[/code]

when I debug Applet2 I get an error on the top of package ,it is :

"resolving Constant-pool of clazz LMyPackage2/Applet2;failed:no such clazz LMyPackage1/Library1"

I think it is related to library1 that I cast in this line:

ff = (Library1) JCSystem.getAppletShareableInterfaceObject(Applet1_AID,(byte)0);

I defined ff with OwnerPin type ,is it right ?when I change it to Library1 there is this error again.

as you see in above code I leave empty the body of Interface1 because I do not have any method to pass Applet1 firewal,I want to share just Pin,am I right or no?

I do not know what is my mistake in Sharing Interface Object Pin ,Please help me

Sincerely yours,

Orchid

NewOrchida at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 9
As mentoined before, you need to include in the shareable interface the methods you want to share. Do not leave it empty, but put in methods from OwnerPin.
lexdabeara at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 10
Dear lexdabear,Thanks a lot for your help,My problem is solved by your guid,your thank you very much.Yours sincerely ,Orchid.
NewOrchida at 2007-7-8 23:46:20 > top of Java-index,Java Mobility Forums,Consumer and Commerce...