If your applets must be compliant with the ISO/IEC 7816-4:2013 specification, then you must track the applet security state on each channel where it is active. Additionally, in the case of multiselectable applets, you must copy the state (including its security configuration) when you perform MANAGE CHANNEL
commands from a channel other than the basic channel.
For example, applets might need to perform some sort of initialization upon activation, as well as cleanup procedures during deactivation. To do these tasks, a multiselectable applet might need to keep track of the channels on which it is being selected during a card session.
To track this information, you need to know the channel on which the task is being performed. Tracking is done by two methods in the Java Card API:
APDU
class: public static byte getCLAChannel();
This method returns the origin channel where the command was issued. In case of MANAGE CHANNEL
or SELECT FILE
commands, if this method is called within the Applet.select()
, MultiSelectable.select(boolean)
, Applet.deselect()
, or MultiSelectable.deselect(boolean)
methods, it returns the APDU command logical channel specified in the CLA byte.
JCSystem
class: public static byte getAssignedChannel();
This method returns the channel of the currently selected applet. In case of a MANAGE CHANNEL
command, if this method is invoked inside the Applet.select()
, MultiSelectable.select(boolean)
, Applet.deselect()
, or MultiSelectable.deselect(boolean)
methods, it returns the channel where the applet to be selected or deselected is assigned to run.