Java Card Open Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc 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 Applet Install Select Process Deselect getShareableInterfaceObject
Java Card Open Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc 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 Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc page 3 Programming a Java Card (3) Selection / Deselection –When an ISO 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 Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc 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 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 Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc 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 Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc page 6 Programming a Java Card (1) The ISO-7816 APDU communication model Command APDU Response APDU Host Java Card
Java Card Open Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc 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) CLAINSP1P2 Body (optional) LcDATALe
Java Card Open Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc page 8 Programming a Java Card (3) Response APDU –Data - command optional response –SW1 and SW2 - status word Trailer (mandatory)Body (optional) SW1DATASW2
Java Card Open Platform Combines tomorrow's technology and platforms C:\Presentations - JavaCard_OpenPlatform.ppt - bsc page 9 Programming a Java Card (4) Naming conventions in Java Card All named resources use ISO 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 PIX proprietary identifier extension RID register identifier 5 bytes