【发布时间】:2015-12-26 17:22:30
【问题描述】:
我正在尝试使用 GPSShell 中的 -instParam 选项为我的智能卡提供 PIN。我找到了一些示例,但我不知道如何使用给定的 PIN 初始化 OwnerPIN 对象。 AFAIK 我的小程序的安装方法有一个 LV 编码结构,但我该如何解析它。我尝试了 BERTLV 对象,但在安装小程序时出现“条件不满足”错误。 我有什么:
public static void install(byte[] bArray, short bOffset, byte bLength)
{
new MYPinCard(bArray, bOffset, bLength);
}
private MYPinCard(byte[] bArray, short bOffset, byte bLength)
{
m_pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);
byte iLen = bArray[bOffset]; // aid length
short iOffset = (short) (bOffset+iLen+1);
iLen = bArray[iOffset]; // application privileges length
iOffset = (short) (iOffset+iLen+1);
iLen = bArray[iOffset]; // application specific parameters length
iOffset++;
try
{
m_pin.update(bArray, iOffset, iLen);
}
catch (PINException e)
{
ISOException.throwIt((short)0x6AAA);
}
testdata = new byte[iLen];
Util.arrayCopy(bArray, bOffset, testdata, (short)0, iLen);
register();
}
private void getInstallParams(APDU apdu)
{
try
{
byte[] buffer = apdu.getBuffer();
// inform the JCRE that the applet has data to return
short le = apdu.setOutgoing();
// set the actual number of the outgoing data bytes
apdu.setOutgoingLength(((short)testdata.length));
apdu.sendBytesLong(testdata, (short)0, (short)testdata.length);
}
catch (APDUException e)
{
ISOException.throwIt(SW_APDU_EXCEPTION);
}
catch (TransactionException e)
{
ISOException.throwIt(SW_TRANSACTION_EXCEPTION);
}
catch (ArrayIndexOutOfBoundsException e)
{
ISOException.throwIt(SW_AIOOB_EXCEPTION);
}
catch (NullPointerException e)
{
ISOException.throwIt(SW_NULLPOINTER_EXCEPTION);
}
}
使用 getInstallParams() 方法,我可以检索字节。对于我的 PIN,它是 2 个字节的值,但我不知道如何处理这些字节。
有什么提示吗?
【问题讨论】:
-
Util.arrayCopy(bArray, bOffset, testdata, (short)0, iLen);部分可能使用了错误的偏移量——恕我直言,iOffset应该在那里(如果你想存储参数值)。