/**
*
*/
package testing;
import javacard.framework.APDU;
import javacard.framework.ISO7816;
import javacard.framework.Applet;
import javacard.framework.ISOException;
import javacard.framework.OwnerPIN;
import javacard.framework.Util;
/**
* @author amitp
*
*/
public class Testing extends Applet {
final static byte CLASS_ONE = (byte) 0x00;
final static byte CLASS_TWO = (byte) 0xA0;
final static byte INS_VERIFY = (byte) 0x20;
final static byte INS_SEL_APPLET = (byte) 0x04;
final static byte SELECT = (byte) 0xA4;
final static byte[] PIN_NO = { (byte) 0x11, (byte) 0x22,(byte) 0x33,(byte) 0x44};
final static byte[] APPLET_ID = { (byte) 0XAA,(byte)0XBB,(byte)0XCC,(byte)0XDD,(byte) 0XEE };
final static short RES_FIRST_CMD = 0x6099;
final static short SW_AUTHENTICATION_METHOD_BLOCKED = 0x1300;
static OwnerPIN pin;
public static void install(byte[] bArray, short bOffset, byte bLength) {
// GP-compliant JavaCard applet registration
pin = new OwnerPIN((byte) 0X03,(byte) 0x04);
pin.update(PIN_NO, (short) 0, (byte) 0x04);
new testing.Testing().register(bArray, (short) (bOffset + 1),
bArray[bOffset]);
}
public void process(APDU apdu) {
// Good practice: Return 9000 on SELECT
if (selectingApplet()) {
return;
}
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0xA4:
if(buf[ISO7816.OFFSET_CLA]!=(byte) 0xA0)
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
else
{
short byte_read=(short)(apdu.setIncomingAndReceive());
byte x = Util.arrayCompare(buf, ISO7816.OFFSET_CDATA, APPLET_ID, (short)0 , byte_read);
if(x!= (byte) 0x00)
{
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
else
{
ISOException.throwIt(RES_FIRST_CMD);
}
}
break;
case (byte) 0x20:
varify(apdu);
break;
default:
// good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
private void varify(APDU apdu)
{
if(pin.getTriesRemaining()==0)
ISOException.throwIt(SW_AUTHENTICATION_METHOD_BLOCKED);
byte[] buffer = apdu.getBuffer();
//short len_of_LC_byte = buffer[ISO7816.OFFSET_LC];
//if( len_of_LC_byte !=5)
//ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
byte byte_read=(byte)(apdu.setIncomingAndReceive());
if(pin.check(buffer, ISO7816.OFFSET_CDATA,byte_read)== false)
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
}
我正在使用 JCOP 工具,因此将其加载到 java 卡中。它已成功加载到卡中,但是当我在其上发送命令时,选择 APPLET 给出 9000 但其他命令给出;
jcshell: Error code: -7fefffd1 (0x8010002F)
jcshell: Command failed: SCardTransmit(): 0x8010002f, PCSC failed with 0x8010002F: 0x2F (Warning,--,(SCard))
当我使用 Gpshell 时,我收到如下错误:
send_APDU() returns 0x8010002F (A communications error with the smart card has been detected. Retry the operation.
在调试模式下,所有结果都很好。谁能告诉我我在哪里做错了???