Reputation: 1264
I am developing an applet in JavaCard with JCDE on Eclipse.
I am testing my applet with JCWDE and APDUTOOL but I get SW1=6F and SW2=00... The thing is that I am using the class BigNumber of JavaCard API and the function init() is not working like I would like.
The code of my applet:
import javacard.framework.APDU;
import javacard.framework.APDUException;
import javacard.framework.Applet;
import javacard.framework.CardRuntimeException;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.UserException;
import javacard.framework.Util;
import javacard.security.CryptoException;
import javacardx.framework.math.BigNumber;
import javacard.security.MessageDigest;
public class SignatureGPS extends Applet {
public static final byte CLA = (byte) 0xB0;
public static final byte INS = (byte) 0x00;
private BigNumber s;
private BigNumber x;
private SignatureGPS() {
try {
s = new BigNumber((short)100);
x = new BigNumber((short)100);
byte[] tmp = {(byte) 0xc6, (byte) 0x85, (byte)0x8e, 0x06, (byte)0xb7, 0x04, 0x04, (byte)0xe9, (byte)0xcd, (byte)0x9e, 0x3e, (byte)0xcb, 0x66, 0x23, (byte)0x95, (byte)0xb4,
0x42, (byte)0x9c, 0x64, (byte)0x81, 0x39, 0x05, 0x3f, (byte)0xb5, 0x21, (byte)0xf8, 0x28, (byte)0xaf, 0x60, 0x6b, 0x4d, 0x3d, (byte)0xba, (byte)0xa1, 0x4b, 0x5e,
0x77, (byte)0xef, (byte)0xe7, 0x59, 0x28, (byte)0xfe, 0x1d, (byte)0xc1, 0x27, (byte)0xa2, (byte)0xff, (byte)0xa8, (byte)0xde, 0x33, 0x48, (byte)0xb3, (byte)0xc1,
(byte)0x85, 0x6a, 0x42, (byte)0x9b, (byte)0xf9, 0x7e, 0x7e, 0x31, (byte)0xc2, (byte)0xe5, (byte)0xbd, 0x66};
x.init(tmp, (short) 0, (short) tmp.length, BigNumber.FORMAT_HEX);
h = MessageDigest.getInstance(MessageDigest.ALG_SHA_256, false);
}
catch(ArithmeticException e){}
catch(CryptoException e){CryptoException.throwIt(e.getReason());}
catch(NullPointerException e){}
catch(ArrayIndexOutOfBoundsException e){}
}
public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
new SignatureGPS().register();
}
public void process(APDU apdu)
throws ISOException, ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException, APDUException, {
byte[] buffer = apdu.getBuffer();
if (this.selectingApplet()) return;
if (buffer[ISO7816.OFFSET_CLA] != CLA)
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
if (buffer[ISO7816.OFFSET_INS]!=0)
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
short LC = apdu.getIncomingLength();
apdu.setIncomingAndReceive();
s.init(buffer, (short)5, LC, BigNumber.FORMAT_HEX);
}
}
So the problem occurs at the line s.init(buffer, (short)5, LC, BigNumber.FORMAT_HEX);
but the thing that is strange is that it seems to work in the constructor (x.init(tmp, (short) 0, (short) tmp.length, BigNumber.FORMAT_HEX);
)
Does anybody see what am I doing wrong?
Here is the response I get from APDUTOOL:
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.
powerup;
// Select the installer applet
0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;
// create SignatureGPS applet
0x80 0xB8 0x00 0x00 0xd 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x01 0x00 0x7F;Received ATR = 0x3b 0xf0 0x11 0x00 0xff 0x00
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: b8, P1: 00, P2: 00, Lc: 0d, 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 01, 00, Le: 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 01, SW1: 90, SW2: 00
// select SignatureGPS applet
0x00 0xA4 0x04 0x00 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x01 0x7F;
CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 0b, 01, 02, 03, 04, 05, 06, 07, 08, 09, 00, 01, Le: 00, SW1: 90, SW2: 00
0xB0 0x00 0x00 0x00 0x02 0x03 0x04 0x7F;
CLA: b0, INS: 00, P1: 00, P2: 00, Lc: 02, 03, 04, Le: 00, SW1: 6f, SW2: 00
So in this list of APDU commands, I create my applet and select it and then I send an APDU which contains 2 datas (0x03 0x04) and with my line s.init(buffer, (short)5, LC, BigNumber.FORMAT_HEX);
I expect that s
gonna be initialize at 0x0304 but as you can see, I get the SW 6F00...
Thank you very much for your help !
Upvotes: 0
Views: 726
Reputation: 40851
As you already found out in your previous question on that issue, trying to allocate s = new BigNumber((short)100);
throws an ArithmethicException
.
s
never gets initialized in your code and, hence, is null
.Consequently, trying to call init
on a null
reference in
s.init(buffer, (short)5, LC, BigNumber.FORMAT_HEX);
will result in a NullPointerException
, which in turn results in the response status word 6F00
.
Note that x.init(...);
in your constructor will never be called due to the exception on the line
s = new BigNumber((short)100);
Upvotes: 1