2014-10-03 5 views
1

hello world 애플릿을 사용하여 jwcde 시뮬레이션을 실행하려고합니다. 나는 JC221을 사용한다.JCWDE 시뮬레이터 실행 : 호출 된 install() 메서드의 예외

package hello; 



import javacard.framework.APDU; 

import javacard.framework.Applet; 

import javacard.framework.ISO7816; 

import javacard.framework.ISOException; 

import javacard.framework.Util; 



public class HelloWorldApplet extends Applet { 

     private static final byte[] helloWorld = {(byte)'H',(byte)'e',(byte)'l',(byte)'l',(byte)'o',(byte)' ',(byte)'W',(byte)'o',(byte)'r',(byte)'l',(byte)'d',}; 



     private static final byte HW_CLA = (byte)0x80; 

     private static final byte HW_INS = (byte)0x00; 



     public static void install(byte[] bArray, short bOffset, byte bLength) { 

      new HelloWorldApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]); 

     } 



     public void process(APDU apdu) { 



      if (selectingApplet()) { 

      return; 

     } 



     byte[] buffer = apdu.getBuffer(); 

     byte CLA = (byte) (buffer[ISO7816.OFFSET_CLA] & 0xFF); 

     byte INS = (byte) (buffer[ISO7816.OFFSET_INS] & 0xFF); 



     if (CLA != HW_CLA) 

     { 

      ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); 

     } 



      switch (INS) { 

      case HW_INS: 

       getHelloWorld(apdu); 

       break; 

      default: 

       ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 

     } 

    } 



    private void getHelloWorld(APDU apdu) 

    { 

     byte[] buffer = apdu.getBuffer(); 

     short length = (short) helloWorld.length; 



     Util.arrayCopyNonAtomic(helloWorld, (short)0, buffer, (short)0, (short) length); 



     apdu.setOutgoingAndSend((short)0, length); 

    } 

} 

내가이 명령을 사용하여 컴파일 관리 :

애플릿입니다

javac -g -d hello -classpath “.;%JC_HOME%\lib\api.jar;%JC_HOME%\lib\javacardframework.jar” HelloWorldApplet.java 

그리고 컴파일 된 클래스 파일이 경로에 있는지 확인.

다음
jcwde jcwde.app 

내가 새로운 명령을 시작합니다

//+ 

// Copyright © 2003 Sun Microsystems, Inc. All rights reserved. 

// SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 

//- 



//+ 

// Workfile:@(#)jcwde.app 1.4 

// Version:1.4 

// Date:07/16/03 

//- 



// applet          AID 

com.sun.javacard.installer.InstallerApplet  0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0x8:0x1 

com.sun.javacard.samples.JavaPurse.JavaPurse  0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x2:0x1 

com.sun.javacard.samples.JavaLoyalty.JavaLoyalty 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x5:0x1 

com.sun.javacard.samples.wallet.Wallet   0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x6:0x1 

hello.HelloWorldApplet       0x01:0x02:0x03:0x04:0x05:0x06:0x07:0x08:0x09:0x00:0x01 

내가 명령 줄 창 (Windows7의)에서이 명령을 jcwde를 시작

는 사용을 jcwde jcwde.app 파일입니다 행 창 및 apdutool가 시작 : 여기
apdutool -nobanner -noatr HelloWorldApplet.scr > hello.scr.jcwde.out 

는 .SCR 스크립트 파일입니다 를 파워 업;

// Select the installer applet 
0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F; 
// 90 00 = SW_NO_ERROR 

// create Applet 
0x80 0xB8 0x00 0x00 0x0d 0x0b 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x01 0x00 0x7F; 

// Select Applet 
0x00 0xa4 0x04 0x00 0x0b 0x01 0x02 0x03 0x04 0x05 0x6 0x07 0x08 0x09 0x00 0x01 0x7F; 

// Send APDU command to get a Hello World message 
0x80 0x00 0x00 0x00 0x00 0x00; 

powerdown; 

그리고 여기합니다 (jcwde 명령 창에서) 결과 :

D:\jc221\samples\src\demo\jcwde>jcwde jcwde.app 

Java Card 2.2.1 Workstation Development Environment, Version 1.3 

Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. 

jcwde is listening for T=0 Apdu's on TCP/IP port 9á025. 

Exception from the invoked install() method:public static void hello.HelloWorldApplet.install(byte[],short,byte) 

jcwde exiting on receipt of power down command. 



D:\jc221\samples\src\demo\jcwde> 

그리고 이것은 hello.scr.jcwde.out 파일의 결과입니다

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: b8, P1: 00, P2: 00, Lc: 0d, 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 01, 00, Le: 00, SW1: 64, SW2: 44 

CLA: 80, INS: ba, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 

CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 01, Le: 00, SW1: 6d, SW2: 00 

CLA: 80, INS: 00, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 6d, SW2: 00 

그래서 질문은 왜 예외를 throw합니까 : 호출 된 install() 메서드에서 예외 : public static void hello.HelloWorldApplet.install (byte [], short, byte)

그리고 세 번째 줄 SW1 : 64 SW2 : 44의 결과 SW가 90:00이 아닌 이유는 무엇입니까?

+0

새로운 HelloWorldApplet()을 변경하십시오. register (bArray, (short) (bOffset + 1), bArray [bOffset]); HelloWorldApplet(). register() –

+0

@AnuragSharma 인스턴스 AID를 무시하는 이유는 무엇입니까? –

답변

0

이 문제의 근원은 JCWDE의 버그 (?) 인 것 같습니다. Java Card 사양에서는 install 매개 변수에 최소한 길이 바이트 (길이가 0 인 경우에도)를 포함해야하지만 JCWDE는 스크립트를 통해 가져 오는 모든 설치 매개 변수를 사용하는 것으로 보입니다. 따라서 설치 매개 변수를 명시 적으로 전달하지 않으면 바이트 배열 bArray의 길이는 0입니다. 따라서 bArray[bOffset]에 액세스하면 IndexOutOfBounds 예외가 발생합니다. 그래서 bArray/bLength의 길이를 확인하고 그에 따라 하나

register(bArray, (short) (bOffset + 1), bArray[bOffset]); 

또는

register(); 

를 호출하는 좋은 생각이있을 수 있습니다.