1 / 9

Programming a Java Card

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

raoul
Download Presentation

Programming a Java Card

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 • Process commands send from the host • Deselection • Clean up and state saving • get SIO • Deliver the reverence of the own instance

  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( ... ) ----------------------

  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

  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 );

  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 -----------------

  6. Programming a Java Card (1) • The ISO-7816 APDU communication model Command APDU Response APDU Host Java Card

  7. Header (mandatory) Body (optional) CLA INS P1 P2 Lc DATA Le 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

  8. Body (optional) Trailer (mandatory) DATA SW1 SW2 Programming a Java Card (3) • Response APDU • Data - command optional response • SW1 and SW2 - status word

  9. RID register identifier PIX proprietary identifier extension 5 bytes 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

More Related