Upload
raoul
View
33
Download
0
Embed Size (px)
DESCRIPTION
Applet. Install. Select. Process. Deselect. getShareableInterfaceObject. Programming a Java Card. The Applet Model Installation Create an applet instance Register the applet with the JCRE Selection Select the applet, do some initialization Processing - PowerPoint PPT Presentation
Citation preview
Java Card Open PlatformCombines tomorrow's technology and platforms
C:\Presentations - JavaCard_OpenPlatform.ppt - bsc - 26.02.02 - page 1
Programming a Java Card
• The Applet Model– Installation
• Create an applet instance• Register the applet with the JCRE
– Selection• Select the applet, do some initialization
– Processing• Process commands send from the host
– Deselection• Clean up and state saving
– get SIO• Deliver the reverence of the own instance
AppletInstall
Select
Process
Deselect
getShareableInterfaceObject
Java Card Open PlatformCombines tomorrow's technology and platforms
C:\Presentations - JavaCard_OpenPlatform.ppt - bsc - 26.02.02 - page 2
Programming a Java Card (2)
• Installation– Create an Applet instance
– Call the Constructor
– Create Applet objects
– Register the Applet with the JCRE
– Do Error Handling
package com.gieseckedevrient.applets.myfirst;
import javacard.framework.*;
public class MyFirst extends Applet{ // ---------------------------------------------- // Constructor // ---------------------------------------------- private MyFirst () {
register (); } // -- END - static elements ---------------------
// ---------------------------------------------- // Install method // ----------------------------------------------------------------- public static void install(byte[] buffer, short offset, byte length) { new MyFirst(); } // -- END - Public static void install( ... ) ----------------------
Java Card Open PlatformCombines tomorrow's technology and platforms
C:\Presentations - JavaCard_OpenPlatform.ppt - bsc - 26.02.02 - page 3
Programming a Java Card (3)• Selection / Deselection
– When an ISO 7816-4 select command is received
– JCRE checks if the AID corresponds to an registered applet
– If so, the active applet is first deselected and the applet with the correct AID is selected
– Otherwise the command is transfered to the selected applet for processing
• Command Processing– Get the APDU buffer
– Decode the command header
– Receive command data if needed
– Perform command
– Send response– Throw ISOException if status is not 90 00
Java Card Open PlatformCombines tomorrow's technology and platforms
C:\Presentations - JavaCard_OpenPlatform.ppt - bsc - 26.02.02 - page 4
Programming a Java Card (8) - Processing (1)
public void process(APDU o_apdu) throws ISOException
{
if( selectingApplet() )
{
m_sz_Verified = false;
return;
}
byte[] ba_buffer = o_apdu.getBuffer();
//Examination of the buffer.
switch( ba_buffer[ ISO7816.OFFSET_INS ] )
{
//PIN Verification as defined in ISO 7816-4.
case VERIFY: // ----------------------------
s_databytes = receive( o_apdu );
s_dataoffset = Util.getShort( ba_buffer, ISO7816.OFFSET_P1 );
b_result = Util.arrayCompare( ba_buffer, (short) (ISO7816.OFFSET_CDATA & 0x00FF), m_sba_aPin, (short)0,
s_databytes );
Java Card Open PlatformCombines tomorrow's technology and platforms
C:\Presentations - JavaCard_OpenPlatform.ppt - bsc - 26.02.02 - page 5
Programming a Java Card (8) - Processing (2) if( b_result == (byte)0x00 )
{
m_sz_Verified = true;
}
else
ISOException.throwIt( ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED );
break;
case READ: // -----------------------------------------------------
if( !m_sz_Verified )
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
o_apdu.setOutgoing();
o_apdu.setOutgoingLength( (short) 80 );
o_apdu.sendBytesLong( m_sba_userdata, (short)0, (short)80 );
break;
default : // ------------------------------------------------------
ISOException.throwIt( ISO7816.SW_INS_NOT_SUPPORTED );
}
} // -- END - public void process( ... ) throws ISOException -----------------
Java Card Open PlatformCombines tomorrow's technology and platforms
C:\Presentations - JavaCard_OpenPlatform.ppt - bsc - 26.02.02 - page 6
Programming a Java Card (1)
• The ISO-7816 APDU communication model
Command APDU
Response APDU
Host Java Card
Java Card Open PlatformCombines tomorrow's technology and platforms
C:\Presentations - JavaCard_OpenPlatform.ppt - bsc - 26.02.02 - page 7
Programming a Java Card (2)
• Command APDU
– CLA - indicates the type of command (ISO, prop.)
– INS - specifies the instruction to be performed
– P1 and P2 - instruction parameters
– Lc - number of bytes in the data field
– Data - command optional data
– Le - number of bytes expected in the response
Header (mandatory)
CLA INS P1 P2
Body (optional)
Lc DATA Le
Java Card Open PlatformCombines tomorrow's technology and platforms
C:\Presentations - JavaCard_OpenPlatform.ppt - bsc - 26.02.02 - page 8
Programming a Java Card (3)
• Response APDU
– Data - command optional response
– SW1 and SW2 - status word
Trailer (mandatory)Body (optional)
SW1DATA SW2
Java Card Open PlatformCombines tomorrow's technology and platforms
C:\Presentations - JavaCard_OpenPlatform.ppt - bsc - 26.02.02 - page 9
Programming a Java Card (4)
• Naming conventions in Java Card
• All named resources use ISO 7816-5 AIDs
• Named resources are– Packages (for loading, linking and deletion)– Applet Classes (for installation of applets)– Applet Instances (the real card applications)
0 to 11 bytes
PIXproprietary identifier extension
RIDregister identifier
5 bytes