Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.4K Development
- 17 Developer Projects
- 139 Programming Languages
- 293.1K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 161 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 473 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Sharing Objects between Applets...
Hello!
i have information like that we can only share primitive data types by using shareable interface methods between two different applets which are under different context, different packages.
is it possible to share objects between applets??
i mean;
for example we have cardholder class which was written by us and in a java card applet we define a variable whose data type cardholder class.. can i have this variable and its reference from another applet which is under different package.
Thanks a lot in advance!
i have information like that we can only share primitive data types by using shareable interface methods between two different applets which are under different context, different packages.
is it possible to share objects between applets??
i mean;
for example we have cardholder class which was written by us and in a java card applet we define a variable whose data type cardholder class.. can i have this variable and its reference from another applet which is under different package.
Thanks a lot in advance!
Tagged:
Answers
-
Hi,
You can share objects as long as they are also shareable objects. For this they do not need to be an applet, just have an interface that extends Shareable.
Here is an example of a User class that is shareable like thispublic interface SharedUser extends Shareable { /** * @return the id */ public short getId(); /** * @return the name */ public short getName(byte[] buf, short off); } public class User implements SharedUser { private static short count = 1; private short id; private byte[] name; /** * */ public User() { id = count++; name = new byte[] { 'S', 'h', 'a', 'n', 'e' }; } /* (non-Javadoc) * @see oracle.other.SharedUser#getId() */ public short getId() { return id; } /* (non-Javadoc) * @see oracle.other.SharedUser#getName(byte[], short) */ public short getName(byte[] buf, short off) { return Util.arrayCopy(name, (short) 0, buf, off, (short) name.length); } } public interface SharedAccess extends Shareable { public SharedUser getUser(); } public class AccessApplet extends Applet implements SharedAccess { public static void install(byte[] bArray, short bOffset, byte bLength) { // GP-compliant JavaCard applet registration new AccessApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]); } /* * (non-Javadoc) * * @see javacard.framework.Applet#select() */ public boolean select() { return false; } public void process(APDU apdu) { return; } /* * (non-Javadoc) * * @see javacard.framework.Applet#getShareableInterfaceObject(javacard.framework.AID, byte) */ public Shareable getShareableInterfaceObject(AID clientAID, byte parameter) { return this; } /* * (non-Javadoc) * * @see oracle.other.SharedAccess#getUser() */ public SharedUser getUser() { return new User(); } }
You can add a method to your main SOI to return the shareable interface (SharedUser in this case) and then use that in your client applet. Be aware that the only way to get a byte array across a SOI is using the APDU buffer to copy. You will notice the getName method of the shared user takes an array rather than returning the array. The copy happens in the server context and the server is allowed to access the APDU buffer as it is global. If you return the name buffer or pass a buffer from the server you will get a security exception.
Cheers,
Shane
Edited by: safarmer on 13/07/2011 13:39 -
Here is the client applet. To illustrate the security issue INS 0x00 works, 0x01 returns 0x6F00 as I have no error handling.
public class Main extends Applet { private SharedAccess acc; private byte[] sharedAID = { 'a', 'c', 'c', 'e', 's', 's' }; private byte[] buffer = new byte[256]; /** * */ public Main(byte[] bArray, short bOffset, byte bLength) { register(bArray, (short) (bOffset + 1), bArray[bOffset]); AID aid = JCSystem.lookupAID(sharedAID, (short) 0, (byte) sharedAID.length); acc = (SharedAccess) JCSystem.getAppletShareableInterfaceObject(aid, (byte) 0); } public static void install(byte[] bArray, short bOffset, byte bLength) { // GP-compliant JavaCard applet registration new Main(bArray, bOffset, bLength); } public void process(APDU apdu) { // Good practice: Return 9000 on SELECT if (selectingApplet()) { return; } byte[] buf = apdu.getBuffer(); apdu.setIncomingAndReceive(); short rlen = 0; switch (buf[ISO7816.OFFSET_INS]) { case (byte) 0x00: Util.setShort(buf, (short) 0, acc.getUser().getId()); rlen = acc.getUser().getName(buf, (short) 2); apdu.setOutgoingAndSend((short) 0, rlen); break; case (byte) 0x01: Util.setShort(buffer, (short) 0, acc.getUser().getId()); rlen = acc.getUser().getName(buffer, (short) 2); apdu.setOutgoing(); apdu.setOutgoingLength(rlen); apdu.sendBytesLong(buffer, (short) 0, rlen); break; default: // good practice: If you don't know the INStruction, say so: ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); } } }
Cheers,
Shane -
Removed duplicate post as the forum wasn't posting my reply. I guess it did. Thanks Oracle : )
Edited by: safarmer on 13/07/2011 13:43 -
It works..and also i am using global apdu buffer to share byte arrays between applets.
Thanks a lot.. -
Dear,
You are using process(APDU apdu) method to get a global array which can be passed between applets. But I am developing a Telecom application, it is triggered by event through processToolkit(byte event) method, so the applet will not receive any apdu, then how can I get the APDU buffer? Thank you very much!
-
Dear Safarmer,
You are using process(APDU apdu) method to get a global array which can be passed between applets. But I am developing a Telecom application, it is triggered by event through processToolkit(byte event) method, so the applet will not receive any apdu, then how can I get the APDU buffer? Thank you very much!
This discussion has been closed.