Problem during loadgae of file

Hello,

I am trying to modify Loader.java sample to load simple HelloWorld applet to the

JCOP simulator.

During the execution the problem with call to the installForInstallAbdMakeSelectable aperas. The error code returned by he simulator is just 6a80 (Wrong data). I cant't find out what is the problem... Maybe anyone could help me?

So here is the code of my program, that shoul load and install applet, also make it selectable:

publicclass Loader

{

private Loader(){}

privatevoid load(String capFileName)throws Exception

{

CapFile capFile =new CapFile(capFileName,null);

System.out.println("Package name: " + capFile.pkg);

byte[][] applets = capFile.aids;

if ((applets ==null) || (applets.length == 0))

{

thrownew RuntimeException("no applets in cap file");

}

// Get connection to terminal, we look for the simulation.

// As you might want to use "pcsc", "4" or "tcl", "10" in case of

// Windows or "PCSC", null in case of Linux, you should pass the name

// of the terminal on the command line or in a properties file

System.out.println("Open terminal ...");

JCTerminal term = JCTerminal.getInstance("Remote",null);

term.open();

// Create a logging terminal spitting out the APDUs on standard out

TraceJCTerminal _term =new TraceJCTerminal();

_term.setLog(new PrintWriter(System.out));

_term.init(term);

term = _term;

// Get JavaCard representative, passing NULL resets card and returns ATR

System.out.println("Get card ...");

JCard card =new JCard(term, null, 2000);

// Get the off-card representative for the card manager and use it to

// select the on-card CardManager

System.out.println("Select card manager ...");

CardManager cardManager =new CardManager(card, CardManager.daid);

cardManager.select();

// For downloading something, we have to be authenticated to card manager.

// For this, the keys must be set. The keys to use should of course

// be configurable as well.

byte[] dfltKey = c2b("404142434445464748494a4b4c4d4e4f");

cardManager.setKey(new OPKey(255, 1, OPKey.DES_ECB, dfltKey));

cardManager.setKey(new OPKey(255, 2, OPKey.DES_ECB, dfltKey));

cardManager.setKey(new OPKey(255, 3, OPKey.DES_ECB, dfltKey));

//cardManager.setKey(new OPKey(1, 1, OPKey.DES_ECB, c2b("707172737475767778797a7b7c7d7e7f")));

//cardManager.setKey(new OPKey(1, 2, OPKey.DES_ECB, c2b("606162636465666768696a6b6c6d6e6f")));

cardManager.setKey(new OPKey(1, 3, OPKey.DES_ECB, c2b("505152535455565758595a5b5c5d5e5f")));

System.out.println("Authenticate to card manager ...");

cardManager.initializeUpdate(255, 0, OPApplet.SCP_UNDEFINED);

cardManager.externalAuthenticate(OPApplet.APDU_CLR);

System.out.println("deleting applets");

cardManager.deleteObject(capFile.pkgId, 0, capFile.pkgId.length,true);

System.out.println("applets deleted");

// And load the cap-file, do not forget to call installForLoad

System.out.println("Loading cap-file ..."+capFile.pkg);

cardManager.installForLoad(capFile.pkgId, 0, capFile.pkgId.length, null, 0, 0, null, 0, null, 0, 0, null, 0);

cardManager.load(capFile, null, SecurityDomain.LOAD_ALL,new PrintWriter(System.out), 250);

System.out.println("Finished loading !");

// Install applet, we try to install the first applet given in the

// cap file, and try to instantiate it under the same AID as given for its

// representation in the cap file. No installation data is passed.

System.out.println("Installing applet ...");

cardManager.installForInstallAndMakeSelectable//HERE EXCEPTION APPEARS

(

capFile.pkgId,

0,

capFile.pkgId.length,

applets[0],

0,

applets[0].length,/* applet */

applets[0],

0,

applets[0].length,/* instance aid */

OPApplet.NO_PRIVS,/* no special priviledges */

null,

0,

0,/* install data */

null,

0

);

System.out.println("Install succeeded!");

// synchronize state with on-card card manager

cardManager.update();

// Print information regarding card manager, applets and packages on-card

JCInfo info = JCInfo.INFO;

System.out.println("\nCardManager AID: " + info.dataToString(cardManager.getAID()));

System.out.println("CardManager state : " + info.toString("card.status", (byte) cardManager.getState()) +"\n");

There is the reaply of the smulator:

Open terminal ...

Get card ...

--Waitingfor card...

Select card manager ...

ATR=3B FA 13 00 00 81 31 FE 45 4A 43 4F 50 34 31 56;.....1.EJCOP41V

32 32 31 96221.

=> 00 A4 04 00 07 A0 00 00 00 03 00 00 00 .............

(0 msec)

<= 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65o..............e

01 FF 90 00....

Status: No Error

Authenticate to card manager ...

=> 80 50 00 00 08 A9 2D 23 0F 2E CD 55 7A 00 .P....-#...Uz.

(0 msec)

<= 00 00 57 F3 97 D9 7F 72 88 55 FF 02 00 20 BA 9A..W....r.U... ..

16 94 77 B9 81 CE 96 61 84 55 71 73 90 00 ..w....a.Uqs..

Status: No Error

=> 84 82 00 00 10 18 F1 1A 0C 97 BD D1 66 8B 43 41............f.CA

46 39 44 85 9C F9D..

(0 msec)

<= 90 00 ..

Status: No Error

deleting applets

=> 80 E4 00 80 0C 4F 0A 48 65 6C 6C 6F 57 6F 72 6C.....O.HelloWorl

64 00 d.

(0 msec)

<= 00 90 00...

Status: No Error

applets deleted

Loading cap-file ...com.sun.javacard.samples.HelloWorld

=> 80 E6 02 00 0F 0A 48 65 6C 6C 6F 57 6F 72 6C 64......HelloWorld

00 00 00 00 00 .....

(0 msec)

<= 00 90 00...

Status: No Error

=> 80 E8 00 00 FA C4 82 01 57 01 00 38 DE CA FF ED........W..8....

02 02 04 00 01 0A 48 65 6C 6C 6F 57 6F 72 6C 64......HelloWorld

23 63 6F 6D 2F 73 75 6E 2F 6A 61 76 61 63 61 72#com/sun/javacar

64 2F 73 61 6D 70 6C 65 73 2F 48 65 6C 6C 6F 57d/samples/HelloW

6F 72 6C 64 02 00 21 00 38 00 21 00 12 00 0B 00orld..!.8.!.....

36 00 0E 00 65 00 0A 00 13 00 00 00 6E 02 9A 006...e.......n...

00 00 00 00 00 01 01 00 04 00 0B 01 02 01 07 A0................

00 00 00 62 01 01 03 00 12 01 0E 48 65 6C 6C 6F...b.......Hello

57 6F 72 6C 64 41 70 70 6C 00 14 06 00 0E 00 00WorldAppl.......

00 80 03 01 00 01 07 01 00 00 00 1D 07 00 65 00..............e.

02 10 18 8C 00 07 18 11 01 00 90 0B 87 00 18 8B................

00 05 7A 01 30 8F 00 03 8C 00 0A 7A 05 23 19 8B..z.0......z.#..

00 08 2D 19 8B 00 02 32 03 29 04 70 19 1A 08 AD..-....2.).p....

00 16 04 1F 8D 00 01 3B 16 04 1F 41 29 04 19 08.......;...A)...

8B 00 09 32 1F 64 E8 19 8B 00 06 3B 19 16 04 08...2.d.....;....

41 8B 00 04 19 03 08 8B 00 0B 19 AD 00 03 16 00A...............

(0 msec)

<= 00 90 00...

Status: No Error

=> 80 E8 80 01 61 04 8B 00 0C 7A 08 00 0A 00 00 00....a....z......

00 00 00 00 00 00 00 05 00 36 00 0D 02 00 02 00.........6......

06 80 10 02 03 80 0A 06 01 00 02 00 03 80 0A 09................

03 80 03 01 03 80 0A 07 06 80 03 00 03 80 0A 01................

03 80 0A 03 06 00 00 01 03 80 0A 04 03 80 0A 05................

09 00 13 00 03 0E 23 2C 00 0C 05 0C 06 03 07 05......#,........

10 0C 08 09 06 09 00.......

(16 msec)

<= 00 90 00...

Status: No Error

Finished loading !

Installing applet ...

=> 80 E6 0C 00 2D 0A 48 65 6C 6C 6F 57 6F 72 6C 64....-.HelloWorld

0E 48 65 6C 6C 6F 57 6F 72 6C 64 41 70 70 6C 0E.HelloWorldAppl.

48 65 6C 6C 6F 57 6F 72 6C 64 41 70 70 6C 01 00HelloWorldAppl..

00 00 00...

(0 msec)

<= 6A 80 j.

Status: Wrong data

EX: msg null,classclass com.ibm.jc.JCException

com.ibm.jc.JCException:

Error: 6a80

APDU: 6A80

at com.ibm.jc.JCUtil.check9000(Unknown Source)

at com.ibm.jc.SecurityDomain.handleInstall(Unknown Source)

at com.ibm.jc.SecurityDomain.installForInstallAndMakeSelectable(Unknown

Source)

at loader.Loader.load(Loader.java:93)

at loader.Loader.main(Loader.java:187)

Please, help me, I don't get it, ehat could be wrong in this sample?

[10832 byte] By [Ievaa] at [2007-11-27 1:57:57]
# 1
Have you tried to upload the same file using the JCOP Shell? Just turn trace APDU option on. Regards,Aleksandar
fara0na at 2007-7-12 1:34:06 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 2

Yes, I did.

Below are the results of HelloWorldAppl loading to Java Card in JCOP Shell simulations process.

- /term "Remote|localhost:1175"

--Opening terminal

> /card -a a000000003000000 -c com.ibm.jc.CardManager

resetCard with timeout: 0 (ms)

--Waiting for card...

ATR=3B FA 13 00 00 81 31 FE 45 4A 43 4F 50 34 31 56;.....1.EJCOP41V

32 32 31 96221.

ATR: T=1, FI=1/DI=3 (93clk/etu), N=0, IFSC=254, BWI=4/CWI=5, Hist="JCOP41V221"

=> 00 A4 04 00 08 A0 00 00 00 03 00 00 00 00 ..............

(0 msec)

<= 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65o..............e

01 FF 90 00....

Status: No Error

cm> set-key 255/1/DES-ECB/404142434445464748494a4b4c4d4e4f 255/2/DES-ECB/404142434445464748494a4b4c4d4e4f 255/3/DES-ECB/404142434445464748494a4b4c4d4e4f

cm> init-update 255

=> 80 50 00 00 08 E6 F0 56 27 06 B6 C6 42 00 .P.....V'...B.

(0 msec)

<= 00 00 57 F3 97 D9 7F 72 88 55 FF 02 00 00 3D 02..W....r.U....=.

9C 31 C7 89 6E 2E 4E BD 56 FB A4 9A 90 00 .1..n.N.V.....

Status: No Error

cm> ext-auth plain

=> 84 82 00 00 10 6B FC E2 0E 7D 91 7F 9E DD 09 6A.....k...}.....j

90 D0 2C D6 E9 ..,..

(16 msec)

<= 90 00 ..

Status: No Error

cm> delete 48656c6c6f576f726c644170706c

=> 80 E4 00 00 10 4F 0E 48 65 6C 6C 6F 57 6F 72 6C.....O.HelloWorl

64 41 70 70 6C 00 dAppl.

(0 msec)

<= 6A 88 j.

Status: Reference data not found

jcshell: Error code: 6a88 (Reference data not found)

jcshell: Wrong response APDU: 6A88

Ignoring expected error

cm> delete 48656c6c6f576f726c64

=> 80 E4 00 00 0C 4F 0A 48 65 6C 6C 6F 57 6F 72 6C.....O.HelloWorl

64 00 d.

(0 msec)

<= 6A 88 j.

Status: Reference data not found

jcshell: Error code: 6a88 (Reference data not found)

jcshell: Wrong response APDU: 6A88

Ignoring expected error

cm> upload -b 250 "C:\Documents and Settings\Ieva\workspace\HelloWorld\bin\com\sun\javacard\samples\HelloWorld\javacard\HelloWorld.cap"

=> 80 E6 02 00 17 0A 48 65 6C 6C 6F 57 6F 72 6C 64......HelloWorld

08 A0 00 00 00 03 00 00 00 00 00 00 00 .............

(31 msec)

<= 00 90 00...

Status: No Error

=> 80 E8 00 00 FA C4 82 01 57 01 00 38 DE CA FF ED........W..8....

02 02 04 00 01 0A 48 65 6C 6C 6F 57 6F 72 6C 64......HelloWorld

23 63 6F 6D 2F 73 75 6E 2F 6A 61 76 61 63 61 72#com/sun/javacar

64 2F 73 61 6D 70 6C 65 73 2F 48 65 6C 6C 6F 57d/samples/HelloW

6F 72 6C 64 02 00 21 00 38 00 21 00 12 00 0B 00orld..!.8.!.....

36 00 0E 00 65 00 0A 00 13 00 00 00 6E 02 9A 006...e.......n...

00 00 00 00 00 01 01 00 04 00 0B 01 02 01 07 A0................

00 00 00 62 01 01 03 00 12 01 0E 48 65 6C 6C 6F...b.......Hello

57 6F 72 6C 64 41 70 70 6C 00 14 06 00 0E 00 00WorldAppl.......

00 80 03 01 00 01 07 01 00 00 00 1D 07 00 65 00..............e.

02 10 18 8C 00 07 18 11 01 00 90 0B 87 00 18 8B................

00 05 7A 01 30 8F 00 03 8C 00 0A 7A 05 23 19 8B..z.0......z.#..

00 08 2D 19 8B 00 02 32 03 29 04 70 19 1A 08 AD..-....2.).p....

00 16 04 1F 8D 00 01 3B 16 04 1F 41 29 04 19 08.......;...A)...

8B 00 09 32 1F 64 E8 19 8B 00 06 3B 19 16 04 08...2.d.....;....

41 8B 00 04 19 03 08 8B 00 0B 19 AD 00 03 16 00A...............

(16 msec)

<= 00 90 00...

Status: No Error

=> 80 E8 80 01 61 04 8B 00 0C 7A 08 00 0A 00 00 00....a....z......

00 00 00 00 00 00 00 05 00 36 00 0D 02 00 02 00.........6......

06 80 10 02 03 80 0A 06 01 00 02 00 03 80 0A 09................

03 80 03 01 03 80 0A 07 06 80 03 00 03 80 0A 01................

03 80 0A 03 06 00 00 01 03 80 0A 04 03 80 0A 05................

09 00 13 00 03 0E 23 2C 00 0C 05 0C 06 03 07 05......#,........

10 0C 08 09 06 09 00.......

(16 msec)

<= 00 90 00...

Status: No Error

Load report:

347 bytes loaded in 0.1 seconds

effective code size on card:

+ package AID10

+ applet AIDs21

+ classes17

+ methods104

+ statics0

+ exports0

overall152 bytes

cm> install -i 48656c6c6f576f726c644170706c -q C9#() 48656c6c6f576f726c64 48656c6c6f576f726c644170706c

=> 80 E6 0C 00 2F 0A 48 65 6C 6C 6F 57 6F 72 6C 64..../.HelloWorld

0E 48 65 6C 6C 6F 57 6F 72 6C 64 41 70 70 6C 0E.HelloWorldAppl.

48 65 6C 6C 6F 57 6F 72 6C 64 41 70 70 6C 01 00HelloWorldAppl..

02 C9 00 00 00 .....

(0 msec)

<= 90 00 ..

Status: No Error

cm> card-info

=> 80 F2 80 00 02 4F 00 00.....O..

(0 msec)

<= 08 A0 00 00 00 03 00 00 00 01 9E 90 00 .............

Status: No Error

=> 80 F2 40 00 02 4F 00 00..@..O..

(0 msec)

<= 0E 48 65 6C 6C 6F 57 6F 72 6C 64 41 70 70 6C 07.HelloWorldAppl.

00 90 00...

Status: No Error

=> 80 F2 10 00 02 4F 00 00.....O..

(0 msec)

<= 07 A0 00 00 00 03 53 50 01 00 01 08 A0 00 00 00......SP........

03 53 50 41 0A 48 65 6C 6C 6F 57 6F 72 6C 64 01.SPA.HelloWorld.

00 01 0E 48 65 6C 6C 6F 57 6F 72 6C 64 41 70 70...HelloWorldApp

6C 90 00l..

Status: No Error

Card Manager AID: A000000003000000

Card Manager state : OP_READY

Application: SELECTABLE (--) "HelloWorldAppl"

Load File :LOADED (--) A0000000035350(Security Domain)

Module:A000000003535041

Load File :LOADED (--) "HelloWorld"

Module:"HelloWorldAppl"

cm> /select |HelloWorldAppl

=> 00 A4 04 00 0E 48 65 6C 6C 6F 57 6F 72 6C 64 41.....HelloWorldA

70 70 6C 00ppl.

(0 msec)

<= 00 A4 04 00 0E 48 65 6C 6C 6F 57 6F 72 6C 64 41.....HelloWorldA

70 70 6C 90 00 ppl..

Status: No Error

Everything works fine. That's why, I don't get it, where mistake is made.

The only logical consumption is, that there are maybe some mistakes in my OffCard API Java code?!

May be anyone has well-working Java OffCard sample, that loads and installs applet (also makes it selectable)?

Best regards,

Eve

Ievaa at 2007-7-12 1:34:06 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 3
JCOP requires an install parameter: (LTL) 02 C9 00
lexdabeara at 2007-7-12 1:34:06 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 4
Ok, so where this parameter should be posted in my Java program code?and what does this one mean?Regards,Eve
Ievaa at 2007-7-12 1:34:06 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 5
Thanks, lexdabear very much for your help.it did work out with {0xC9, 0x00} install parameters byte array.Anyway, could you still explain to me why those are needed for JCOP? And what does those application specific parameter mean?Bes regards,Eve
Ievaa at 2007-7-12 1:34:06 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 6
Refer to GlobalPlatform 2.1.1 specification, 9.5.2.3.6 INSTALL [for LOAD] abd INSTALL [for install] Parameters, Table 9-35: Install Parameter TagsTag - Value - Presence'C9 -- Application Specific Parameters - Mandatory
lexdabeara at 2007-7-12 1:34:06 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 7

Thank you very much for your help.

Besides, have you ever had any problems with JCException return code (-6) = TERMINAL_ERROR. What could cause such an exception?

It is thrown by simulator after 40 times writing a lot of info to EEPROM, and after

20 times on real card i get the message, that i/o device could not perform the request?

What could cause such an error? Are there any limits to session time or writing to EEPROM times limitation through single session?

Best regards,

Eve

Ievaa at 2007-7-12 1:34:06 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 8
Sorry for my last quite full question. I have found that my applet worked incorrectly, because it allocated EEPROM many times, until the were no persistent memory left.That was the reason of an error.Thanks for your help,Best regards,Eve
Ievaa at 2007-7-12 1:34:06 > top of Java-index,Java Mobility Forums,Consumer and Commerce...