JavaCard Applet Development Related Questions and Answers.
-
sla1023
- Posts: 7
- Joined: Mon Feb 13, 2017 12:00 am
- Points :78
-
Contact:
Post
by sla1023 » Sun Feb 26, 2017 9:52 pm
Is there a way to send and receive messages between applets?
For example, is it possible to run the functions defined in the process function in A applet with the B applet?
For example code
A applet
Code: Select all
package Test
import javacard.framework.*;
public class A extends Applet
{
private A() {
}
public static void install(byte[] bArray, short bOffset, byte bLength)
{
new A().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu)
{
if (selectingApplet())
{
return;
}
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS])
{
case (byte)0x00:
// Send message to B applet(apdu or ....)
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
B applet
Code: Select all
package Test
import javacard.framework.*;
public class B extends Applet
{
private B() {
}
public static void install(byte[] bArray, short bOffset, byte bLength)
{
new B().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu)
{
if (selectingApplet())
{
return;
}
// Receive message from A applet(apdu or ...)
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS])
{
// Execute A applet message
case (byte)0x00:
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
-
UNKNwYSHSA
- Posts: 630
- Joined: Thu May 21, 2015 4:05 am
- Points :3055
-
Contact:
Post
by UNKNwYSHSA » Mon Feb 27, 2017 12:00 am
You want to process commands in different applet with one code block?
You can use the BasicService class.
AppletA:
Code: Select all
package testService;
import javacard.framework.*;
import javacard.framework.service.*;
public class AppletA extends Applet
{
public static void install(byte[] bArray, short bOffset, byte bLength)
{
new AppletA().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu)
{
if (selectingApplet())
{
return;
}
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS])
{
case (byte)0x00:
BasicService bs = theService.getInstance();
bs.processCommand(apdu);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
AppletB:
Code: Select all
package testService;
import javacard.framework.*;
import javacard.framework.service.*;
public class AppletB extends Applet
{
public static void install(byte[] bArray, short bOffset, byte bLength)
{
new AppletB().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu)
{
if (selectingApplet())
{
return;
}
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS])
{
case (byte)0x00:
BasicService bs = theService.getInstance();
bs.processCommand(apdu);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
The service:
Code: Select all
package testService;
import javacard.framework.service.BasicService;
import javacard.framework.APDU;
public class theService extends BasicService {
public static BasicService the_service;
public static BasicService getInstance() {
if (the_service == null) {
the_service = new theService();
}
return the_service;
}
public boolean processCommand(APDU apdu) {
fail(apdu, (short) 0x6600);
return true;
}
}
sense and simplicity
Users browsing this forum: Bing [Bot] and 56 guests
JavaCard OS : Disclaimer
Board Disclaimer
The views and comments posted in these fora are personal and do not necessarily represent the those of the Management of JavaCard OS.
The Management of JavaCard OS does not, under any circumstances whatsoever, accept any responsibility for any advice, or recommentations, made by, or implied by, any member or guest vistor of JavaCard OS that results in any loss whatsoever in any manner to a member of JavaCard OS, or to any other person.
Furthermore, the Management of JavaCard OS is not, and cannot be, responsible for the content of any other Internet site(s) that have been linked to from JavaCard OS.