简体   繁体   English

关于Javacards中SELECT APDU命令的一些问题

[英]Some questions about SELECT APDU command in Javacards

The quoted below passage is a part of an article that named How to write a Java Card applet: A developer's guide and written by Zhiqun Chen. 下面引用的段落是一篇名为“ 如何编写Java Card小程序 ”的文章的一部分:开发人员指南 ,由Zhiqun Chen撰写。

I saw it here 我在这里看到

Once an applet is selected, the JCRE forwards all subsequent APDU commands (including the SELECT command) to the applet's process() method. 选择applet后,JCRE会将所有后续APDU命令(包括SELECT命令)转发到applet的process()方法。 In the process() method, the applet interprets each APDU command and performs the task specified by the command. 在process()方法中,applet解释每个APDU命令并执行命令指定的任务。 For each command APDU, the applet responds to the CAD by sending back a response APDU, which informs the CAD of the result of processing the command APDU. 对于每个命令APDU,小应用程序通过发回一个响应APDU来响应CAD,该响应APDU通知CAD处理命令APDU的结果。 The process() method in class javacard.framework.Applet is an abstract method: a subclass of the Applet class must override this method to implement an applet's functions." 类javacard.framework.Applet中的process()方法是一个抽象方法:Applet类的子类必须覆盖此方法才能实现applet的功能。“


Update : 更新:

And also the below passage is a part of an Oracle article that named Writing A JavaCard Applet ( Here ): 此外,下面的段落是Oracle文章的一部分,该文章名为Writing A JavaCard AppletHere ):

Examines the Header 检查标题

The process method examines the first two bytes of the APDU header, the CLA byte and INS byte. 处理方法检查APDU头的前两个字节,CLA字节和INS字节。 If the value of the CLA byte is 0 and the value of the INS byte is 0xA4, it indicates that this is the header of a SELECT APDU command. 如果CLA字节的值为0且INS字节的值为0xA4,则表示这是SELECT APDU命令的标头。 In this case, the process method returns control to the JCRE: 在这种情况下,process方法将控制权返回给JCRE:

// check SELECT APDU command 
if ((buffer[ISO7816.OFFSET_CLA] == 0) &&
(buffer[ISO7816.OFFSET_INS] == (byte) (0xA4)) )  
 return;

在此输入图像描述 Q0: In the above Image App1 was selected already. Q0:在上面的图像中已经选择了App1。 when the new SELECT APP2 command receive by JCRE , What it do? 当新的SELECT APP2命令由JCRE接收时,它做什么? It refers it to the process() method of App1 and receives a return from it? 它将它引用到App1process()方法并从中接收返回值? Or it call deselect() method of App1 and then call select() method of App2 ? 或者它调用App1的 deselect()方法然后调用App2的 select()方法?

If JCRE sends the SELECT App2 APDU command to process() method of App1 , what happens after receiving a Return from it?! 如果JCRE将SELECT App2 APDU命令发送到App1的 process()方法,收到返回后会发生什么?!

If JCRE right after receiving SELECT App2 APDU command, call deselect() of app1 and then call select() of app2, what it do after receiving true from app2 select() method? 如果JCRE在收到SELECT App2 APDU命令之后立即调用app1的deselect()然后调用app2的select(),它从app2 select()方法收到true之后会做什么? Does it wait for next command? 它等待下一个命令吗?


Q1 : Based on the above passage(Specially the part that is in bold) I conclude that I can write an applet that as it selected, Its impossible to select another applet(Until the card remove from the CAD).For this purpose we just need to write a code in its process() method to select itself when it receive a SELECT APDU command. Q1:基于上面的段落(特别是粗体部分)我得出结论,我可以编写一个applet,因为它选择了,它不可能选择另一个applet(直到卡从CAD中删除)。为此我们只是需要在其process()方法中编写代码,以便在收到SELECT APDU命令时自行SELECT APDU Is this right? 这是正确的吗?

Q2 : Is there any way to deselect an applet without sending another select command or removing the card from CAD? Q2:有没有办法取消选择applet而不发送另一个select命令或从CAD中删除卡?

Q3 : Is is possible to write an applet in a way that it remains active in the background of another active applet? 问题3:是否可以以在另一个活动applet的后台保持活动的方式编写applet? (something like a key-loggers in computers) I myself think it is impossible because of incompatibility of java card with multi-threading . (类似于计算机中的键盘记录器)我自己认为这是不可能的,因为java卡与多线程不兼容。 Is that right? 是对的吗?

Appreciate any help. 感谢任何帮助。

Q0 (update) : If a SELECT by NAME is received for a that does not select the current applet then: Q0(更新) :如果收到一个没有选择当前applet的SELECT by NAME,则:

  • if another Applet is selected then only the deselect method is called 如果选择了另一个Applet,则只调用deselect方法
  • if no other Applet is selected then only the process method is called 如果未选择其他Applet,则仅调用process方法

Q1 : No. The system will still handle all the SELECT by NAME APDU's before it forwards it to the Applet process method. Q1 :不会。系统仍会处理所有SELECT by NAME APDU,然后再转发给Applet process方法。 So another Applet can be selected before the SELECT is send to the currently selected applet, and the newly selected Applet will receive the APDU instead. 因此,在将SELECT发送到当前选定的applet之前,可以选择另一个Applet,而新选择的Applet将接收APDU。

Note that the system will even re-select the current Applet if a SELECT by NAME is received with the current Applet's AID (so all memory and objects that are cleared on deselect will be cleared, and the select and deselect methods will be called). 请注意,如果使用当前Applet的AID接收到SELECT by NAME,系统甚至会重新选择当前Applet(因此将取消选择取消选择时清除的所有内存和对象,并调用selectdeselect方法)。

Note that later API's (Chen's book is still applicable, but aging a bit) have added a method to check if the APDU was used to select the current Applet. 请注意,后来的API(陈的书仍然适用,但有点老化)添加了一种方法来检查APDU是否用于选择当前的Applet。 This is also useful to check how it was selected, which primarily is useful if the Applet is also selected by default , ie before any APDU was received. 这也是有用的检查它是如何选择的,如果小程序也被默认选择 ,即任何APDU被接收之前这主要是有用的。

Q2 : No, currently not. Q2 :不,目前没有。 This is tricky functionality that will have firewall and security implications. 这是一个棘手的功能,具有防火墙和安全隐患。 So this would not be a minor update to the Java Card standard. 所以这不是Java Card标准的一个小更新。 It comes up quite a lot on the forums though. 它虽然在论坛上出现了很多。 You may access other applets through the firewall of course. 当然,您可以通过防火墙访问其他小程序。

Q3 : There are indeed no background tasks. 问题3 :确实没有后台任务。 Adding multi-threading would completely break the API of Java Card Classic Edition, so it will never be added. 添加多线程将完全打破Java Card Classic Edition的API,因此永远不会添加它。 To share information both Applets must be explicitly designed to do so, and the firewall rules will be in effect. 要共享信息,必须明确设计Applet,防火墙规则才会生效。

Q0 : If a SELECT by NAME is received JCRE will check if AID specified in APDU partialEquals() any AID registered by JCRE. Q0 :如果收到SELECT by NAME,JCRE将检查APDU partialEquals()中指定的AID是否由JCRE注册的任何AID。 If there is no such AID registered by JCRE, the SELECT by NAME APDU will be sent to the currently selected applet. 如果JCRE没有注册此类AID,则SELECT by NAME APDU将被发送到当前选定的applet。 If such AID is registered by JCRE, no matter what applet is currently selected, the currently selected applet will be deselected (invoking deselect()) and the applet with matching AID will be selected (calling select() and passing selectingApplet()=True to process()). 如果JCRE注册了这样的AID,无论当前选择了什么applet,都将取消选择当前选择的applet(调用deselect())并选择匹配AID的applet(调用select()并传递SelectingApplet()= True处理())​​。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM