📄 jcrespec08rmi.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML LANG="en"><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><META NAME="GENERATOR" CONTENT="Adobe FrameMaker 7.0/HTML Export Filter"><LINK REL="STYLESHEET" HREF="unx_unstr_styles.css" CHARSET="ISO-8859-1" TYPE="text/css"><META name="DC.TITLE" content="Runtime Environment Specification for the Java Card Platform, Version 2.2.2"><TITLE>C H A P T E R 8 - Remote Method Invocation Service </TITLE></HEAD><BODY BGCOLOR="#ffffff"><DIV><div class="navbar" align="center"><table dir="LTR" summary="Navigation bar, includes the book title and navigation buttons" width=100% cellpadding="0" cellspacing="0" border="0"><colgroup span="2" width="100%"><col id="1" span="1" width="50%"><col id="2" span="1" width="50%"><tr bgcolor="#cccccc"><td class="navbartitle" align=left rowspan="1" colspan="1" abbr="ChapTitle"> Runtime Environment Specification for the Java Card Platform, Version 2.2.2</td><td valign="top" align="right" rowspan="1" colspan="1" abbr="NavButtons"><a href="index.html"><img src="shared/toc01.gif" title="Table Of Contents" alt="Table Of Contents" width="30" height="26" border="0"></a><a href="JCRESpec07transact.html"><img src="shared/prev01.gif" title="Previous Chapter" alt="Previous Chapter" width="30" height="26" border="0"></a><a href="JCRESpec09api.html"><img src="shared/next01.gif" title="Next Chapter" alt="Next Chapter" width="30" height="26" border="0"></a><a href="ix.html"><img src="shared/index01.gif" title="Book Index" alt="Book Index" width="30" height="26" border="0"></a></td></tr></table><br><br></div></DIV><TABLE DIR="LTR" SUMMARY="Chapter Number" ABBR="ChapNum" WIDTH="100%" BORDER="0"><COLGROUP SPAN="1" WIDTH="100%"><COL ID="1" SPAN="1"><TR><TD ALIGN="right" CLASS="ChapNumber"><SPAN CLASS="ChapNumPrefix"><A NAME="pgfId-409401"></A>C H A P T E R </SPAN> <SPAN CLASS="ChapNumNum">8</SPAN><A NAME="53672"></A></TD></TR></TABLE><TABLE DIR="LTR" SUMMARY="Chapter Title" ABBR="ChapTitle" WIDTH="100%" BORDER="0"><COLGROUP SPAN="1" WIDTH="100%"><COL ID="1" SPAN="1" WIDTH="100%"><TR><TD ALIGN="right" CLASS="ChapTitle"><HR SIZE=7 NOSHADE><A NAME="pgfId-409406"></A><A NAME="66388"></A>Remote Method<A NAME="marker-420208"></A> Invocation <A NAME="marker-420175"></A>Service</TD></TR></TABLE><P CLASS="Paragraph"><A NAME="pgfId-416545"></A>Java Card platform Remote Method Invocation (Java Card RMI) is a subset of the Java platform Remote Method Invocation (RMI) system. It provides a mechanism for a client application running on the CAD platform to invoke a method on a remote object on the card. The on-card transport layer for Java Card RMI is provided in the package <KBD CLASS="Filename-Command">javacard.framework.service</KBD> by the class <KBD CLASS="Filename-Command">RMIService</KBD>. It is designed as a service requested by the Java Card RMI-based applet when it is the currently selected applet.</P><P CLASS="Paragraph"><A NAME="pgfId-416552"></A>The Java Card RMI message is encapsulated within the APDU object passed into the <KBD CLASS="Filename-Command">RMIService</KBD> methods.</P><H2 CLASS="Head1"><A NAME="pgfId-411693"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>8.1 <A NAME="marker-420174"></A>Java Card Platform RMI</H2><P CLASS="Paragraph"><A NAME="pgfId-411782"></A>This section defines the subset of the RMI system that is supported by Java Card platform RMI. </P><H3 CLASS="Head2"><A NAME="pgfId-417999"></A>8.1.1 Remote <A NAME="marker-420176"></A>Objects</H3><P CLASS="Paragraph"><A NAME="pgfId-418004"></A>A remote object is one whose remote methods can be invoked remotely from the CAD client. A remote object is described by one or more remote interfaces. A remote interface is an interface that extends, directly or indirectly, the interface <KBD CLASS="Filename-Command">java.rmi.Remote</KBD>. The methods of a remote interface are referred to as remote methods. A remote method declaration includes the exception <KBD CLASS="Filename-Command">java.rmi.RemoteException</KBD> (or one of its superclasses such as <KBD CLASS="Filename-Command">java.io.IOException</KBD> or <KBD CLASS="Filename-Command">java.lang.Exception</KBD>) in its <KBD CLASS="Filename-Command">throws</KBD> clause. Additionally, in the remote method declaration, a remote object declared as the return value must be declared as the remote interface, not the implementation class of that interface.</P><P CLASS="Paragraph"><A NAME="pgfId-416590"></A>Java Card RMI imposes additional constraints on the definition of remote methods. These constraints are a result of the Java Card platform language subset and other feature limitations.</P><H4 CLASS="Head3"><A NAME="pgfId-411773"></A>8.1.1.1 Parameters and Return Values</H4><P CLASS="Paragraph"><A NAME="pgfId-411698"></A>The parameters of a remote method must only include parameters of the following types:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-411699"></A>Any supported primitive data types</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1-"><A NAME="pgfId-411700"></A>Any single-dimension array of a supported primitive data type</LI><P CLASS="Linebreak"></P></UL><P CLASS="Paragraph"><A NAME="pgfId-411701"></A>The return value of a remote method must only be one of the following types:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-411702"></A>Any supported primitive data type</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1-"><A NAME="pgfId-417438"></A>Any single-dimension array type of a supported primitive data type</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1-"><A NAME="pgfId-417439"></A>Any remote interface type</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1-"><A NAME="pgfId-416631"></A>A void return</LI><P CLASS="Linebreak"></P></UL><P CLASS="Paragraph"><A NAME="pgfId-416632"></A>All parameters, including array parameters, are always transmitted by value during the remote method invocation. The return values from a remote method are transmitted by value for primitive types and arrays. Return values that are remote object references are transmitted by reference using a remote object reference descriptor.</P><H4 CLASS="Head3"><A NAME="pgfId-411706"></A>8.1.1.2 Exceptions</H4><P CLASS="Paragraph"><A NAME="pgfId-411708"></A>Java Card RMI uses the following simplified model for returning exceptions thrown by remote methods:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-411710"></A>When an exception defined in the Java Card API is thrown by a remote method, the exact exception type and the embedded reason code is transmitted to the client application. In essence, the exception object is transmitted by value.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-411811"></A>When an exception not defined in the Java Card API is thrown by a remote method, the "closest" superclass exception type from the API and the embedded reason code is transmitted to the client application. In this case, the "closest" API defined superclass exception object is transmitted by value. The client application can distinguish an inexact exception from an exact one. </LI><P CLASS="Linebreak"></P></UL><H4 CLASS="Head3"><A NAME="pgfId-411712"></A>8.1.1.3 Functional Limitations</H4><P CLASS="Paragraph"><A NAME="pgfId-411713"></A>The definition of the supported subset of Java Card RMI for the Java Card Platform, Version 2.2.2, implies functional limitations during the execution of Java Card API remote methods:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-411714"></A>CAD client application remote objects cannot be passed as arguments to remote methods.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-411821"></A>Card remote objects cannot be passed as arguments to remote methods.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-411822"></A>Applets on the card cannot invoke remote methods on the CAD client.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-417591"></A>Method argument data and return values, along with the Java Card RMI protocol overhead, must fit within the size constraints of an APDU command and APDU response, respectively.</LI><P CLASS="Linebreak"></P></UL><H2 CLASS="Head1"><A NAME="pgfId-411229"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>8.2 RMI <A NAME="marker-420179"></A>Messages</H2><P CLASS="Paragraph"><A NAME="pgfId-427291"></A>The Java Card RMI message protocol consists of two commands that are used to:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-416656"></A>Get the initial remote object reference for the Java Card RMI based applet. The initial remote object reference is the seed remote object that the CAD client application needs to begin remote method invocations.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-416657"></A>Send a remote method invocation request to the card.</LI><P CLASS="Linebreak"></P></UL><P CLASS="Paragraph"><A NAME="pgfId-416658"></A>To ensure that the protocol is compatible with all applications, the SELECT FILE command is used for getting the initial reference. The response to the SELECT FILE command allows the remote method invocation command itself to be customized by the applet.</P><H3 CLASS="Head2"><A NAME="pgfId-411237"></A>8.2.1 Applet <A NAME="marker-420180"></A>Selection</H3><P CLASS="Paragraph"><A NAME="pgfId-411312"></A>The selection command used to retrieve the initial reference is the ISO 7816-4 SELECT FILE command, with the following options in the header:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-416693"></A><STRONG CLASS="Lead-In2para">Direct selection by DF Name, that is, selection by AID.</STRONG> This is the normal option used to select all applet instances in the Java Card platform.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-416694"></A><STRONG CLASS="Lead-In2para">Return FCI (File Control Information - ISO7816-4), optional template.</STRONG> This is an additional option that indicates that the applet is expected to return FCI information.</LI><P CLASS="Linebreak"></P></UL><P CLASS="ParaIndent1"><A NAME="pgfId-418969"></A>In addition, an alternate RFU variant of the Return FCI option is required to configure the <KBD CLASS="Filename-Command">RMIService</KBD> for an alternate Java Card RMI protocol format. For more details see <A HREF="JCRESpec08rmi.html#79682" CLASS="XRef">Section 8.4.1, SELECT FILE Command</A>.</P><P CLASS="Paragraph"><A NAME="pgfId-411315"></A>The answer to this command is a constructed TLV (tag-length-value) data structure (ISO 7816-6) that includes the following information:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-411316"></A>The byte to be used as instruction byte (INS) for subsequent invocation commands.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1-"><A NAME="pgfId-411317"></A>The initial remote object reference descriptor. The descriptor includes the remote object identifier and information to identify the associated class.</LI><P CLASS="Linebreak"></P></UL><H3 CLASS="Head2"><A NAME="pgfId-411246"></A>8.2.2 Method <A NAME="marker-420181"></A>Invocation</H3><P CLASS="Paragraph"><A NAME="pgfId-411684"></A>To request a method invocation, the CAD client provides the following information:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-411300"></A><STRONG CLASS="Lead-In2para">The remote object identifier.</STRONG> This identifier is used to uniquely identify the object on the card.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-411301"></A><STRONG CLASS="Lead-In2para">The invoked method identifier.</STRONG> This designator uniquely identifies the remote method within the remote object class or superclass.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-411302"></A><STRONG CLASS="Lead-In2para">The values of the arguments.</STRONG> These values are raw values for primitive data types, and for arrays, a length followed by the values.</LI><P CLASS="Linebreak"></P></UL><P CLASS="Paragraph"><A NAME="pgfId-411303"></A>The response to the invocation request may include one of the following items:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-411304"></A><STRONG CLASS="Lead-In2para">A primitive return value.</STRONG> This is a raw primitive data type value.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-416383"></A><STRONG CLASS="Lead-In2para">An array of primitive components.</STRONG> This is a length followed by the raw primitive data type values.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-416397"></A><STRONG CLASS="Lead-In2para">A remote object reference descriptor.</STRONG> The descriptor includes the remote object identifier and information to instantiate a proxy instance of the remote card object.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-416395"></A>An exception. This is thrown by the remote method.</LI><P CLASS="Linebreak"></P></UL><H2 CLASS="Head1"><A NAME="pgfId-411251"></A><DIV><HR ALIGN=left SIZE=6 WIDTH=15% noshade></DIV>8.3 <A NAME="63243"></A>Data <A NAME="marker-420182"></A>Formats</H2><P CLASS="Paragraph"><A NAME="pgfId-411338"></A>This section describes the formats used to encapsulate the following:</P><UL><LI CLASS="Bullet1"><A NAME="pgfId-411339"></A>A remote object identifier that identifies the remote object on the card.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-411869"></A>A remote object reference descriptor that describes the remote object on the card for the CAD client.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-411870"></A>A method identifier that identifies the remote method on the card.</LI><P CLASS="Linebreak"></P><LI CLASS="Bullet1"><A NAME="pgfId-411871"></A>The method parameters and return values.</LI><P CLASS="Linebreak"></P></UL><P CLASS="Paragraph"><A NAME="pgfId-412355"></A>This section uses a C-like structure notation similar to that used in the <EM CLASS="Emphasis">Virtual Machine Specification, Java Card Platform, Version 2.2.2</EM>.</P><H3 CLASS="Head2"><A NAME="pgfId-411255"></A>8.3.1 Remote Object <A NAME="marker-420183"></A>Identifier</H3><P CLASS="Paragraph"><A NAME="pgfId-411347"></A>A remote object identifier is a 16-bit unsigned number that uniquely identifies a remote object on the card. </P><H3 CLASS="Head2"><A NAME="pgfId-411263"></A>8.3.2 <A NAME="89167"></A>Remote <A NAME="marker-420184"></A>Object Reference Descriptor</H3><P CLASS="Paragraph"><A NAME="pgfId-416728"></A>The remote object reference descriptor includes the remote object identifier, as well as information to instantiate the proxy class on the CAD client. The remote object reference descriptor uses one of two alternate formats. The representation based on the name of the class uses the <KBD CLASS="Filename-Command">remote_ref_with_class</KBD> format. The representation based on the names of the implemented remote interfaces uses the <KBD CLASS="Filename-Command">remote_ref_with_interfaces</KBD> format.</P><P CLASS="Paragraph"><A NAME="pgfId-416749"></A>A remote object reference descriptor is therefore defined as follows:</P><DIV CLASS="Code"><BR><TABLE CLASS="Code" BORDER=1 BORDERCOLORLIGHT="#FFFFFF" BORDERCOLORDARK="#000000" CELLPADDING=5 CELLSPACING=0 DIR="LTR"><TBODY><TR><TD SCOPE="ROW"><PRE CLASS="ScreenText"><A NAME="pgfId-428743"></A>remote_ref_descriptor {</PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -