| Код | /* * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */
// /* // Workfile:@(#)HelloWorld.java 1.7 // Version:1.7 // Date:01/03/06 // // Archive: /Products/Europa/samples/com/sun/javacard/samples/HelloWorld/HelloWorld.java // Modified:01/03/06 12:13:08 // Original author: Mitch Butler // */ package test;
import javacard.framework.APDU; import javacard.framework.Applet; import javacard.framework.ISO7816; import javacard.framework.ISOException; import javacard.framework.Util;
import javacard.framework.APDU; import javacard.framework.Applet; import javacard.framework.ISO7816; import javacard.framework.ISOException;
public class HelloWorld extends Applet {
/** * Instruction: say hello */ private final static byte SAY_HELLO_INS = (byte) 0x01; /** * Instruction: do nothing */ private final static byte DO_NOTHING_INS = (byte) 0x02;
/** * Byte array representing "Hello Java Card world!" string. */ private static byte[] helloMessage = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, // "Hello " 0x4A, 0x61, 0x76, 0x61, 0x20, // "Java " 0x43, 0x61, 0x72, 0x64, 0x20, // "Card " 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21 // "world!" }; /** * This method is called once during applet instantiation process. * @param bArray * @param bOffset * @param bLength * @throws ISOException */ public static void install(byte[] bArray, short bOffset, byte bLength ) throws ISOException { new HelloWorld().register(bArray, (short) (bOffset + 1), bArray[bOffset]); } /** * This method is called each time the applet receives APDU. */ public void process(APDU apdu) { byte[] buffer = apdu.getBuffer();
// Handle applet selecting. if (selectingApplet()) { // Return 9000 - selecting is successful return; } // Now determine the requested instruction: switch (buffer[ISO7816.OFFSET_INS]) { case SAY_HELLO_INS: sayHello(apdu); return; case DO_NOTHING_INS: return; default: // We do not support any other INS values ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); } return; }
/** * Sends hello message to host using given APDU. * @param apdu APDU that requested hello message */ private void sayHello(APDU apdu) { // Here all bytes of the APDU are stored byte[] buffer = apdu.getBuffer();
// Get length of hello message short length = (short) helloMessage.length; // Tell JVM that we will send data apdu.setOutgoing(); // Set the length of data to send apdu.setOutgoingLength((byte) length); // Copy hello message to the APDU buffer for (short i = 0; i < length; i++) buffer[i] = helloMessage[i]; // Send our message starting at 0 position apdu.sendBytes((short) 0, length); } }
|
запускаю на эмуляторе CREF и получаю:
| Код | Java Card 2.2.2 APDU Tool, Version 1.3 Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Opening connection to localhost on port 9025. Connected. Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x01 CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, a0, 00, 00, 00, 62, 03, 01, 08, 01, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b0, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 01, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 01, P2: 00, Lc: 17, 01, 00, 14, de, ca, ff, ed, 01, 02, 04, 00, 01, 0a, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: bc, P1: 01, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 02, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 02, P2: 00, Lc: 20, 02, 00, 1f, 00, 14, 00, 1f, 00, 0f, 00, 15, 00, 32, 00, 0c, 00, 7b, 00, 23, 00, 12, 00, 00, 00, 6f, 00, 02, 00, 01, 00, 16, 02, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 02, P2: 00, Lc: 02, 01, 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: bc, P1: 02, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 04, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 04, P2: 00, Lc: 18, 04, 00, 15, 02, 03, 01, 07, a0, 00, 00, 00, 62, 01, 01, 00, 01, 07, a0, 00, 00, 00, 62, 00, 01, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: bc, P1: 04, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 03, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 03, P2: 00, Lc: 12, 03, 00, 0f, 01, 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 00, 00, 08, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: bc, P1: 03, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 06, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 06, P2: 00, Lc: 0f, 06, 00, 0c, 00, 80, 03, 00, ff, 00, 07, 01, 00, 00, 00, 1c, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: bc, P1: 06, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 07, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 07, 00, 7b, 00, 01, 10, 18, 8c, 00, 00, 7a, 05, 30, 8f, 00, 01, 3d, 8c, 00, 02, 18, 1d, 04, 41, 18, 1d, 25, 8b, 00, 03, 7a, 02, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 21, 19, 8b, 00, 04, 2d, 18, 8b, 00, 05, 60, 03, 7a, 1a, 04, 25, 73, 00, 12, 00, 01, 00, 02, 00, 0b, 00, 11, 18, 19, 8c, 00, 06, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 20, 7a, 7a, 11, 6d, 00, 8d, 00, 07, 7a, 04, 23, 19, 8b, 00, 04, 2d, 7b, 00, 08, 92, 32, 19, 8b, 00, 09, 3b, 19, 1f, 5b, 8b, 00, 0a, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 07, P2: 00, Lc: 1e, 03, 29, 04, 70, 0f, 1a, 16, 04, 7b, 00, 08, 16, 04, 25, 38, 59, 04, 01, 16, 04, 1f, 6c, f0, 19, 03, 1f, 8b, 00, 0b, 7a, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: bc, P1: 07, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 08, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 08, P2: 00, Lc: 20, 08, 00, 23, 00, 02, 00, 01, 00, 01, 03, 00, 16, 48, 65, 6c, 6c, 6f, 20, 4a, 61, 76, 61, 20, 43, 61, 72, 64, 20, 77, 6f, 72, 6c, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 08, P2: 00, Lc: 06, 64, 21, 00, 00, 00, 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: bc, P1: 08, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 05, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 05, P2: 00, Lc: 20, 05, 00, 32, 00, 0c, 06, 80, 03, 00, 01, 00, 00, 00, 06, 00, 00, 01, 03, 80, 03, 02, 03, 80, 0a, 01, 03, 80, 03, 03, 06, 00, 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 05, P2: 00, Lc: 15, 46, 06, 80, 07, 01, 05, 00, 00, 00, 03, 80, 0a, 07, 03, 80, 0a, 09, 03, 80, 0a, 04, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: bc, P1: 05, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b2, P1: 09, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: b4, P1: 09, P2: 00, Lc: 15, 09, 00, 12, 00, 00, 00, 0e, 05, 06, 04, 0a, 07, 05, 16, 08, 07, 04, 06, 07, 0b, 12, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: bc, P1: 09, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 CLA: 80, INS: ba, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00
|
Вопрос такой: что должно произойти после запуска HelloWorld апплета? И насколько полученный результат соответствует этому? И как вообще интерпретировать этот результат? |