How can I share Pin variable between two packages?
Hi every one,
Is there any one who knows how can I share Pin variable that it is defined with OwnerPin between two packages in java card( with eclipse 3.1),I studied Sharing Interface subject and I knows it teorical but I can not do it practical .
I can share primitive data type but I can not share Ownerpin.
If anybody has some sample codes or knows any link ,please inform me.
My code is same as below:
//In Server Side
package ginaPack;
import javacard.framework.*;
publicclass GinaAppletextends Appletimplements GinaInterface{
OwnerPIN pin;
private GinaApplet (byte[] bArray,short bOffset,byte bLength){
pin =new OwnerPIN(PIN_TRY_LIMIT,MAX_PIN_SIZE);
byte PinTemp[] =newbyte[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);
}
public Shareable getShareableInterfaceObject(AID clientAID,byte parameter)
{
returnthis;
}
public OwnerPIN getPinShareable()
{
return pin;
}
publicvoid process(APDU apdu)
{
//there are some codes in this here
}
}
//Interface in Server side
publicinterface GinaInterfaceextends Shareable
{
public OwnerPIN getPinShareable();
}
//In Client side
import ginaPack.*;
publicclass UserCardAppletextends Applet{
private UserCardApplet(byte[] bArray,short bOffset,byte bLength){
//there are some codes in this here
}
publicboolean select(){
finalbyte[] Gina_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 ( GinaAID ==null )// probably not loaded on card
{
ISOException.throwIt( ISO7816.SW_FUNC_NOT_SUPPORTED );//6a 80
}
GinaInterface ff = (GinaInterface) JCSystem.getAppletShareableInterfaceObject(GinaAID,(byte)0);
if( ff ==null )
{
ISOException.throwIt((short)0x0903);
}
if ( ff.getPinShareable().getTriesRemaining()== 0 )returnfalse;
}
My problem is in this line :
"if ( ff.getPinShareable().getTriesRemaining()== 0 ) return false; "when I select my applet this line throw an exception, ff.getPinshareable includes all of OwnerPin methods(such as getTriesRemaining ,check ,reset, update ,...)but all of them throw exception .
I think firewal does not allow other packages uses this methods .If my guess is right then what should I do for sharing the variables that they are defined with non primitive data type such as (OwnerPin,Signature,...)
I'd appriciated for any help.
yours sincerely,
Orchid.
Message was edited by:
NewOrchid
[5815 byte] By [
NewOrchida] at [2007-11-26 17:38:15]

# 1
Applet 1:
package com.package1;
import javacard.framework.*;
public class Applet1 extends Applet {
private static final byte tryLimit = (byte)3;
private static byte[] pinBytes = {(byte)1, (byte)7, (byte)4, (byte)5, (byte)2};
private Library1 lib;
protected Applet1(byte bArray[], short bOffset, byte bLength) throws PINException {
lib= new Library1(tryLimit, (byte)pinBytes.length);
lib.update(pinBytes, (short)0, (byte)pinBytes.length);
register();
}
public static void install(byte[] bArray, short bOffset, byte bLength) {
new Applet1(bArray, bOffset, bLength);
}
public void process(APDU apdu) {
byte status=(byte)0;
lib.resetAndUnblock();
if (!(lib instanceof Shareable)) status += (byte)2;
if (!(lib instanceof MyPIN)) status += (byte)4;
ISOException.throwIt(Util.makeShort((byte)0x90, status)); // sw indicates tries remaining
}
public Shareable getShareableInterfaceObject(AID cltAID, byte parm) {
return lib;
}
}
Library1:
package com.package1;
import javacard.framework.OwnerPIN;
import javacard.framework.PINException;
public class Library1 extends OwnerPIN implements Interface1{
public Library1(byte tryLimit, byte maxPINSize) throws PINException {
super(tryLimit, maxPINSize);
}
}
Interface1:
package com.package1;
import javacard.framework.PIN;
import javacard.framework.Shareable;
public interface Interface1 extends Shareable {
boolean check(byte[] pin, short offset, byte length);
byte getTriesRemaining();
boolean isValidated();
void reset();
}
Applet2:
package com.package2;
import javacard.framework.*;
import com.package1;
public class Applet2 extends Applet {
private final static byte CLA_TEST = (byte)0x80;
private final static byte INS_TEST = (byte)0x20;
private final static byte P1_AUTHORIZE = (byte)0x00;
private final static byte P1_DOIT = (byte)0x01;
private final static byte P1_CHECK_SIO = (byte)0x0a;
private Interface1 sio;
protected Applet2(byte bArray[], short bOffset, byte bLength) {
register();
}
public static void install(byte[] bArray, short bOffset, byte bLength) {
new Applet2(bArray, bOffset, bLength);
}
public void process(APDU apdu) {
byte[] buffer = apdu.getBuffer();
if ((buffer[ISO7816.OFFSET_CLA] == CLA_TEST) ||
(buffer[ISO7816.OFFSET_CLA] == ISO7816.CLA_ISO7816)) {
short bytesReceived = apdu.setIncomingAndReceive();
switch (buffer[ISO7816.OFFSET_INS]) {
case ISO7816.INS_SELECT:
if (!JCSystem.getAID().equals(buffer, ISO7816.OFFSET_CDATA, buffer[ISO7816.OFFSET_LC]))
ISOException.throwIt(ISO7816.SW_APPLET_SELECT_FAILED);
sio = (Library1)JCSystem.getAppletShareableInterfaceObject(JCSystem.lookupAID(<fill in parameters>);
if (sio == null)
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
break;
case INS_TEST:
switch (buffer[ISO7816.OFFSET_P1]) {
case P1_AUTHORIZE:
if (!sio.isValidated()) {
if(!sio.check(buffer, ISO7816.OFFSET_CDATA, buffer[ISO7816.OFFSET_LC]))
ISOException.throwIt(Util.makeShort((byte)0x9A, sio.getTriesRemaining()));
}
break;
case P1_DOIT:
if (!sio.isValidated())
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
sio.reset();
ISOException.throwIt(Util.makeShort((byte)0x9A, sio.getTriesRemaining()));
break;
default:
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
else {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
}
}
1. Upload package1
2. Install Applet1
3. Select Applet1
4. Upload package2
5. Install Applet2
6. Select Applet2