What is the functionality of selectingApplet() method in JAVACARD2.2

时间秒杀一切 提交于 2019-12-11 09:35:35

问题


As mentioned in JavaCard 2.2 APIs documents here, selectingApplet() is a method that is used by the applet process() method to distinguish the SELECT APDU command which selected this applet, from all other SELECT APDU commands which may relate to file or internal applet state selection and it returns true if this applet is being selected.

My question is that Why we need this method? and even more general : Why the selected applet need to receive SELECT-applet commands? I think the only entity that need to know SELECT-applet APDUs is JCRE.

I suggest the below scenario :

  1. JCRE receive the APDU command from the CAD
  2. Check it to see if it is a SELECT APDU command or not.
  3. If it is not a SELECT APDU command, It sends the received APDU to the process() method of selected Applet. and the selected applet interpret and execute it (using switches and if expressions and no need to use selectingApplet() method)
  4. if it is a SELECT APDU command, check the length of the Data Field of the command to see if it is a SELECT File or it is a SELECT Applet.
  5. if it is SELECT File command, JCRE send it to the process() method of selected applet again. but if it is a SELECT Applet coomand, JCRE invoke deselet() method of currently selected applet and then invoke select() method of the new requested applet. and after receiving True, make it selected and wait for next APDU command.(and even no need to send the previous SELECT-Applet APDU command to process() method of this new selected applet)

What is wrong with the above implementation? and what is the advantages of current implementation in JC 2.2 (that sends all the receive APDUs to the process() method of currently selected applet and the selectingApplet() distinguish different SELECT commands)

I think the current implementation providing a vulnerability! if a programmer implement his/her applet in a way that its process() method writes all of received APDUs in EEPROM, the he/she can retrieve AID of some other installed applets on the card. is this right?


回答1:


You can use SELECT to distinguish between default selection after an ATR (a Global Platform option) and normal selection though SELECT. In other words, distinguish between being in the MF or application DF. The method select() will be called in both cases.

Furthermore, SELECT where P1 is different from 04 may return (FCI/FCP) data to the terminal. The runtime would not know what to return, as that is application specific.

selectingApplet() is very useful as you can immediately see that the Applet actually got (re-)selected with this method. If the applet gets reselected you may want to do some internal housekeeping, but you certainly don't want to return a status word indicating an error. An error would indicate that the APDU failed and this is inconsistent with the fact that the applet was selected by the runtime.




回答2:


Regarding your last point: no.
Because of the APDU is a valid AID of another applet, the JCRE will recognize that fact and not direct it to the current applet but deseclect the current applet and select the other applet referenced by the AID and call selectingApplet().
The selectingApplet() method is the only way that the applet knows it got selected in just this current APDU.
For example, it can be used to reset some file pointers or reset Securemessaging and other authentication status.

edit: i was referring to the default applet template, that goes like this:

process(){
if(selectingApplet()){
return;
}

So actually the method is just returning a boolean and in fact the normal process method is called but immidiatly terminated/finished or whatever.

On the other hand, select() method can be overwritten by the applet which will be called the first time its gets selected. There are no major diffrences between them(that i know) except that select gets called prior and can deny selection of th applet thus is more powerful(Might be useful for Interapplet communication)



来源:https://stackoverflow.com/questions/26816690/what-is-the-functionality-of-selectingapplet-method-in-javacard2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!