我正在使用Eclipse上的JCDE在JavaCard中开发一个applet。
我正在用JCWDE和APDUTOOL测试我的小程序,但是我得到了SW1=6F和SW2=00。问题是,我使用的是类BigNumber的JavaCard API,函数init()不像我所希望的那样工作。
我的小程序的代码:
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);
}
}因此,问题发生在行s.init(buffer, (short)5, LC, BigNumber.FORMAT_HEX);中,但奇怪的是,它似乎在构造函数(x.init(tmp, (short) 0, (short) tmp.length, BigNumber.FORMAT_HEX);)中工作。
有人看到我做错什么了吗?
以下是我从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因此,在这个APDU命令列表中,我创建我的applet并选择它,然后我发送一个包含2个数据的APDU (0x030x04),使用我的行s.init(buffer, (short)5, LC, BigNumber.FORMAT_HEX);,我希望s将在0x0304初始化,但正如您所看到的,我得到了SW 6F00.非常感谢你的帮助!
发布于 2014-11-06 06:51:41
正如您在previous question on that issue中已经发现的,尝试分配s = new BigNumber((short)100);会抛出一个ArithmethicException。
s永远不会在代码中被初始化,因此也就是null。init引用调用
S.init(缓冲液,(短)5,LC,BigNumber.FORMAT_HEX);
将导致NullPointerException,这反过来会导致响应状态字6F00。注意,由于行中的异常,构造函数中的x.init(...);将永远不会调用。
s = new BigNumber((short)100);https://stackoverflow.com/questions/26761318
复制相似问题