Problem with BioAPI in jcop simulator

Hello everyone.

I am trying to develop verification application, that implements javacard forum BioAPI. The problem is, that simple server-client sample (from java card kit 2.2.2 ) wokrs fine on JCOP card, but i can't load it in the simulator. It always returns some terminal error.

Could anyone help me?

There is the APDU trace i get:

- /term"Remote|localhost:1035"

--Opening terminal

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

resetCard with timeout: 0 (ms)

--Waitingfor 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 5C 52 8B 8E 1B 6D 9B F5 00 .P...\R...m...

(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 0F 96 4F 83 23 E2 24 91 90 00 .1....O.#.$...

Status: No Error

cm> ext-auth plain

=> 84 82 00 00 10 F7 A3 19 01 E9 A9 A7 74 68 16 0B............th..

C9 69 B4 87 A5 .i...

(16 msec)

<= 90 00 ..

Status: No Error

cm> delete 62696f6d657472794170706c

=> 80 E4 00 00 0E 4F 0C 62 69 6F 6D 65 74 72 79 41.....O.biometryA

70 70 6C 00ppl.

(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 7365727665724170706c

=> 80 E4 00 00 0C 4F 0A 73 65 72 76 65 72 41 70 70.....O.serverApp

6C 00 l.

(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 62696f6d65747279

=> 80 E4 00 00 0A 4F 08 62 69 6F 6D 65 74 72 79 00.....O.biometry.

(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\BioSample\bin\bio\javacard\bio.cap"

=> 80 E6 02 00 15 08 62 69 6F 6D 65 74 72 79 08 A0......biometry..

00 00 00 03 00 00 00 00 00 00 00...........

(0 msec)

<= 00 90 00...

Status: No Error

=> 80 E8 00 00 FA C4 82 03 7E 01 00 16 DE CA FF ED........~.......

02 02 04 00 01 08 62 69 6F 6D 65 74 72 79 03 62......biometry.b

69 6F 02 00 21 00 16 00 21 00 1D 00 15 00 72 00io..!...!.....r.

51 01 D6 00 17 00 4A 00 00 01 87 0A 0C 00 02 00Q.....J.........

01 00 0A 02 02 00 04 00 15 02 02 01 07 A0 00 00................

00 62 01 01 01 01 07 A0 00 00 01 32 00 01 03 00.b.........2....

1D 02 0A 73 65 72 76 65 72 41 70 70 6C 00 32 0C...serverAppl.2.

62 69 6F 6D 65 74 72 79 41 70 70 6C 01 3A 06 00biometryAppl.:..

51 00 00 43 80 03 01 00 01 05 0D 00 00 00 8E FFQ..C............

FF 00 3E 00 66 00 92 00 9C 00 A6 00 B0 00 BA 00..>.f...........

C4 00 D0 00 E5 00 F2 81 02 09 0A 09 0F 0D 0E 0B................

0C 10 11 81 00 09 0A 09 0F 0D 0E 0B 0C 10 11 80................

02 00 00 80 03 01 00 01 07 03 00 00 01 46 01 8B.............F..

01 B0 07 01 D6 01 01 6C 80 07 01 73 00 13 04 41.......l...s...A

18 8C 00 17 19 1E 25 29 04 16 04 61 08 18 8B 00......%)...a....

12 70 0C 18 19 1E 04 41 16 04 8B 00 16 18 10 00.p.....A........

(0 msec)

<= 00 90 00...

Status: No Error

=> 80 E8 00 01 FA 1F 08 8D 00 05 87 01 7A 04 30 8F............z.0.

00 03 18 1D 1E 8C 00 18 7A 02 21 19 8B 00 0C 2D........z.!....-

18 8B 00 10 60 03 7A 1A 04 25 73 00 10 00 10 00....`.z..%s.....

10 00 09 18 19 8B 00 1A 70 08 11 6D 00 8D 00 0E........p..m....

7A 04 22 AD 01 67 08 11 68 81 8D 00 0E 19 8B 00z."..g..h.......

0C 2D 19 8B 00 14 32 AD 01 1A 08 1F 8E 04 00 1B.-....2.........

09 AD 01 8E 01 00 1B 0B 7A 01 30 18 77 01 10 AD........z.0.w...

01 8E 01 00 1B 01 78 01 10 AD 01 8E 01 00 1B 00......x.........

78 01 10 AD 01 8E 01 00 1B 05 7A 01 10 AD 01 8Ex.........z.....

01 00 1B 06 78 01 10 AD 01 8E 01 00 1B 03 78 03....x.........x.

30 AD 01 19 1E 8E 03 00 1B 04 78 05 50 11 AB CD0.........x.P...

8D 00 19 AD 01 1D 1A 1F 16 04 8E 05 00 1B 02 78...............x

04 40 AD 01 19 1E 1F 8E 04 00 1B 07 78 04 40 AD.@..........x.@.

01 19 1E 1F 8E 04 00 1B 08 78 04 42 18 8C 00 17.........x.B....

19 1E 25 29 04 16 04 61 08 18 8B 00 12 70 0C 18..%)...a.....p..

19 1E 04 41 16 04 8B 00 16 7B 00 04 03 7B 00 00...A.....{...{..

(16 msec)

<= 00 90 00...

Status: No Error

=> 80 E8 00 02 FA 04 92 5B 8D 00 09 28 05 18 15 05.......[...(....

03 8D 00 0D 94 00 00 0B 87 00 7A 04 30 8F 00 11..........z.0...

18 1D 1E 8C 00 08 7A 02 22 19 8B 00 0C 2D 18 8B......z."....-..

00 10 60 03 7A AD 00 67 08 11 62 00 8D 00 0E 1A..`.z..g..b.....

04 25 73 00 23 00 10 00 11 00 0B 00 1C 18 19 8B.%s.#...........

00 0A 70 19 2E 1B 8B 00 06 8D 00 0E 70 0F 18 19..p.........p...

8B 00 0F 70 08 11 6D 00 8D 00 0E 7A 05 22 19 8B...p..m....z."..

00 0C 2D AD 00 03 1A 03 1A 92 8E 05 00 0B 02 32..-............2

19 8B 00 02 3B 19 1F 8B 00 15 19 03 1F 8B 00 07....;...........

7A 04 23 19 8B 00 0C 2D 19 8B 00 14 32 AD 00 1Az.#....-....2...

08 1F 8E 04 00 0B 07 29 04 16 04 11 40 00 6D 08.......)....@.m.

11 91 01 8D 00 0E 7A 08 00 17 00 02 00 01 00 01......z.........

03 00 0A 73 65 72 76 65 72 41 70 70 6C 00 00 00...serverAppl...

00 05 00 72 00 1C 02 00 41 00 02 00 02 00 03 80...r....A.......

0A 07 01 00 02 00 05 00 00 00 06 81 04 00 03 81................

03 01 03 80 0A 04 06 00 00 FF 06 80 08 0B 03 00................

(0 msec)

<= 00 90 00...

Status: No Error

=> 80 E8 80 03 94 00 41 08 01 81 02 00 03 80 0A 01......A.........

06 80 08 04 06 80 07 01 03 00 41 09 03 80 03 03..........A.....

01 00 41 00 03 80 03 01 01 81 03 00 03 80 0A 06..A.............

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

06 81 03 01 03 00 02 08 01 81 01 00 09 00 4A 00..............J.

11 30 39 14 0A 0E 0A 0A 0A 0A 0A 12 0F 0D 43 1D.09...........C.

3E 2A 00 35 07 06 0D 0C 07 08 06 07 05 14 08 0D>*.5............

04 05 0A 07 0E 0A 0A 0A 0A 0C 0A 0B 0D 0D 08 0D................

0C 03 04 05 09 04 08 06 07 05 0D 13 07 03 07 08................

07 0C 06 06 06 07 05 0A 10 00 ..........

(15 msec)

<= 00 90 00...

Status: No Error

Load report:

898 bytes loaded in 0.2 seconds

effective code size on card:

+package AID8

+ applet AIDs32

+ classes84

+ methods473

+ statics19

+ exports0

overall616 bytes

cm> install -i 7365727665724170706c -q C9#() 62696f6d65747279 7365727665724170706c

=> 80 E6 0C 00 25 08 62 69 6F 6D 65 74 72 79 0A 73....%.biometry.s

65 72 76 65 72 41 70 70 6C 0A 73 65 72 76 65 72erverAppl.server

41 70 70 6C 01 00 02 C9 00 00 00Appl.......

jcshell: Error code: -6 (Card terminal error)

jcshell: Communication problems:null

Unexpected error; aborting execution

cm> card-info

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

jcshell: Error code: -6 (Card terminal error)

jcshell: Communication problems: java.net.SocketException: Software caused connection abort: socket write error

Best regards,

Eve

[8441 byte] By [Ievaa] at [2007-11-27 6:25:30]
# 1
Please post the applet/library source.
lexdabeara at 2007-7-12 17:45:21 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 2

There is the source (it does nothing, just declres interfaces from BioAPI) for the server:

/*

* Copyright 2005 Sun Microsystems, Inc. All rights reserved.

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

*/

/*

* @(#)SampleBioServer.java1.4 06/01/03

*/

package bio;

import javacard.framework.*;

import org.javacardforum.javacard.biometry.*;

public class SampleBioServer extends Applet implements SharedBioTemplate

{

public final static byte CLA=(byte)0xCF;

public final static byte INS_ENROLL = (byte)0x10;

public final static byte MATCH_TRY_LIMIT = (byte)5;

private OwnerBioTemplate impl;

protected SampleBioServer(byte[] bArray, short bOffset, byte bLength)

{

byte aidLen = bArray[bOffset];

if (aidLen== (byte)0)

{

register();

} else

{

register(bArray, (short)(bOffset+1), aidLen);

}

impl = BioBuilder.buildBioTemplate(BioBuilder.PASSWORD,MATCH_TRY_LIMIT);

}

/**

* Installs this applet.

* @param bArray the array containing installation parameters

* @param bOffset the starting offset in bArray

* @param bLength the length in bytes of the parameter data in bArray

*/

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

{

new SampleBioServer(bArray,bOffset,bLength);

}

/**

* Processes an incoming APDU.

* @see APDU

* @param apdu the incoming APDU

* @exception ISOException with the response bytes per ISO 7816-4

*/

public void process(APDU apdu) throws ISOException

{

byte buffer[] = apdu.getBuffer();

// check SELECT APDU command

if(selectingApplet())

return;

switch (buffer[ISO7816.OFFSET_INS])

{

case INS_ENROLL:

enrollData(apdu);

break;

default:

ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);

}

}

/**

* method takes in the data

* This implementation assumes that all the password data is given in the

* enroll method.

**/

public void enrollData(APDU apdu) throws ISOException

{

if (impl == null)

ISOException.throwIt((short)0x6881);

byte []buffer = apdu.getBuffer();

short bytesRead = apdu.setIncomingAndReceive();

impl.init(buffer, ISO7816.OFFSET_CDATA, bytesRead);

impl.doFinal();

//enrollment complete

}

public Shareable getShareableInterfaceObject(AID clientAID, byte parameter)

{

return this;

}

// the methods below implement the SharedBioTemplate interface

public boolean isInitialized(){

return impl.isInitialized();

}

public boolean isValidated(){

return impl.isValidated();

}

public void reset(){

impl.reset();

}

public byte getTriesRemaining(){

return impl.getTriesRemaining();

}

public byte getBioType(){

return impl.getBioType();

}

public short getVersion(byte[] dest, short offset){

return impl.getVersion(dest,offset);

}

public short getPublicTemplateData(short publicOffset, byte[] dest, short destOffset, short length) throws BioException{

BioException.throwIt((short)0xABCD);

return impl.getPublicTemplateData(publicOffset,dest,destOffset,length);

}

public short initMatch(byte[] candidate, short offset, short length) throws BioException{

return impl.initMatch(candidate,offset,length);

}

public short match(byte[] candidate, short offset, short length) throws BioException{

return impl.match(candidate,offset,length);

}

}

There is a client:

/*

* Copyright 2005 Sun Microsystems, Inc. All rights reserved.

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

*/

/*

* @(#)SamplePasswdBioApplet.java1.4 06/01/03

*/

package bio;

import javacard.framework.*;

import org.javacardforum.javacard.biometry.*;

public class SamplePasswdBioApplet extends Applet

{

public final static byte CLA=(byte)0xCF;

public final static byte INS_GET_REQ = (byte)0x10;

public final static byte INS_MATCH = (byte)0x11;

//--Error codes

public static final short ERROR_MATCH_FAILED = (short)0x9101;

private SharedBioTemplate bioImpl;

private static final byte[] BIO_SERVER_AID = {(byte)0x73, (byte)0x65,

(byte)0x72, (byte)0x76, (byte)0x65, (byte)0x72, (byte)0x41, (byte)0x70,

(byte)0x70, (byte)0x6C};

/**

* Only this class's install method should create the applet object.

*/

protected SamplePasswdBioApplet(byte[] bArray, short bOffset, byte bLength)

{

byte aidLen = bArray[bOffset];

if (aidLen== (byte)0)

{

register();

} else

{

register(bArray, (short)(bOffset+1), aidLen);

}

AID bioServerAID = JCSystem.lookupAID(BIO_SERVER_AID,(short)0,(byte)BIO_SERVER_AID.length);

bioImpl = (SharedBioTemplate)JCSystem.getAppletShareableInterfaceObject(bioServerAID,(byte)0);

}

/**

* Installs this applet.

* @param bArray the array containing installation parameters

* @param bOffset the starting offset in bArray

* @param bLength the length in bytes of the parameter data in bArray

*/

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

{

new SamplePasswdBioApplet(bArray,bOffset,bLength);

}

/**

* Processes an incoming APDU.

* @see APDU

* @param apdu the incoming APDU

* @exception ISOException with the response bytes per ISO 7816-4

*/

public void process(APDU apdu)

{

byte buffer[] = apdu.getBuffer();

// check SELECT APDU command

if(selectingApplet())

return;

if(bioImpl == null)

ISOException.throwIt((short)0x6200);

switch (buffer[ISO7816.OFFSET_INS]){

case INS_GET_REQ:

try

{

getRequirements(apdu);

}

catch(BioException bio)

{

ISOException.throwIt(bio.getReason());

}

break;

case INS_MATCH:

match(apdu);

break;

default:

ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);

}

}

/**

* method returns the public template data.

**/

public void getRequirements(APDU apdu) throws BioException

{

byte []buffer = apdu.getBuffer();

//byte []pubTemp = JCSystem.makeTransientByteArray((short)4,JCSystem.CLEAR_ON_DESELECT);

short length = bioImpl.getPublicTemplateData((short)0, buffer, (short)0, (short)buffer.length);

apdu.setOutgoing();

apdu.setOutgoingLength(length);

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

}

/**

* following match method matches the password passed in with the reference

* template

**/

public void match(APDU apdu)

{

byte []buffer = apdu.getBuffer();

short bytesRead = apdu.setIncomingAndReceive();

short result = bioImpl.initMatch(buffer, ISO7816.OFFSET_CDATA, bytesRead);

if(result < BioTemplate.MINIMUM_SUCCESSFUL_MATCH_SCORE){

ISOException.throwIt(ERROR_MATCH_FAILED);

}

}

}

Best regards,

Eve.

Ievaa at 2007-7-12 17:45:21 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 3

Just step through with the debugger and watch where the card mutes. You will find out that it will happen at this line:impl = BioBuilder.buildBioTemplate(BioBuilder.PASSWORD,MATCH_TRY_LIMIT);

I will repeat myself:

The implementation for the Bio API is NOT present. The OS cannot read the future how a BioTemplate should look like for the many possible biometric features (finger scan, password, smell, ...), because: IT IS NOT IMPLEMENTED.

I see that you did not understand the previous posts, so I suggest you the following: create your own e.g. MyBioBuilder, which extends the BioBuilder class, and fill the buildBioTemplate with life. The way you are trying it to use is intended for an implementation of a match on card algorithm in the smart card itself. Your way is the applet way.

Why does JCOP mute? The mentioned line throws an exception which is uncaught --> can be seen as a programmatic error. JC RE spec. is our best friend: 7.6.3 Cleanup Responsibilities of the Java Card RE:

...

Alternatively, programmatic abortion after creating objects within the transaction can be deemed to be a programmatic error. when this occurs, the Java Card RE may, to ensure the security of the card and to avoid heap space loss, lock up the card session to force tear / reset processing.

lexdabeara at 2007-7-12 17:45:21 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 4

I did understand you quite clearly. But it was unclear to me, why this sample works on JCOP, but not in simulator.

Actually, this sample have been taken from Java Card SDK 2.2.2. It is meaningless, because int one of its documents, there are three classes mentioned (server+client+ownerBioTemplate derived class, that implements functionality). Only server and client source codes are represented.

Thanks a lot lexdaber..

Have a nice day.

Best regards,

Eve

Ievaa at 2007-7-12 17:45:21 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 5
I also wanted to notice, that BioBuilder is final class, and BuilBioTemplate method is static, so there is no way to extend it. I suppose, that i just have to create my one builder class separately.Best regards,Eve
Ievaa at 2007-7-12 17:45:21 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 6
Sorry, you are correct. BioBuilder needs to be implemented according to the skeleton as well as the methods of the BioTemplate and OwnerBioTemplate.
lexdabeara at 2007-7-12 17:45:21 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 7
So, no extension or implemention, just adding my own source code directly in the sceleton stub files? This is the question i am wondering.Best regards,Eve
Ievaa at 2007-7-12 17:45:21 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 8

Something like class MyOwnerBioTemplate implements OwnerBioTemplate {

...

}

class MyBioBuilder {

...

(use same constants and implement the buildBioTemplate method)

}

MyOwnerBioTemplate = MyBioBuilder.buildBioTemplate(BioBuilder.PASSWORD,MATCH_TRY_LIMIT)

lexdabeara at 2007-7-12 17:45:21 > top of Java-index,Java Mobility Forums,Consumer and Commerce...