JCSystem.getAppletShareableInterfaceObject返回6f00

时间:2016-11-12 14:30:33

标签: applet smartcard javacard

我对javacard可共享对象有疑问。我想通过以下链接从客户端服务器读取共享数组:[JavaCard: How can an applet's instance call a method in another instance's context?

当我调用函数

时,我有一个客户端和一个服务器applet
theSharedArray = (SharedArray) JCSystem.getAppletShareableInterfaceObject(masterAID, SHARABLE_PARAM);

在客户端它返回6f00。 客户端小程序是:

public class Client extends Applet implements ISO7816 {

    private static final byte SHARABLE_PARAM = 0;
    public interface SharedArray extends Shareable {
        public byte[] getSharedArray();
    }

    public static class SharedArrayImpl implements SharedArray {
        private byte[] sharedArray;

        public SharedArrayImpl(final byte[] arrayToShare) {
            this.sharedArray = arrayToShare;
        }

        public byte[] getSharedArray() {
            return sharedArray;
        }
    }


    byte[] idinAID = new byte[]{(byte)0xA0, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00, 0x10, 0x00};
    private AID masterAID = new AID(idinAID, (short) 0, (byte) idinAID.length);

    public static void install(byte[] bArray, short bOffset, byte bLength) throws SystemException {
        new Client().register(bArray, (short) (bOffset + 1),
                bArray[bOffset]);
    }

    private Client() {        

    }

    public void process(APDU apdu) {

        if (selectingApplet()) {
            return;
        }

        byte[] buf = apdu.getBuffer();
        byte cla = buf[OFFSET_CLA];
        byte ins = buf[OFFSET_INS];

        switch (ins) {
            case (byte) 0x03: 
                sendOut(apdu);
                break;            
            default:
                ISOException.throwIt(SW_INS_NOT_SUPPORTED);
        }
    }

    public void sendOut(APDU apdu)
    {
        final SharedArray theSharedArray;

        theSharedArray = (SharedArray) JCSystem.getAppletShareableInterfaceObject(masterAID, SHARABLE_PARAM);
        byte[] sa = theSharedArray.getSharedArray();
        apdu.setOutgoing();
        apdu.setOutgoingLength((short) 10);
        apdu.sendBytesLong(sa, (short) 0, (short) 10);
    }


}

,服务器小程序是:

public class SharingApplet extends Applet {

    public interface SharedArray extends Shareable {
        public byte[] getSharedArray();
    }

    public static class SharedArrayImpl implements SharedArray {
        private byte[] sharedArray;

        public SharedArrayImpl(final byte[] arrayToShare) {
            this.sharedArray = arrayToShare;
        }

        public byte[] getSharedArray() {
            return sharedArray;
        }
    }


    private static final byte PARAM_SHARED_ARRAY = 0;

    private final SharedArray sharedArray;
    byte[] idinAID = new byte[]{(byte)0xA0, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00, 0x10, 0x00};
    private AID masterAID = new AID(idinAID, (short) 0, (byte) idinAID.length);

    public static void install(byte[] bArray, short bOffset, byte bLength) {
        new SharingApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
    }

    public SharingApplet() {
        sharedArray = new SharedArrayImpl(idinAID);       
    }

    public void process(APDU apdu) {
        if (selectingApplet()) {
            return;
        }

        byte[] buf = apdu.getBuffer();
        switch (buf[ISO7816.OFFSET_INS]) {

        case (byte) 0x03:
        {
            apdu.setOutgoing();
            apdu.setOutgoingLength((short) 9);
            apdu.sendBytesLong(idinAID, (short) 0, (short) 9);
            break;
        }               
        default:
            ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
        }
    }

    public Shareable getShareableInterfaceObject(AID clientAID, byte parameter) {
        if (sharedArray == null || parameter != PARAM_SHARED_ARRAY) {
            return null;
        }
        return sharedArray;
    }
}

如果有人能帮助我,我将不胜感激。 感谢

0 个答案:

没有答案